Changeset - e1e482093077
[Not reviewed]
beta
0 1 1
Marcin Kuzminski - 14 years ago 2011-11-23 21:26:54
marcin@python-works.com
tests for changeset comments
2 files changed with 145 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rhodecode/tests/functional/test_changeset_comments.py
Show inline comments
 
new file 100644
 
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)
 

	
 

	
 

	
 

	
rhodecode/tests/test_hg_operations.py
Show inline comments
 
@@ -181,13 +181,12 @@ def test_clone_with_credentials(no_error
 

	
 
    print '\tchecking if anonymous access is enabled'
 
    anonymous_access = get_anonymous_access()
 
    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,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO,
 
@@ -214,13 +213,12 @@ def test_clone_anonymous():
 

	
 
    print '\tchecking if anonymous access is enabled'
 
    anonymous_access = get_anonymous_access()
 
    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,
 
                   'pass':PASS,
 
                   'host':HOST,
 
                   'cloned_repo':HG_REPO,
 
@@ -383,19 +381,20 @@ def test_logs(initial):
 
if __name__ == '__main__':
 
    create_test_user(force=False)
 
    create_test_repo()
 

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

	
 
    test_push_new_file(commits=2, with_clone=True)
 

	
 
    test_clone_anonymous()
 
    test_push_wrong_path()
 

	
 
    test_push_wrong_credentials()
 

	
 
    test_logs(initial_logs)
 
    print 'finished ok in %.3f' % (time.time() - s)
0 comments (0 inline, 0 general)