review/tests/test_check.py @ 9030dc9517cf

web: add basic tests

This patch adds a new test module `test_web` to automate testing of web
requests. For now the tests are rather simple and only check for
expected status codes.

To set up the flask app within the tests, it has to be configured
properly. This is the reason why the app configuration part in `web.py`
has been moved into an own function - now it may also be used by the
test module.
author Oben Sonne <obensonne@googlemail.com>
date Mon, 02 Jul 2012 22:32:48 +0200
parents bef3dce04be6
children (none)
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
from util import get_identifiers

from .. import messages

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_empty():
    def t(rev):
        output = review(check=True, rev=rev)
        assert not output

        output = review(check=True, verbose=True, rev=rev)
        assert messages.CHECK_SUCCESS in output

        review(signoff=True, no=True, message='.', rev=rev)
        output = review(check=True, verbose=True, rev=rev)
        assert messages.CHECK_SUCCESS in output

        i = get_identifiers(rev)[0]
        review(edit=i, yes=True, rev=rev)
        output = review(check=True, verbose=True, rev=rev)
        assert messages.CHECK_SUCCESS in output

        review(comment=True, message='.', rev=rev)
        output = review(check=True, verbose=True, rev=rev)
        assert messages.CHECK_SUCCESS in output
    t('.')
    t('0')

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_no_nos():
    output = review(check=True, verbose=True, no_nos=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, no=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True)

    i = get_identifiers()[0]
    review(edit=i, yes=True)
    output = review(check=True, verbose=True, no_nos=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_yeses():
    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1')

    output = review(check=True, verbose=True, yeses='0')
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, yeses='1')
    assert messages.CHECK_SUCCESS in output

    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='2')

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_seen():
    should_fail_with(messages.CHECK_UNSEEN, check=True, verbose=True, seen=True)

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

    i = get_identifiers()[0]
    review(edit=i, no=True)
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

    should_fail_with(messages.CHECK_UNSEEN, rev='0', check=True, verbose=True, seen=True)

    review(rev='0', comment=True, message='.')
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_priority_no_nos():
    review(signoff=True, no=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, yeses='0')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True)
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True, yeses='0')

    i = get_identifiers()[0]
    review(edit=i, yes=True)
    output = review(check=True, verbose=True, no_nos=True, seen=True, yeses='0')
    assert messages.CHECK_SUCCESS in output

    review(rev='0', signoff=True, no=True, message='.')
    review(rev='0', comment=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True)
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True)
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True, yeses='0')

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_check_priority_yeses():
    review(comment=True, message='.')
    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1', seen=True)

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, yeses='1', seen=True)
    assert messages.CHECK_SUCCESS in output

    # TODO: For multiple signoffs, no_nos should take priority over "yes" signoffs.