##// END OF EJS Templates
tests: added some additional tests for commit comments....
marcink -
r536:eaeba764 default
parent child Browse files
Show More
@@ -1,237 +1,277 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 from pylons.i18n import ungettext
22 22 import pytest
23 23
24 24 from rhodecode.tests import *
25 25 from rhodecode.model.db import (
26 26 ChangesetComment, Notification, UserNotification)
27 27 from rhodecode.model.meta import Session
28 28 from rhodecode.lib import helpers as h
29 29
30 30
31 31 @pytest.mark.backends("git", "hg", "svn")
32 class TestChangeSetCommentsController(TestController):
32 class TestCommitCommentsController(TestController):
33 33
34 34 @pytest.fixture(autouse=True)
35 35 def prepare(self, request, pylonsapp):
36 36 for x in ChangesetComment.query().all():
37 37 Session().delete(x)
38 38 Session().commit()
39 39
40 40 for x in Notification.query().all():
41 41 Session().delete(x)
42 42 Session().commit()
43 43
44 44 request.addfinalizer(self.cleanup)
45 45
46 46 def cleanup(self):
47 47 for x in ChangesetComment.query().all():
48 48 Session().delete(x)
49 49 Session().commit()
50 50
51 51 for x in Notification.query().all():
52 52 Session().delete(x)
53 53 Session().commit()
54 54
55 55 def test_create(self, backend):
56 56 self.log_user()
57 57 commit = backend.repo.get_commit('300')
58 58 commit_id = commit.raw_id
59 59 text = u'CommentOnCommit'
60 60
61 61 params = {'text': text, 'csrf_token': self.csrf_token}
62 62 self.app.post(
63 63 url(controller='changeset', action='comment',
64 64 repo_name=backend.repo_name, revision=commit_id), params=params)
65 65
66 66 response = self.app.get(
67 67 url(controller='changeset', action='index',
68 68 repo_name=backend.repo_name, revision=commit_id))
69 69
70 70 # test DB
71 71 assert ChangesetComment.query().count() == 1
72 72 assert_comment_links(response, ChangesetComment.query().count(), 0)
73 73
74 74 assert Notification.query().count() == 1
75 75 assert ChangesetComment.query().count() == 1
76 76
77 77 notification = Notification.query().all()[0]
78 78
79 79 comment_id = ChangesetComment.query().first().comment_id
80 80 assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
81 81
82 82 sbj = 'commented on commit `{0}` in the {1} repository'.format(
83 83 h.show_id(commit), backend.repo_name)
84 84 assert sbj in notification.subject
85 85
86 86 lnk = (u'/{0}/changeset/{1}#comment-{2}'.format(
87 87 backend.repo_name, commit_id, comment_id))
88 88 assert lnk in notification.body
89 89
90 90 def test_create_inline(self, backend):
91 91 self.log_user()
92 92 commit = backend.repo.get_commit('300')
93 93 commit_id = commit.raw_id
94 94 text = u'CommentOnCommit'
95 95 f_path = 'vcs/web/simplevcs/views/repository.py'
96 96 line = 'n1'
97 97
98 98 params = {'text': text, 'f_path': f_path, 'line': line,
99 99 'csrf_token': self.csrf_token}
100 100
101 101 self.app.post(
102 102 url(controller='changeset', action='comment',
103 103 repo_name=backend.repo_name, revision=commit_id), params=params)
104 104
105 105 response = self.app.get(
106 106 url(controller='changeset', action='index',
107 107 repo_name=backend.repo_name, revision=commit_id))
108 108
109 109 # test DB
110 110 assert ChangesetComment.query().count() == 1
111 111 assert_comment_links(response, 0, ChangesetComment.query().count())
112 112 response.mustcontain(
113 113 '''class="inline-comment-placeholder" '''
114 114 '''path="vcs/web/simplevcs/views/repository.py" '''
115 115 '''target_id="vcswebsimplevcsviewsrepositorypy"'''
116 116 )
117 117
118 118 assert Notification.query().count() == 1
119 119 assert ChangesetComment.query().count() == 1
120 120
121 121 notification = Notification.query().all()[0]
122 122 comment = ChangesetComment.query().first()
123 123 assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
124 124
125 125 assert comment.revision == commit_id
126 126 sbj = 'commented on commit `{commit}` ' \
127 127 '(file: `{f_path}`) in the {repo} repository'.format(
128 128 commit=h.show_id(commit),
129 129 f_path=f_path, line=line, repo=backend.repo_name)
130 130 assert sbj in notification.subject
131 131
132 132 lnk = (u'/{0}/changeset/{1}#comment-{2}'.format(
133 133 backend.repo_name, commit_id, comment.comment_id))
134 134 assert lnk in notification.body
135 135 assert 'on line n1' in notification.body
136 136
137 137 def test_create_with_mention(self, backend):
138 138 self.log_user()
139 139
140 140 commit_id = backend.repo.get_commit('300').raw_id
141 141 text = u'@test_regular check CommentOnCommit'
142 142
143 143 params = {'text': text, 'csrf_token': self.csrf_token}
144 144 self.app.post(
145 145 url(controller='changeset', action='comment',
146 146 repo_name=backend.repo_name, revision=commit_id), params=params)
147 147
148 148 response = self.app.get(
149 149 url(controller='changeset', action='index',
150 150 repo_name=backend.repo_name, revision=commit_id))
151 151 # test DB
152 152 assert ChangesetComment.query().count() == 1
153 153 assert_comment_links(response, ChangesetComment.query().count(), 0)
154 154
155 155 notification = Notification.query().one()
156 156
157 157 assert len(notification.recipients) == 2
158 158 users = [x.username for x in notification.recipients]
159 159
160 160 # test_regular gets notification by @mention
161 161 assert sorted(users) == [u'test_admin', u'test_regular']
162 162
163 def test_create_with_status_change(self, backend):
164 self.log_user()
165 commit = backend.repo.get_commit('300')
166 commit_id = commit.raw_id
167 text = u'CommentOnCommit'
168 f_path = 'vcs/web/simplevcs/views/repository.py'
169 line = 'n1'
170
171 params = {'text': text, 'changeset_status': 'approved',
172 'csrf_token': self.csrf_token}
173
174 self.app.post(
175 url(controller='changeset', action='comment',
176 repo_name=backend.repo_name, revision=commit_id), params=params)
177
178 response = self.app.get(
179 url(controller='changeset', action='index',
180 repo_name=backend.repo_name, revision=commit_id))
181
182 # test DB
183 assert ChangesetComment.query().count() == 1
184 assert_comment_links(response, ChangesetComment.query().count(), 0)
185
186 assert Notification.query().count() == 1
187 assert ChangesetComment.query().count() == 1
188
189 notification = Notification.query().all()[0]
190
191 comment_id = ChangesetComment.query().first().comment_id
192 assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
193
194 sbj = 'commented on commit `{0}` (status: Approved) ' \
195 'in the {1} repository'.format(
196 h.show_id(commit), backend.repo_name)
197 assert sbj in notification.subject
198
199 lnk = (u'/{0}/changeset/{1}#comment-{2}'.format(
200 backend.repo_name, commit_id, comment_id))
201 assert lnk in notification.body
202
163 203 def test_delete(self, backend):
164 204 self.log_user()
165 205 commit_id = backend.repo.get_commit('300').raw_id
166 206 text = u'CommentOnCommit'
167 207
168 208 params = {'text': text, 'csrf_token': self.csrf_token}
169 209 self.app.post(
170 210 url(
171 211 controller='changeset', action='comment',
172 212 repo_name=backend.repo_name, revision=commit_id),
173 213 params=params)
174 214
175 215 comments = ChangesetComment.query().all()
176 216 assert len(comments) == 1
177 217 comment_id = comments[0].comment_id
178 218
179 219 self.app.post(
180 220 url(controller='changeset', action='delete_comment',
181 221 repo_name=backend.repo_name, comment_id=comment_id),
182 222 params={'_method': 'delete', 'csrf_token': self.csrf_token})
183 223
184 224 comments = ChangesetComment.query().all()
185 225 assert len(comments) == 0
186 226
187 227 response = self.app.get(
188 228 url(controller='changeset', action='index',
189 229 repo_name=backend.repo_name, revision=commit_id))
190 230 assert_comment_links(response, 0, 0)
191 231
192 232 @pytest.mark.parametrize('renderer, input, output', [
193 233 ('rst', 'plain text', '<p>plain text</p>'),
194 234 ('rst', 'header\n======', '<h1 class="title">header</h1>'),
195 235 ('rst', '*italics*', '<em>italics</em>'),
196 236 ('rst', '**bold**', '<strong>bold</strong>'),
197 237 ('markdown', 'plain text', '<p>plain text</p>'),
198 238 ('markdown', '# header', '<h1>header</h1>'),
199 239 ('markdown', '*italics*', '<em>italics</em>'),
200 240 ('markdown', '**bold**', '<strong>bold</strong>'),
201 241 ])
202 242 def test_preview(self, renderer, input, output, backend):
203 243 self.log_user()
204 244 params = {
205 245 'renderer': renderer,
206 246 'text': input,
207 247 'csrf_token': self.csrf_token
208 248 }
209 249 environ = {
210 250 'HTTP_X_PARTIAL_XHR': 'true'
211 251 }
212 252 response = self.app.post(
213 253 url(controller='changeset',
214 254 action='preview_comment',
215 255 repo_name=backend.repo_name),
216 256 params=params,
217 257 extra_environ=environ)
218 258
219 259 response.mustcontain(output)
220 260
221 261
222 262 def assert_comment_links(response, comments, inline_comments):
223 263 comments_text = ungettext("%d Commit comment",
224 264 "%d Commit comments", comments) % comments
225 265 if comments:
226 266 response.mustcontain('<a href="#comments">%s</a>,' % comments_text)
227 267 else:
228 268 response.mustcontain(comments_text)
229 269
230 270 inline_comments_text = ungettext("%d Inline Comment", "%d Inline Comments",
231 271 inline_comments) % inline_comments
232 272 if inline_comments:
233 273 response.mustcontain(
234 274 '<a href="#inline-comments" '
235 275 'id="inline-comments-counter">%s</a>' % inline_comments_text)
236 276 else:
237 277 response.mustcontain(inline_comments_text)
General Comments 0
You need to be logged in to leave comments. Login now