adce24d24176

Fix bugs, add tests.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 04 Oct 2009 19:57:03 -0400
parents 467dacbab7d6
children ac51c0878e04
branches/tags (none)
files review/api.py review/extension_ui.py review/tests/test_comment.py

Changes

--- a/review/api.py	Sun Oct 04 19:41:58 2009 -0400
+++ b/review/api.py	Sun Oct 04 19:57:03 2009 -0400
@@ -95,17 +95,6 @@
         node = hex(self.target[rev].node())
         return ReviewChangeset(self.ui, self.repo, node)
     
-    def add_signoff(self, rev):
-        '''Add (and commit) a signoff for the given revision.'''
-        pass
-    
-    def add_comment(self, message, rev='.', filename='', lines=[]):
-        '''Add (and commit) a comment for the given revision, file, and lines.'''
-        node = hex(self.target[rev].node())
-        comment = ReviewComment(self.ui.username(), datetime.utcnow(), node,
-            filename, lines, message)
-        comment.commit(self.ui, self.repo)
-    
 
 
 class ReviewChangeset(object):
@@ -141,6 +130,15 @@
                 { 'message': 'Initialize review data for changeset %s' % self.node,
                   'addremove': True, })
     
+    def add_signoff(self, message, rev='.'):
+        '''Add (and commit) a signoff for the given revision.'''
+        pass
+    
+    def add_comment(self, message, filename='', lines=[]):
+        '''Add (and commit) a comment for the given file and lines.'''
+        comment = ReviewComment(self.ui.username(), datetime.utcnow(),
+            self.node, filename, lines, message)
+        comment.commit(self.ui, self.repo)
 
 class ReviewComment(object):
     '''A single review comment.'''
--- a/review/extension_ui.py	Sun Oct 04 19:41:58 2009 -0400
+++ b/review/extension_ui.py	Sun Oct 04 19:57:03 2009 -0400
@@ -23,12 +23,13 @@
             return
     elif opts.pop('comment'):
         rd = ReviewDatastore(ui, repo)
+        rcset = rd[opts.pop('rev')]
         message = opts.pop('message')
         
         if not message:
             raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE)
         
-        rd.add_comment(message=message)
+        rcset.add_comment(message=message)
         return
     
     # No other options matched, so we're at the basic review command.
--- a/review/tests/test_comment.py	Sun Oct 04 19:41:58 2009 -0400
+++ b/review/tests/test_comment.py	Sun Oct 04 19:57:03 2009 -0400
@@ -7,6 +7,17 @@
 
 
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
+def test_no_comments():
+    sandbox = get_sandbox_repo()
+    
+    gather_output()
+    review()
+    output = grab_output()
+    
+    assert messages.REVIEW_LOG_COMMENTS % (0, 0) in output
+
+
+@with_setup(setup_reviewed_sandbox, teardown_sandbox)
 def test_blank_comment():
     sandbox = get_sandbox_repo()
     
@@ -20,11 +31,49 @@
 
 
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
-def test_no_comments():
+def test_add_comments_to_parent_rev():
     sandbox = get_sandbox_repo()
     
+    review(comment=True, message='Test comment one.')
+    
+    gather_output()
+    review()
+    output = grab_output()
+    
+    assert messages.REVIEW_LOG_COMMENTS % (1, 1) in output
+    
+    review(comment=True, message='Test comment two.')
+    
+    gather_output()
+    review()
+    output = grab_output()
+    
+    assert messages.REVIEW_LOG_COMMENTS % (2, 1) in output
+
+
+@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+def test_add_comments_to_specific_rev():
+    sandbox = get_sandbox_repo()
+    
+    review(comment=True, message='Test comment one.', rev='0')
+    
+    gather_output()
+    review(rev='0')
+    output = grab_output()
+    
+    assert messages.REVIEW_LOG_COMMENTS % (1, 1) in output
+    
     gather_output()
     review()
     output = grab_output()
     
     assert messages.REVIEW_LOG_COMMENTS % (0, 0) in output
+    
+    review(comment=True, message='Test comment two.', rev='0')
+    
+    gather_output()
+    review(rev='0')
+    output = grab_output()
+    
+    assert messages.REVIEW_LOG_COMMENTS % (2, 1) in output
+