08528309f7cd

Fix the path sanitization and add some tests.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 07 Oct 2009 19:08:50 -0400
parents b3bae1d649d7
children 789e5765c9ff
branches/tags (none)
files review/api.py review/tests/test_comment.py review/tests/util.py

Changes

--- 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):
--- 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
--- 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)