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