Show More
@@ -1,231 +1,237 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 |
|
29 | |||
29 |
|
30 | |||
30 | @pytest.mark.backends("git", "hg", "svn") |
|
31 | @pytest.mark.backends("git", "hg", "svn") | |
31 | class TestChangeSetCommentsController(TestController): |
|
32 | class TestChangeSetCommentsController(TestController): | |
32 |
|
33 | |||
33 | @pytest.fixture(autouse=True) |
|
34 | @pytest.fixture(autouse=True) | |
34 | def prepare(self, request, pylonsapp): |
|
35 | def prepare(self, request, pylonsapp): | |
35 | for x in ChangesetComment.query().all(): |
|
36 | for x in ChangesetComment.query().all(): | |
36 | Session().delete(x) |
|
37 | Session().delete(x) | |
37 | Session().commit() |
|
38 | Session().commit() | |
38 |
|
39 | |||
39 | for x in Notification.query().all(): |
|
40 | for x in Notification.query().all(): | |
40 | Session().delete(x) |
|
41 | Session().delete(x) | |
41 | Session().commit() |
|
42 | Session().commit() | |
42 |
|
43 | |||
43 | request.addfinalizer(self.cleanup) |
|
44 | request.addfinalizer(self.cleanup) | |
44 |
|
45 | |||
45 | def cleanup(self): |
|
46 | def cleanup(self): | |
46 | for x in ChangesetComment.query().all(): |
|
47 | for x in ChangesetComment.query().all(): | |
47 | Session().delete(x) |
|
48 | Session().delete(x) | |
48 | Session().commit() |
|
49 | Session().commit() | |
49 |
|
50 | |||
50 | for x in Notification.query().all(): |
|
51 | for x in Notification.query().all(): | |
51 | Session().delete(x) |
|
52 | Session().delete(x) | |
52 | Session().commit() |
|
53 | Session().commit() | |
53 |
|
54 | |||
54 | def test_create(self, backend): |
|
55 | def test_create(self, backend): | |
55 | self.log_user() |
|
56 | self.log_user() | |
56 |
commit |
|
57 | commit = backend.repo.get_commit('300') | |
|
58 | commit_id = commit.raw_id | |||
57 | text = u'CommentOnCommit' |
|
59 | text = u'CommentOnCommit' | |
58 |
|
60 | |||
59 | params = {'text': text, 'csrf_token': self.csrf_token} |
|
61 | params = {'text': text, 'csrf_token': self.csrf_token} | |
60 | self.app.post( |
|
62 | self.app.post( | |
61 | url(controller='changeset', action='comment', |
|
63 | url(controller='changeset', action='comment', | |
62 | repo_name=backend.repo_name, revision=commit_id), params=params) |
|
64 | repo_name=backend.repo_name, revision=commit_id), params=params) | |
63 |
|
65 | |||
64 | response = self.app.get( |
|
66 | response = self.app.get( | |
65 | url(controller='changeset', action='index', |
|
67 | url(controller='changeset', action='index', | |
66 | repo_name=backend.repo_name, revision=commit_id)) |
|
68 | repo_name=backend.repo_name, revision=commit_id)) | |
67 |
|
69 | |||
68 | # test DB |
|
70 | # test DB | |
69 | assert ChangesetComment.query().count() == 1 |
|
71 | assert ChangesetComment.query().count() == 1 | |
70 | assert_comment_links(response, ChangesetComment.query().count(), 0) |
|
72 | assert_comment_links(response, ChangesetComment.query().count(), 0) | |
71 |
|
73 | |||
72 | assert Notification.query().count() == 1 |
|
74 | assert Notification.query().count() == 1 | |
73 | assert ChangesetComment.query().count() == 1 |
|
75 | assert ChangesetComment.query().count() == 1 | |
74 |
|
76 | |||
75 | notification = Notification.query().all()[0] |
|
77 | notification = Notification.query().all()[0] | |
76 |
|
78 | |||
77 | comment_id = ChangesetComment.query().first().comment_id |
|
79 | comment_id = ChangesetComment.query().first().comment_id | |
78 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT |
|
80 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT | |
79 |
|
81 | |||
80 |
sbj = 'commented on |
|
82 | sbj = 'commented on commit `{0}` in the {1} repository'.format( | |
|
83 | h.show_id(commit), backend.repo_name) | |||
81 | assert sbj in notification.subject |
|
84 | assert sbj in notification.subject | |
82 |
|
85 | |||
83 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( |
|
86 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( | |
84 | backend.repo_name, commit_id, comment_id)) |
|
87 | backend.repo_name, commit_id, comment_id)) | |
85 | assert lnk in notification.body |
|
88 | assert lnk in notification.body | |
86 |
|
89 | |||
87 | def test_create_inline(self, backend): |
|
90 | def test_create_inline(self, backend): | |
88 | self.log_user() |
|
91 | self.log_user() | |
89 |
commit |
|
92 | commit = backend.repo.get_commit('300') | |
|
93 | commit_id = commit.raw_id | |||
90 | text = u'CommentOnCommit' |
|
94 | text = u'CommentOnCommit' | |
91 | f_path = 'vcs/web/simplevcs/views/repository.py' |
|
95 | f_path = 'vcs/web/simplevcs/views/repository.py' | |
92 | line = 'n1' |
|
96 | line = 'n1' | |
93 |
|
97 | |||
94 | params = {'text': text, 'f_path': f_path, 'line': line, |
|
98 | params = {'text': text, 'f_path': f_path, 'line': line, | |
95 | 'csrf_token': self.csrf_token} |
|
99 | 'csrf_token': self.csrf_token} | |
96 |
|
100 | |||
97 | self.app.post( |
|
101 | self.app.post( | |
98 | url(controller='changeset', action='comment', |
|
102 | url(controller='changeset', action='comment', | |
99 | repo_name=backend.repo_name, revision=commit_id), params=params) |
|
103 | repo_name=backend.repo_name, revision=commit_id), params=params) | |
100 |
|
104 | |||
101 | response = self.app.get( |
|
105 | response = self.app.get( | |
102 | url(controller='changeset', action='index', |
|
106 | url(controller='changeset', action='index', | |
103 | repo_name=backend.repo_name, revision=commit_id)) |
|
107 | repo_name=backend.repo_name, revision=commit_id)) | |
104 |
|
108 | |||
105 | # test DB |
|
109 | # test DB | |
106 | assert ChangesetComment.query().count() == 1 |
|
110 | assert ChangesetComment.query().count() == 1 | |
107 | assert_comment_links(response, 0, ChangesetComment.query().count()) |
|
111 | assert_comment_links(response, 0, ChangesetComment.query().count()) | |
108 | response.mustcontain( |
|
112 | response.mustcontain( | |
109 | '''class="inline-comment-placeholder" ''' |
|
113 | '''class="inline-comment-placeholder" ''' | |
110 | '''path="vcs/web/simplevcs/views/repository.py" ''' |
|
114 | '''path="vcs/web/simplevcs/views/repository.py" ''' | |
111 | '''target_id="vcswebsimplevcsviewsrepositorypy"''' |
|
115 | '''target_id="vcswebsimplevcsviewsrepositorypy"''' | |
112 | ) |
|
116 | ) | |
113 |
|
117 | |||
114 | assert Notification.query().count() == 1 |
|
118 | assert Notification.query().count() == 1 | |
115 | assert ChangesetComment.query().count() == 1 |
|
119 | assert ChangesetComment.query().count() == 1 | |
116 |
|
120 | |||
117 | notification = Notification.query().all()[0] |
|
121 | notification = Notification.query().all()[0] | |
118 | comment = ChangesetComment.query().first() |
|
122 | comment = ChangesetComment.query().first() | |
119 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT |
|
123 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT | |
120 |
|
124 | |||
121 | assert comment.revision == commit_id |
|
125 | assert comment.revision == commit_id | |
122 |
|
126 | sbj = 'commented on commit `{commit}` ' \ | ||
123 | sbj = ' commented on a commit of {0}'.format(backend.repo_name) |
|
127 | '(file: `{f_path}`) in the {repo} repository'.format( | |
|
128 | commit=h.show_id(commit), | |||
|
129 | f_path=f_path, line=line, repo=backend.repo_name) | |||
124 | assert sbj in notification.subject |
|
130 | assert sbj in notification.subject | |
125 |
|
131 | |||
126 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( |
|
132 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( | |
127 | backend.repo_name, commit_id, comment.comment_id)) |
|
133 | backend.repo_name, commit_id, comment.comment_id)) | |
128 | assert lnk in notification.body |
|
134 | assert lnk in notification.body | |
129 | assert 'on line n1' in notification.body |
|
135 | assert 'on line n1' in notification.body | |
130 |
|
136 | |||
131 | def test_create_with_mention(self, backend): |
|
137 | def test_create_with_mention(self, backend): | |
132 | self.log_user() |
|
138 | self.log_user() | |
133 |
|
139 | |||
134 | commit_id = backend.repo.get_commit('300').raw_id |
|
140 | commit_id = backend.repo.get_commit('300').raw_id | |
135 | text = u'@test_regular check CommentOnCommit' |
|
141 | text = u'@test_regular check CommentOnCommit' | |
136 |
|
142 | |||
137 | params = {'text': text, 'csrf_token': self.csrf_token} |
|
143 | params = {'text': text, 'csrf_token': self.csrf_token} | |
138 | self.app.post( |
|
144 | self.app.post( | |
139 | url(controller='changeset', action='comment', |
|
145 | url(controller='changeset', action='comment', | |
140 | repo_name=backend.repo_name, revision=commit_id), params=params) |
|
146 | repo_name=backend.repo_name, revision=commit_id), params=params) | |
141 |
|
147 | |||
142 | response = self.app.get( |
|
148 | response = self.app.get( | |
143 | url(controller='changeset', action='index', |
|
149 | url(controller='changeset', action='index', | |
144 | repo_name=backend.repo_name, revision=commit_id)) |
|
150 | repo_name=backend.repo_name, revision=commit_id)) | |
145 | # test DB |
|
151 | # test DB | |
146 | assert ChangesetComment.query().count() == 1 |
|
152 | assert ChangesetComment.query().count() == 1 | |
147 | assert_comment_links(response, ChangesetComment.query().count(), 0) |
|
153 | assert_comment_links(response, ChangesetComment.query().count(), 0) | |
148 |
|
154 | |||
149 | notification = Notification.query().one() |
|
155 | notification = Notification.query().one() | |
150 |
|
156 | |||
151 | assert len(notification.recipients) == 2 |
|
157 | assert len(notification.recipients) == 2 | |
152 | users = [x.username for x in notification.recipients] |
|
158 | users = [x.username for x in notification.recipients] | |
153 |
|
159 | |||
154 | # test_regular gets notification by @mention |
|
160 | # test_regular gets notification by @mention | |
155 | assert sorted(users) == [u'test_admin', u'test_regular'] |
|
161 | assert sorted(users) == [u'test_admin', u'test_regular'] | |
156 |
|
162 | |||
157 | def test_delete(self, backend): |
|
163 | def test_delete(self, backend): | |
158 | self.log_user() |
|
164 | self.log_user() | |
159 | commit_id = backend.repo.get_commit('300').raw_id |
|
165 | commit_id = backend.repo.get_commit('300').raw_id | |
160 | text = u'CommentOnCommit' |
|
166 | text = u'CommentOnCommit' | |
161 |
|
167 | |||
162 | params = {'text': text, 'csrf_token': self.csrf_token} |
|
168 | params = {'text': text, 'csrf_token': self.csrf_token} | |
163 | self.app.post( |
|
169 | self.app.post( | |
164 | url( |
|
170 | url( | |
165 | controller='changeset', action='comment', |
|
171 | controller='changeset', action='comment', | |
166 | repo_name=backend.repo_name, revision=commit_id), |
|
172 | repo_name=backend.repo_name, revision=commit_id), | |
167 | params=params) |
|
173 | params=params) | |
168 |
|
174 | |||
169 | comments = ChangesetComment.query().all() |
|
175 | comments = ChangesetComment.query().all() | |
170 | assert len(comments) == 1 |
|
176 | assert len(comments) == 1 | |
171 | comment_id = comments[0].comment_id |
|
177 | comment_id = comments[0].comment_id | |
172 |
|
178 | |||
173 | self.app.post( |
|
179 | self.app.post( | |
174 | url(controller='changeset', action='delete_comment', |
|
180 | url(controller='changeset', action='delete_comment', | |
175 | repo_name=backend.repo_name, comment_id=comment_id), |
|
181 | repo_name=backend.repo_name, comment_id=comment_id), | |
176 | params={'_method': 'delete', 'csrf_token': self.csrf_token}) |
|
182 | params={'_method': 'delete', 'csrf_token': self.csrf_token}) | |
177 |
|
183 | |||
178 | comments = ChangesetComment.query().all() |
|
184 | comments = ChangesetComment.query().all() | |
179 | assert len(comments) == 0 |
|
185 | assert len(comments) == 0 | |
180 |
|
186 | |||
181 | response = self.app.get( |
|
187 | response = self.app.get( | |
182 | url(controller='changeset', action='index', |
|
188 | url(controller='changeset', action='index', | |
183 | repo_name=backend.repo_name, revision=commit_id)) |
|
189 | repo_name=backend.repo_name, revision=commit_id)) | |
184 | assert_comment_links(response, 0, 0) |
|
190 | assert_comment_links(response, 0, 0) | |
185 |
|
191 | |||
186 | @pytest.mark.parametrize('renderer, input, output', [ |
|
192 | @pytest.mark.parametrize('renderer, input, output', [ | |
187 | ('rst', 'plain text', '<p>plain text</p>'), |
|
193 | ('rst', 'plain text', '<p>plain text</p>'), | |
188 | ('rst', 'header\n======', '<h1 class="title">header</h1>'), |
|
194 | ('rst', 'header\n======', '<h1 class="title">header</h1>'), | |
189 | ('rst', '*italics*', '<em>italics</em>'), |
|
195 | ('rst', '*italics*', '<em>italics</em>'), | |
190 | ('rst', '**bold**', '<strong>bold</strong>'), |
|
196 | ('rst', '**bold**', '<strong>bold</strong>'), | |
191 | ('markdown', 'plain text', '<p>plain text</p>'), |
|
197 | ('markdown', 'plain text', '<p>plain text</p>'), | |
192 | ('markdown', '# header', '<h1>header</h1>'), |
|
198 | ('markdown', '# header', '<h1>header</h1>'), | |
193 | ('markdown', '*italics*', '<em>italics</em>'), |
|
199 | ('markdown', '*italics*', '<em>italics</em>'), | |
194 | ('markdown', '**bold**', '<strong>bold</strong>'), |
|
200 | ('markdown', '**bold**', '<strong>bold</strong>'), | |
195 | ]) |
|
201 | ]) | |
196 | def test_preview(self, renderer, input, output, backend): |
|
202 | def test_preview(self, renderer, input, output, backend): | |
197 | self.log_user() |
|
203 | self.log_user() | |
198 | params = { |
|
204 | params = { | |
199 | 'renderer': renderer, |
|
205 | 'renderer': renderer, | |
200 | 'text': input, |
|
206 | 'text': input, | |
201 | 'csrf_token': self.csrf_token |
|
207 | 'csrf_token': self.csrf_token | |
202 | } |
|
208 | } | |
203 | environ = { |
|
209 | environ = { | |
204 | 'HTTP_X_PARTIAL_XHR': 'true' |
|
210 | 'HTTP_X_PARTIAL_XHR': 'true' | |
205 | } |
|
211 | } | |
206 | response = self.app.post( |
|
212 | response = self.app.post( | |
207 | url(controller='changeset', |
|
213 | url(controller='changeset', | |
208 | action='preview_comment', |
|
214 | action='preview_comment', | |
209 | repo_name=backend.repo_name), |
|
215 | repo_name=backend.repo_name), | |
210 | params=params, |
|
216 | params=params, | |
211 | extra_environ=environ) |
|
217 | extra_environ=environ) | |
212 |
|
218 | |||
213 | response.mustcontain(output) |
|
219 | response.mustcontain(output) | |
214 |
|
220 | |||
215 |
|
221 | |||
216 | def assert_comment_links(response, comments, inline_comments): |
|
222 | def assert_comment_links(response, comments, inline_comments): | |
217 | comments_text = ungettext("%d Commit comment", |
|
223 | comments_text = ungettext("%d Commit comment", | |
218 | "%d Commit comments", comments) % comments |
|
224 | "%d Commit comments", comments) % comments | |
219 | if comments: |
|
225 | if comments: | |
220 | response.mustcontain('<a href="#comments">%s</a>,' % comments_text) |
|
226 | response.mustcontain('<a href="#comments">%s</a>,' % comments_text) | |
221 | else: |
|
227 | else: | |
222 | response.mustcontain(comments_text) |
|
228 | response.mustcontain(comments_text) | |
223 |
|
229 | |||
224 | inline_comments_text = ungettext("%d Inline Comment", "%d Inline Comments", |
|
230 | inline_comments_text = ungettext("%d Inline Comment", "%d Inline Comments", | |
225 | inline_comments) % inline_comments |
|
231 | inline_comments) % inline_comments | |
226 | if inline_comments: |
|
232 | if inline_comments: | |
227 | response.mustcontain( |
|
233 | response.mustcontain( | |
228 | '<a href="#inline-comments" ' |
|
234 | '<a href="#inline-comments" ' | |
229 | 'id="inline-comments-counter">%s</a>' % inline_comments_text) |
|
235 | 'id="inline-comments-counter">%s</a>' % inline_comments_text) | |
230 | else: |
|
236 | else: | |
231 | response.mustcontain(inline_comments_text) |
|
237 | response.mustcontain(inline_comments_text) |
General Comments 0
You need to be logged in to leave comments.
Login now