review/tests/test_init.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 __future__ import with_statement

import os

from nose import with_setup

from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
from util import setup_sandbox, get_datastore_repo, get_sandbox_repo
from util import clone_sandbox_repo, sandbox_clone_path

from .. import messages
from .. import api

@with_setup(setup_sandbox, teardown_sandbox)
def test_init():
    sandbox = get_sandbox_repo()

    output = review(init=True, remote_path='/sandbox-review')
    assert messages.INIT_SUCCESS_UNCOMMITTED in output

    assert '.hgreview' not in sandbox['tip']
    assert os.path.exists('.hgreview')
    assert os.path.isdir(api.DEFAULT_DATASTORE_DIRNAME)
    assert get_datastore_repo(api.DEFAULT_DATASTORE_DIRNAME)

    with open('.hgreview', 'r') as hgrf:
        hgr = hgrf.read()
        assert 'remote = /sandbox-review' in hgr

@with_setup(setup_sandbox, teardown_sandbox)
def test_init_without_remote_path():
    should_fail_with(messages.INIT_REQUIRES_REMOTE_PATH, init=True)

@with_setup(setup_sandbox, teardown_sandbox)
def test_init_twice():
    review(init=True, remote_path='/sandbox-review')
    should_fail_with(messages.INIT_EXISTS_UNCOMMITTED, init=True, remote_path='/sandbox-review')

@with_setup(setup_reviewed_sandbox(), teardown_sandbox)
def test_init_clone():
    review(comment=True, message='Test comment one.')
    review(comment=True, rev='0', message='Test comment two.')

    clone_sandbox_repo()
    os.chdir(sandbox_clone_path)

    review(init=True)

    output = review()
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment two.' not in output

    output = review(rev='0')
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment two.' in output