##// END OF EJS Templates
fixed tests
marcink -
r2194:ec6691dd beta
parent child Browse files
Show More
@@ -1,148 +1,152 b''
1 1 from rhodecode.tests import *
2 2 from rhodecode.model.db import ChangesetComment, Notification, User, \
3 3 UserNotification
4 4
5 5
6 6 class TestChangeSetCommentsController(TestController):
7 7
8 8 def setUp(self):
9 9 for x in ChangesetComment.query().all():
10 10 self.Session.delete(x)
11 11 self.Session.commit()
12 12
13 13 for x in Notification.query().all():
14 14 self.Session.delete(x)
15 15 self.Session.commit()
16 16
17 17 def tearDown(self):
18 18 for x in ChangesetComment.query().all():
19 19 self.Session.delete(x)
20 20 self.Session.commit()
21 21
22 22 for x in Notification.query().all():
23 23 self.Session.delete(x)
24 24 self.Session.commit()
25 25
26 26 def test_create(self):
27 27 self.log_user()
28 28 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
29 29 text = u'CommentOnRevision'
30 30
31 31 params = {'text': text}
32 32 response = self.app.post(url(controller='changeset', action='comment',
33 33 repo_name=HG_REPO, revision=rev),
34 34 params=params)
35 35 # Test response...
36 36 self.assertEqual(response.status, '302 Found')
37 37 response.follow()
38 38
39 39 response = self.app.get(url(controller='changeset', action='index',
40 40 repo_name=HG_REPO, revision=rev))
41 41 # test DB
42 42 self.assertEqual(ChangesetComment.query().count(), 1)
43 43 self.assertTrue('''<div class="comments-number">%s '''
44 44 '''comment(s) (0 inline)</div>''' % 1 in response.body)
45 45
46 46 self.assertEqual(Notification.query().count(), 1)
47 47 self.assertEqual(ChangesetComment.query().count(), 1)
48 48
49 49 notification = Notification.query().all()[0]
50 50
51 51 ID = ChangesetComment.query().first().comment_id
52 52 self.assertEqual(notification.type_,
53 53 Notification.TYPE_CHANGESET_COMMENT)
54 54 sbj = (u'/vcs_test_hg/changeset/'
55 55 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
56 56 print "%s vs %s" % (sbj, notification.subject)
57 57 self.assertTrue(sbj in notification.subject)
58 58
59 59 def test_create_inline(self):
60 60 self.log_user()
61 61 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
62 62 text = u'CommentOnRevision'
63 63 f_path = 'vcs/web/simplevcs/views/repository.py'
64 64 line = 'n1'
65 65
66 66 params = {'text': text, 'f_path': f_path, 'line': line}
67 67 response = self.app.post(url(controller='changeset', action='comment',
68 68 repo_name=HG_REPO, revision=rev),
69 69 params=params)
70 70 # Test response...
71 71 self.assertEqual(response.status, '302 Found')
72 72 response.follow()
73 73
74 74 response = self.app.get(url(controller='changeset', action='index',
75 75 repo_name=HG_REPO, revision=rev))
76 76 #test DB
77 77 self.assertEqual(ChangesetComment.query().count(), 1)
78 self.assertTrue('''<div class="comments-number">0 comment(s)'''
79 ''' (%s inline)</div>''' % 1 in response.body)
80 self.assertTrue('''<div class="inline-comment-placeholder-line"'''
81 ''' line="n1" target_id="vcswebsimplevcsviews'''
82 '''repositorypy">''' in response.body)
78 response.mustcontain(
79 '''<div class="comments-number">0 comment(s)'''
80 ''' (%s inline)</div>''' % 1
81 )
82 response.mustcontain(
83 '''<div style="display:none" class="inline-comment-placeholder" '''
84 '''path="vcs/web/simplevcs/views/repository.py" '''
85 '''target_id="vcswebsimplevcsviewsrepositorypy">'''
86 )
83 87
84 88 self.assertEqual(Notification.query().count(), 1)
85 89 self.assertEqual(ChangesetComment.query().count(), 1)
86 90
87 91 notification = Notification.query().all()[0]
88 92 ID = ChangesetComment.query().first().comment_id
89 93 self.assertEqual(notification.type_,
90 94 Notification.TYPE_CHANGESET_COMMENT)
91 95 sbj = (u'/vcs_test_hg/changeset/'
92 96 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
93 97 print "%s vs %s" % (sbj, notification.subject)
94 98 self.assertTrue(sbj in notification.subject)
95 99
96 100 def test_create_with_mention(self):
97 101 self.log_user()
98 102
99 103 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
100 104 text = u'@test_regular check CommentOnRevision'
101 105
102 106 params = {'text':text}
103 107 response = self.app.post(url(controller='changeset', action='comment',
104 108 repo_name=HG_REPO, revision=rev),
105 109 params=params)
106 110 # Test response...
107 111 self.assertEqual(response.status, '302 Found')
108 112 response.follow()
109 113
110 114 response = self.app.get(url(controller='changeset', action='index',
111 115 repo_name=HG_REPO, revision=rev))
112 116 # test DB
113 117 self.assertEqual(ChangesetComment.query().count(), 1)
114 118 self.assertTrue('''<div class="comments-number">%s '''
115 119 '''comment(s) (0 inline)</div>''' % 1 in response.body)
116 120
117 121 self.assertEqual(Notification.query().count(), 2)
118 122 users = [x.user.username for x in UserNotification.query().all()]
119 123
120 124 # test_regular get's notification by @mention
121 125 self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
122 126
123 127 def test_delete(self):
124 128 self.log_user()
125 129 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
126 130 text = u'CommentOnRevision'
127 131
128 132 params = {'text': text}
129 133 response = self.app.post(url(controller='changeset', action='comment',
130 134 repo_name=HG_REPO, revision=rev),
131 135 params=params)
132 136
133 137 comments = ChangesetComment.query().all()
134 138 self.assertEqual(len(comments), 1)
135 139 comment_id = comments[0].comment_id
136 140
137 141 self.app.delete(url(controller='changeset',
138 142 action='delete_comment',
139 143 repo_name=HG_REPO,
140 144 comment_id=comment_id))
141 145
142 146 comments = ChangesetComment.query().all()
143 147 self.assertEqual(len(comments), 0)
144 148
145 149 response = self.app.get(url(controller='changeset', action='index',
146 150 repo_name=HG_REPO, revision=rev))
147 151 self.assertTrue('''<div class="comments-number">0 comment(s)'''
148 152 ''' (0 inline)</div>''' in response.body)
General Comments 0
You need to be logged in to leave comments. Login now