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