Show More
@@ -0,0 +1,143 b'' | |||
|
1 | from rhodecode.tests import * | |
|
2 | from rhodecode.model.db import ChangesetComment, Notification, User, \ | |
|
3 | UserNotification | |
|
4 | ||
|
5 | class TestChangeSetCommentrController(TestController): | |
|
6 | ||
|
7 | def setUp(self): | |
|
8 | for x in ChangesetComment.query().all(): | |
|
9 | self.Session().delete(x) | |
|
10 | self.Session().commit() | |
|
11 | ||
|
12 | for x in Notification.query().all(): | |
|
13 | self.Session().delete(x) | |
|
14 | self.Session().commit() | |
|
15 | ||
|
16 | def tearDown(self): | |
|
17 | for x in ChangesetComment.query().all(): | |
|
18 | self.Session().delete(x) | |
|
19 | self.Session().commit() | |
|
20 | ||
|
21 | for x in Notification.query().all(): | |
|
22 | self.Session().delete(x) | |
|
23 | self.Session().commit() | |
|
24 | ||
|
25 | def test_create(self): | |
|
26 | self.log_user() | |
|
27 | rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | |
|
28 | text = u'CommentOnRevision' | |
|
29 | ||
|
30 | params = {'text':text} | |
|
31 | response = self.app.post(url(controller='changeset', action='comment', | |
|
32 | repo_name=HG_REPO, revision=rev), | |
|
33 | params=params) | |
|
34 | # Test response... | |
|
35 | self.assertEqual(response.status, '302 Found') | |
|
36 | response.follow() | |
|
37 | ||
|
38 | response = self.app.get(url(controller='changeset', action='index', | |
|
39 | repo_name=HG_REPO, revision=rev)) | |
|
40 | # test DB | |
|
41 | self.assertEqual(ChangesetComment.query().count(), 1) | |
|
42 | self.assertTrue('''<div class="comments-number">%s ''' | |
|
43 | '''comment(s) (0 inline)</div>''' % 1 in response.body) | |
|
44 | ||
|
45 | ||
|
46 | self.assertEqual(Notification.query().count(), 1) | |
|
47 | notification = Notification.query().all()[0] | |
|
48 | ||
|
49 | self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT) | |
|
50 | self.assertTrue((u'/vcs_test_hg/changeset/27cd5cce30c96924232df' | |
|
51 | 'fcd24178a07ffeb5dfc#comment-1') in notification.subject) | |
|
52 | ||
|
53 | def test_create_inline(self): | |
|
54 | self.log_user() | |
|
55 | rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | |
|
56 | text = u'CommentOnRevision' | |
|
57 | f_path = 'vcs/web/simplevcs/views/repository.py' | |
|
58 | line = 'n1' | |
|
59 | ||
|
60 | params = {'text':text, 'f_path':f_path, 'line':line} | |
|
61 | response = self.app.post(url(controller='changeset', action='comment', | |
|
62 | repo_name=HG_REPO, revision=rev), | |
|
63 | params=params) | |
|
64 | # Test response... | |
|
65 | self.assertEqual(response.status, '302 Found') | |
|
66 | response.follow() | |
|
67 | ||
|
68 | response = self.app.get(url(controller='changeset', action='index', | |
|
69 | repo_name=HG_REPO, revision=rev)) | |
|
70 | #test DB | |
|
71 | self.assertEqual(ChangesetComment.query().count(), 1) | |
|
72 | self.assertTrue('''<div class="comments-number">0 comment(s)''' | |
|
73 | ''' (%s inline)</div>''' % 1 in response.body) | |
|
74 | self.assertTrue('''<div class="inline-comment-placeholder-line"''' | |
|
75 | ''' line="n1" target_id="vcswebsimplevcsviews''' | |
|
76 | '''repositorypy">''' in response.body) | |
|
77 | ||
|
78 | self.assertEqual(Notification.query().count(), 1) | |
|
79 | notification = Notification.query().all()[0] | |
|
80 | ||
|
81 | self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT) | |
|
82 | self.assertTrue((u'/vcs_test_hg/changeset/27cd5cce30c96924232df' | |
|
83 | 'fcd24178a07ffeb5dfc#comment-1') in notification.subject) | |
|
84 | ||
|
85 | def test_create_with_mention(self): | |
|
86 | self.log_user() | |
|
87 | ||
|
88 | rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | |
|
89 | text = u'@test_regular check CommentOnRevision' | |
|
90 | ||
|
91 | params = {'text':text} | |
|
92 | response = self.app.post(url(controller='changeset', action='comment', | |
|
93 | repo_name=HG_REPO, revision=rev), | |
|
94 | params=params) | |
|
95 | # Test response... | |
|
96 | self.assertEqual(response.status, '302 Found') | |
|
97 | response.follow() | |
|
98 | ||
|
99 | response = self.app.get(url(controller='changeset', action='index', | |
|
100 | repo_name=HG_REPO, revision=rev)) | |
|
101 | # test DB | |
|
102 | self.assertEqual(ChangesetComment.query().count(), 1) | |
|
103 | self.assertTrue('''<div class="comments-number">%s ''' | |
|
104 | '''comment(s) (0 inline)</div>''' % 1 in response.body) | |
|
105 | ||
|
106 | ||
|
107 | self.assertEqual(Notification.query().count(), 2) | |
|
108 | users = [x.user.username for x in UserNotification.query().all()] | |
|
109 | ||
|
110 | # test_regular get's notification by @mention | |
|
111 | self.assertEqual(users, [u'test_admin', u'test_regular']) | |
|
112 | ||
|
113 | def test_delete(self): | |
|
114 | self.log_user() | |
|
115 | rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' | |
|
116 | text = u'CommentOnRevision' | |
|
117 | ||
|
118 | params = {'text':text} | |
|
119 | response = self.app.post(url(controller='changeset', action='comment', | |
|
120 | repo_name=HG_REPO, revision=rev), | |
|
121 | params=params) | |
|
122 | ||
|
123 | comments = ChangesetComment.query().all() | |
|
124 | self.assertEqual(len(comments), 1) | |
|
125 | comment_id = comments[0].comment_id | |
|
126 | ||
|
127 | ||
|
128 | self.app.delete(url(controller='changeset', | |
|
129 | action='delete_comment', | |
|
130 | repo_name=HG_REPO, | |
|
131 | comment_id = comment_id)) | |
|
132 | ||
|
133 | comments = ChangesetComment.query().all() | |
|
134 | self.assertEqual(len(comments), 0) | |
|
135 | ||
|
136 | response = self.app.get(url(controller='changeset', action='index', | |
|
137 | repo_name=HG_REPO, revision=rev)) | |
|
138 | self.assertTrue('''<div class="comments-number">0 comment(s)''' | |
|
139 | ''' (0 inline)</div>''' in response.body) | |
|
140 | ||
|
141 | ||
|
142 | ||
|
143 |
@@ -184,7 +184,6 b' def test_clone_with_credentials(no_error' | |||
|
184 | 184 | if anonymous_access: |
|
185 | 185 | print '\tenabled, disabling it ' |
|
186 | 186 | set_anonymous_access(enable=False) |
|
187 | time.sleep(1) | |
|
188 | 187 | |
|
189 | 188 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ |
|
190 | 189 | {'user':USER, |
@@ -217,7 +216,6 b' def test_clone_anonymous():' | |||
|
217 | 216 | if not anonymous_access: |
|
218 | 217 | print '\tnot enabled, enabling it ' |
|
219 | 218 | set_anonymous_access(enable=True) |
|
220 | time.sleep(1) | |
|
221 | 219 | |
|
222 | 220 | clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \ |
|
223 | 221 | {'user':USER, |
@@ -386,7 +384,7 b" if __name__ == '__main__':" | |||
|
386 | 384 | |
|
387 | 385 | initial_logs = get_logs() |
|
388 | 386 | print 'initial activity logs: %s' % len(initial_logs) |
|
389 | ||
|
387 | s = time.time() | |
|
390 | 388 | #test_push_modify_file() |
|
391 | 389 | test_clone_with_credentials() |
|
392 | 390 | test_clone_wrong_credentials() |
@@ -399,3 +397,4 b" if __name__ == '__main__':" | |||
|
399 | 397 | test_push_wrong_credentials() |
|
400 | 398 | |
|
401 | 399 | test_logs(initial_logs) |
|
400 | print 'finished ok in %.3f' % (time.time() - s) |
General Comments 0
You need to be logged in to leave comments.
Login now