diff --git a/rhodecode/tests/functional/test_changeset_comments.py b/rhodecode/tests/functional/test_changeset_comments.py new file mode 100644 --- /dev/null +++ b/rhodecode/tests/functional/test_changeset_comments.py @@ -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('''
%s ''' + '''comment(s) (0 inline)
''' % 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('''
0 comment(s)''' + ''' (%s inline)
''' % 1 in response.body) + self.assertTrue('''
''' 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('''
%s ''' + '''comment(s) (0 inline)
''' % 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('''
0 comment(s)''' + ''' (0 inline)
''' in response.body) + + + + diff --git a/rhodecode/tests/test_hg_operations.py b/rhodecode/tests/test_hg_operations.py --- a/rhodecode/tests/test_hg_operations.py +++ b/rhodecode/tests/test_hg_operations.py @@ -184,7 +184,6 @@ def test_clone_with_credentials(no_error 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 @@ def test_clone_anonymous(): 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 @@ if __name__ == '__main__': 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 @@ if __name__ == '__main__': test_push_wrong_credentials() test_logs(initial_logs) + print 'finished ok in %.3f' % (time.time() - s)