# HG changeset patch # User Steve Losh # Date 1254956930 14400 # Node ID 08528309f7cd38cba0fa25d1e2a260f262e106cf # Parent b3bae1d649d7474d8d82ed3de7bfa48fea45c67e Fix the path sanitization and add some tests. diff -r b3bae1d649d7 -r 08528309f7cd review/api.py --- a/review/api.py Wed Oct 07 18:34:49 2009 -0400 +++ b/review/api.py Wed Oct 07 19:08:50 2009 -0400 @@ -78,9 +78,10 @@ def sanitize_path(p, repo=None): '''Take a path specific to the current platform and convert it.''' if repo: - p = os.path.relpath(p, start=repo.root) + p = os.path.relpath(os.path.realpath(p), start=repo.root) return '/'.join(_split_path_dammit(p)) + class ReviewDatastore(object): '''The data store for all the reviews so far.''' def __init__(self, ui, repo, lpath=None, rpath=None, create=False): diff -r b3bae1d649d7 -r 08528309f7cd review/tests/test_comment.py --- a/review/tests/test_comment.py Wed Oct 07 18:34:49 2009 -0400 +++ b/review/tests/test_comment.py Wed Oct 07 19:08:50 2009 -0400 @@ -173,3 +173,79 @@ assert output[n-1].strip().startswith('2') break + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_add_comments_to_file_in_subdir(): + sandbox = get_sandbox_repo() + + author_line = messages.REVIEW_LOG_COMMENT_AUTHOR % '|' + a1, _, a2 = author_line.partition('|') + + filename = os.path.join('test_dir', 'test_file') + + review(comment=True, message='Test comment one.', rev='1', files=[filename]) + + output = review(rev='1', files=[filename]) + assert a1 in output + assert a2 in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output + + output = review(rev='1', files=['file_two']) + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output + + output = review(rev='0', files=[filename]) + assert a1 not in output + assert a2 not in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output + + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_add_comments_to_file_in_cwd(): + sandbox = get_sandbox_repo() + + author_line = messages.REVIEW_LOG_COMMENT_AUTHOR % '|' + a1, _, a2 = author_line.partition('|') + + os.chdir('test_dir') + + review(comment=True, message='Test comment one.', rev='1', files=['test_file']) + + output = review(rev='1', files=['test_file']) + assert a1 in output + assert a2 in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output + + output = review(rev='1', files=['file_two']) + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output + + output = review(rev='0', files=['test_file']) + assert a1 not in output + assert a2 not in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output + + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_add_comments_to_file_in_reldir(): + sandbox = get_sandbox_repo() + + author_line = messages.REVIEW_LOG_COMMENT_AUTHOR % '|' + a1, _, a2 = author_line.partition('|') + + filename = os.path.join('..', 'file_three') + + os.chdir('test_dir') + + review(comment=True, message='Test comment one.', rev='1', files=[filename]) + + output = review(rev='1', files=[filename]) + assert a1 in output + assert a2 in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output + + output = review(rev='1', files=['file_two']) + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output + + output = review(rev='0', files=[filename]) + assert a1 not in output + assert a2 not in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' not in output \ No newline at end of file diff -r b3bae1d649d7 -r 08528309f7cd review/tests/util.py --- a/review/tests/util.py Wed Oct 07 18:34:49 2009 -0400 +++ b/review/tests/util.py Wed Oct 07 19:08:50 2009 -0400 @@ -67,7 +67,7 @@ def get_sandbox_repo(): - return hg.repository(_ui, '.') + return hg.repository(_ui, sandbox_path) def get_datastore_repo(path): return hg.repository(_ui, path)