test_changeset_comments.py
153 lines
| 6.0 KiB
| text/x-python
|
PythonLexer
r1715 | from rhodecode.tests import * | |||
from rhodecode.model.db import ChangesetComment, Notification, User, \ | ||||
UserNotification | ||||
r3797 | from rhodecode.model.meta import Session | |||
r1715 | ||||
r2149 | ||||
class TestChangeSetCommentsController(TestController): | ||||
r1715 | ||||
def setUp(self): | ||||
for x in ChangesetComment.query().all(): | ||||
r3797 | Session().delete(x) | |||
Session().commit() | ||||
r1715 | ||||
for x in Notification.query().all(): | ||||
r3797 | Session().delete(x) | |||
Session().commit() | ||||
r1715 | ||||
def tearDown(self): | ||||
for x in ChangesetComment.query().all(): | ||||
r3797 | Session().delete(x) | |||
Session().commit() | ||||
r1715 | ||||
for x in Notification.query().all(): | ||||
r3797 | Session().delete(x) | |||
Session().commit() | ||||
r1715 | ||||
def test_create(self): | ||||
self.log_user() | ||||
rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | ||||
text = u'CommentOnRevision' | ||||
r2149 | params = {'text': text} | |||
r1715 | 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) | ||||
r2317 | response.mustcontain('''<div class="comments-number">%s comment ''' | |||
'''(0 inline)</div>''' % 1) | ||||
r1715 | ||||
r2149 | self.assertEqual(Notification.query().count(), 1) | |||
self.assertEqual(ChangesetComment.query().count(), 1) | ||||
r1715 | ||||
notification = Notification.query().all()[0] | ||||
r2149 | ID = ChangesetComment.query().first().comment_id | |||
r2150 | self.assertEqual(notification.type_, | |||
r2149 | Notification.TYPE_CHANGESET_COMMENT) | |||
sbj = (u'/vcs_test_hg/changeset/' | ||||
'27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID) | ||||
print "%s vs %s" % (sbj, notification.subject) | ||||
self.assertTrue(sbj in notification.subject) | ||||
r1715 | ||||
def test_create_inline(self): | ||||
self.log_user() | ||||
rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | ||||
text = u'CommentOnRevision' | ||||
f_path = 'vcs/web/simplevcs/views/repository.py' | ||||
line = 'n1' | ||||
r2149 | params = {'text': text, 'f_path': f_path, 'line': line} | |||
r1715 | 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) | ||||
r2194 | response.mustcontain( | |||
r2317 | '''<div class="comments-number">0 comments''' | |||
r2194 | ''' (%s inline)</div>''' % 1 | |||
) | ||||
response.mustcontain( | ||||
'''<div style="display:none" class="inline-comment-placeholder" ''' | ||||
'''path="vcs/web/simplevcs/views/repository.py" ''' | ||||
'''target_id="vcswebsimplevcsviewsrepositorypy">''' | ||||
) | ||||
r1715 | ||||
self.assertEqual(Notification.query().count(), 1) | ||||
r2149 | self.assertEqual(ChangesetComment.query().count(), 1) | |||
r1715 | ||||
r2149 | notification = Notification.query().all()[0] | |||
ID = ChangesetComment.query().first().comment_id | ||||
r2150 | self.assertEqual(notification.type_, | |||
r2149 | Notification.TYPE_CHANGESET_COMMENT) | |||
sbj = (u'/vcs_test_hg/changeset/' | ||||
'27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID) | ||||
print "%s vs %s" % (sbj, notification.subject) | ||||
self.assertTrue(sbj in notification.subject) | ||||
r1715 | ||||
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) | ||||
r2317 | response.mustcontain('''<div class="comments-number">%s ''' | |||
'''comment (0 inline)</div>''' % 1) | ||||
r1715 | ||||
self.assertEqual(Notification.query().count(), 2) | ||||
users = [x.user.username for x in UserNotification.query().all()] | ||||
r4089 | # test_regular gets notification by @mention | |||
r1723 | self.assertEqual(sorted(users), [u'test_admin', u'test_regular']) | |||
r1715 | ||||
def test_delete(self): | ||||
self.log_user() | ||||
rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | ||||
text = u'CommentOnRevision' | ||||
r2149 | params = {'text': text} | |||
r1715 | 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, | ||||
r1723 | comment_id=comment_id)) | |||
r1715 | ||||
comments = ChangesetComment.query().all() | ||||
self.assertEqual(len(comments), 0) | ||||
response = self.app.get(url(controller='changeset', action='index', | ||||
repo_name=HG_REPO, revision=rev)) | ||||
r2317 | response.mustcontain('''<div class="comments-number">0 comments''' | |||
''' (0 inline)</div>''') | ||||