changeset 1715:e1e482093077 beta

tests for changeset comments
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 23 Nov 2011 22:26:54 +0200
parents 1308f068fc1a
children 7d1fc253549e
files rhodecode/tests/functional/test_changeset_comments.py rhodecode/tests/test_hg_operations.py
diffstat 2 files changed, 145 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rhodecode/tests/functional/test_changeset_comments.py	Wed Nov 23 22:26:54 2011 +0200
@@ -0,0 +1,143 @@
+from rhodecode.tests import *
+from rhodecode.model.db import ChangesetComment, Notification, User, \
+    UserNotification
+
+class TestChangeSetCommentrController(TestController):
+
+    def setUp(self):
+        for x in ChangesetComment.query().all():
+            self.Session().delete(x)
+        self.Session().commit()
+
+        for x in Notification.query().all():
+            self.Session().delete(x)
+        self.Session().commit()
+
+    def tearDown(self):
+        for x in ChangesetComment.query().all():
+            self.Session().delete(x)
+        self.Session().commit()
+
+        for x in Notification.query().all():
+            self.Session().delete(x)
+        self.Session().commit()
+
+    def test_create(self):
+        self.log_user()
+        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
+        text = u'CommentOnRevision'
+
+        params = {'text':text}
+        response = self.app.post(url(controller='changeset', action='comment',
+                                     repo_name=HG_REPO, revision=rev),
+                                     params=params)
+        # Test response...
+        self.assertEqual(response.status, '302 Found')
+        response.follow()
+
+        response = self.app.get(url(controller='changeset', action='index',
+                                repo_name=HG_REPO, revision=rev))
+        # test DB
+        self.assertEqual(ChangesetComment.query().count(), 1)
+        self.assertTrue('''<div class="comments-number">%s '''
+                        '''comment(s) (0 inline)</div>''' % 1 in response.body)
+
+
+        self.assertEqual(Notification.query().count(), 1)
+        notification = Notification.query().all()[0]
+
+        self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT)
+        self.assertTrue((u'/vcs_test_hg/changeset/27cd5cce30c96924232df'
+                          'fcd24178a07ffeb5dfc#comment-1') in notification.subject)
+
+    def test_create_inline(self):
+        self.log_user()
+        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
+        text = u'CommentOnRevision'
+        f_path = 'vcs/web/simplevcs/views/repository.py'
+        line = 'n1'
+
+        params = {'text':text, 'f_path':f_path, 'line':line}
+        response = self.app.post(url(controller='changeset', action='comment',
+                                     repo_name=HG_REPO, revision=rev),
+                                     params=params)
+        # Test response...
+        self.assertEqual(response.status, '302 Found')
+        response.follow()
+
+        response = self.app.get(url(controller='changeset', action='index',
+                                repo_name=HG_REPO, revision=rev))
+        #test DB
+        self.assertEqual(ChangesetComment.query().count(), 1)
+        self.assertTrue('''<div class="comments-number">0 comment(s)'''
+                        ''' (%s inline)</div>''' % 1 in response.body)
+        self.assertTrue('''<div class="inline-comment-placeholder-line"'''
+                        ''' line="n1" target_id="vcswebsimplevcsviews'''
+                        '''repositorypy">''' in response.body)
+
+        self.assertEqual(Notification.query().count(), 1)
+        notification = Notification.query().all()[0]
+
+        self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT)
+        self.assertTrue((u'/vcs_test_hg/changeset/27cd5cce30c96924232df'
+                          'fcd24178a07ffeb5dfc#comment-1') in notification.subject)
+
+    def test_create_with_mention(self):
+        self.log_user()
+
+        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
+        text = u'@test_regular check CommentOnRevision'
+
+        params = {'text':text}
+        response = self.app.post(url(controller='changeset', action='comment',
+                                     repo_name=HG_REPO, revision=rev),
+                                     params=params)
+        # Test response...
+        self.assertEqual(response.status, '302 Found')
+        response.follow()
+
+        response = self.app.get(url(controller='changeset', action='index',
+                                repo_name=HG_REPO, revision=rev))
+        # test DB
+        self.assertEqual(ChangesetComment.query().count(), 1)
+        self.assertTrue('''<div class="comments-number">%s '''
+                        '''comment(s) (0 inline)</div>''' % 1 in response.body)
+
+
+        self.assertEqual(Notification.query().count(), 2)
+        users = [x.user.username for x in UserNotification.query().all()]
+
+        # test_regular get's notification by @mention
+        self.assertEqual(users, [u'test_admin', u'test_regular'])
+
+    def test_delete(self):
+        self.log_user()
+        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
+        text = u'CommentOnRevision'
+
+        params = {'text':text}
+        response = self.app.post(url(controller='changeset', action='comment',
+                                     repo_name=HG_REPO, revision=rev),
+                                     params=params)
+
+        comments = ChangesetComment.query().all()
+        self.assertEqual(len(comments), 1)
+        comment_id = comments[0].comment_id
+
+
+        self.app.delete(url(controller='changeset',
+                                    action='delete_comment',
+                                    repo_name=HG_REPO,
+                                    comment_id = comment_id))
+
+        comments = ChangesetComment.query().all()
+        self.assertEqual(len(comments), 0)
+
+        response = self.app.get(url(controller='changeset', action='index',
+                                repo_name=HG_REPO, revision=rev))
+        self.assertTrue('''<div class="comments-number">0 comment(s)'''
+                        ''' (0 inline)</div>''' in response.body)
+
+
+
+
--- a/rhodecode/tests/test_hg_operations.py	Wed Nov 23 16:37:50 2011 +0200
+++ b/rhodecode/tests/test_hg_operations.py	Wed Nov 23 22:26:54 2011 +0200
@@ -184,7 +184,6 @@
     if anonymous_access:
         print '\tenabled, disabling it '
         set_anonymous_access(enable=False)
-        time.sleep(1)
 
     clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
                   {'user':USER,
@@ -217,7 +216,6 @@
     if not anonymous_access:
         print '\tnot enabled, enabling it '
         set_anonymous_access(enable=True)
-        time.sleep(1)
 
     clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \
                   {'user':USER,
@@ -386,7 +384,7 @@
 
     initial_logs = get_logs()
     print 'initial activity logs: %s' % len(initial_logs)
-
+    s = time.time()
     #test_push_modify_file()
     test_clone_with_credentials()
     test_clone_wrong_credentials()
@@ -399,3 +397,4 @@
     test_push_wrong_credentials()
 
     test_logs(initial_logs)
+    print 'finished ok in %.3f' % (time.time() - s)