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