review/tests/test_init.py @ 22de90ef33ed

Add identifiers to ReviewChangeset's and ReviewSignoff's.

The identifier of a rcset/rsignoff is the filename it was saved as, which is
the hash of its contents.

This will be useful when we want to add replies to comments/signoffs.

CLI support for this feature has also been added (using --verbose and --debug
flags with 'hg review [-r REV]'), as well as some simple unit tests.
author Steve Losh <steve@stevelosh.com>
date Sat, 27 Mar 2010 11:10:12 -0400
parents 1133505b5b04
children a909c2ba47f0
from __future__ import with_statement
from nose import *
from util import *
from .. import messages
from .. import api

import os
from mercurial import util as hgutil


@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():
    try:
        review(init=True)
    except hgutil.Abort, e:
        error = str(e)
        assert messages.INIT_REQUIRES_REMOTE_PATH in error
    else:
        assert False, 'The correct error message was not printed.'


@with_setup(setup_sandbox, teardown_sandbox)
def test_init_twice():
    review(init=True, remote_path='/sandbox-review')
    
    try:
        review(init=True, remote_path='/sandbox-review')
    except hgutil.Abort, e:
        error = str(e)
        assert messages.INIT_EXISTS_UNCOMMITTED in error
    else:
        assert False, 'The correct error message was not printed.'


@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