##// END OF EJS Templates
fixed tests
marcink -
r2194:ec6691dd beta
parent child Browse files
Show More
@@ -1,148 +1,152 b''
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2 from rhodecode.model.db import ChangesetComment, Notification, User, \
2 from rhodecode.model.db import ChangesetComment, Notification, User, \
3 UserNotification
3 UserNotification
4
4
5
5
6 class TestChangeSetCommentsController(TestController):
6 class TestChangeSetCommentsController(TestController):
7
7
8 def setUp(self):
8 def setUp(self):
9 for x in ChangesetComment.query().all():
9 for x in ChangesetComment.query().all():
10 self.Session.delete(x)
10 self.Session.delete(x)
11 self.Session.commit()
11 self.Session.commit()
12
12
13 for x in Notification.query().all():
13 for x in Notification.query().all():
14 self.Session.delete(x)
14 self.Session.delete(x)
15 self.Session.commit()
15 self.Session.commit()
16
16
17 def tearDown(self):
17 def tearDown(self):
18 for x in ChangesetComment.query().all():
18 for x in ChangesetComment.query().all():
19 self.Session.delete(x)
19 self.Session.delete(x)
20 self.Session.commit()
20 self.Session.commit()
21
21
22 for x in Notification.query().all():
22 for x in Notification.query().all():
23 self.Session.delete(x)
23 self.Session.delete(x)
24 self.Session.commit()
24 self.Session.commit()
25
25
26 def test_create(self):
26 def test_create(self):
27 self.log_user()
27 self.log_user()
28 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
28 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
29 text = u'CommentOnRevision'
29 text = u'CommentOnRevision'
30
30
31 params = {'text': text}
31 params = {'text': text}
32 response = self.app.post(url(controller='changeset', action='comment',
32 response = self.app.post(url(controller='changeset', action='comment',
33 repo_name=HG_REPO, revision=rev),
33 repo_name=HG_REPO, revision=rev),
34 params=params)
34 params=params)
35 # Test response...
35 # Test response...
36 self.assertEqual(response.status, '302 Found')
36 self.assertEqual(response.status, '302 Found')
37 response.follow()
37 response.follow()
38
38
39 response = self.app.get(url(controller='changeset', action='index',
39 response = self.app.get(url(controller='changeset', action='index',
40 repo_name=HG_REPO, revision=rev))
40 repo_name=HG_REPO, revision=rev))
41 # test DB
41 # test DB
42 self.assertEqual(ChangesetComment.query().count(), 1)
42 self.assertEqual(ChangesetComment.query().count(), 1)
43 self.assertTrue('''<div class="comments-number">%s '''
43 self.assertTrue('''<div class="comments-number">%s '''
44 '''comment(s) (0 inline)</div>''' % 1 in response.body)
44 '''comment(s) (0 inline)</div>''' % 1 in response.body)
45
45
46 self.assertEqual(Notification.query().count(), 1)
46 self.assertEqual(Notification.query().count(), 1)
47 self.assertEqual(ChangesetComment.query().count(), 1)
47 self.assertEqual(ChangesetComment.query().count(), 1)
48
48
49 notification = Notification.query().all()[0]
49 notification = Notification.query().all()[0]
50
50
51 ID = ChangesetComment.query().first().comment_id
51 ID = ChangesetComment.query().first().comment_id
52 self.assertEqual(notification.type_,
52 self.assertEqual(notification.type_,
53 Notification.TYPE_CHANGESET_COMMENT)
53 Notification.TYPE_CHANGESET_COMMENT)
54 sbj = (u'/vcs_test_hg/changeset/'
54 sbj = (u'/vcs_test_hg/changeset/'
55 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
55 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
56 print "%s vs %s" % (sbj, notification.subject)
56 print "%s vs %s" % (sbj, notification.subject)
57 self.assertTrue(sbj in notification.subject)
57 self.assertTrue(sbj in notification.subject)
58
58
59 def test_create_inline(self):
59 def test_create_inline(self):
60 self.log_user()
60 self.log_user()
61 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
61 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
62 text = u'CommentOnRevision'
62 text = u'CommentOnRevision'
63 f_path = 'vcs/web/simplevcs/views/repository.py'
63 f_path = 'vcs/web/simplevcs/views/repository.py'
64 line = 'n1'
64 line = 'n1'
65
65
66 params = {'text': text, 'f_path': f_path, 'line': line}
66 params = {'text': text, 'f_path': f_path, 'line': line}
67 response = self.app.post(url(controller='changeset', action='comment',
67 response = self.app.post(url(controller='changeset', action='comment',
68 repo_name=HG_REPO, revision=rev),
68 repo_name=HG_REPO, revision=rev),
69 params=params)
69 params=params)
70 # Test response...
70 # Test response...
71 self.assertEqual(response.status, '302 Found')
71 self.assertEqual(response.status, '302 Found')
72 response.follow()
72 response.follow()
73
73
74 response = self.app.get(url(controller='changeset', action='index',
74 response = self.app.get(url(controller='changeset', action='index',
75 repo_name=HG_REPO, revision=rev))
75 repo_name=HG_REPO, revision=rev))
76 #test DB
76 #test DB
77 self.assertEqual(ChangesetComment.query().count(), 1)
77 self.assertEqual(ChangesetComment.query().count(), 1)
78 self.assertTrue('''<div class="comments-number">0 comment(s)'''
78 response.mustcontain(
79 ''' (%s inline)</div>''' % 1 in response.body)
79 '''<div class="comments-number">0 comment(s)'''
80 self.assertTrue('''<div class="inline-comment-placeholder-line"'''
80 ''' (%s inline)</div>''' % 1
81 ''' line="n1" target_id="vcswebsimplevcsviews'''
81 )
82 '''repositorypy">''' in response.body)
82 response.mustcontain(
83 '''<div style="display:none" class="inline-comment-placeholder" '''
84 '''path="vcs/web/simplevcs/views/repository.py" '''
85 '''target_id="vcswebsimplevcsviewsrepositorypy">'''
86 )
83
87
84 self.assertEqual(Notification.query().count(), 1)
88 self.assertEqual(Notification.query().count(), 1)
85 self.assertEqual(ChangesetComment.query().count(), 1)
89 self.assertEqual(ChangesetComment.query().count(), 1)
86
90
87 notification = Notification.query().all()[0]
91 notification = Notification.query().all()[0]
88 ID = ChangesetComment.query().first().comment_id
92 ID = ChangesetComment.query().first().comment_id
89 self.assertEqual(notification.type_,
93 self.assertEqual(notification.type_,
90 Notification.TYPE_CHANGESET_COMMENT)
94 Notification.TYPE_CHANGESET_COMMENT)
91 sbj = (u'/vcs_test_hg/changeset/'
95 sbj = (u'/vcs_test_hg/changeset/'
92 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
96 '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
93 print "%s vs %s" % (sbj, notification.subject)
97 print "%s vs %s" % (sbj, notification.subject)
94 self.assertTrue(sbj in notification.subject)
98 self.assertTrue(sbj in notification.subject)
95
99
96 def test_create_with_mention(self):
100 def test_create_with_mention(self):
97 self.log_user()
101 self.log_user()
98
102
99 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
103 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
100 text = u'@test_regular check CommentOnRevision'
104 text = u'@test_regular check CommentOnRevision'
101
105
102 params = {'text':text}
106 params = {'text':text}
103 response = self.app.post(url(controller='changeset', action='comment',
107 response = self.app.post(url(controller='changeset', action='comment',
104 repo_name=HG_REPO, revision=rev),
108 repo_name=HG_REPO, revision=rev),
105 params=params)
109 params=params)
106 # Test response...
110 # Test response...
107 self.assertEqual(response.status, '302 Found')
111 self.assertEqual(response.status, '302 Found')
108 response.follow()
112 response.follow()
109
113
110 response = self.app.get(url(controller='changeset', action='index',
114 response = self.app.get(url(controller='changeset', action='index',
111 repo_name=HG_REPO, revision=rev))
115 repo_name=HG_REPO, revision=rev))
112 # test DB
116 # test DB
113 self.assertEqual(ChangesetComment.query().count(), 1)
117 self.assertEqual(ChangesetComment.query().count(), 1)
114 self.assertTrue('''<div class="comments-number">%s '''
118 self.assertTrue('''<div class="comments-number">%s '''
115 '''comment(s) (0 inline)</div>''' % 1 in response.body)
119 '''comment(s) (0 inline)</div>''' % 1 in response.body)
116
120
117 self.assertEqual(Notification.query().count(), 2)
121 self.assertEqual(Notification.query().count(), 2)
118 users = [x.user.username for x in UserNotification.query().all()]
122 users = [x.user.username for x in UserNotification.query().all()]
119
123
120 # test_regular get's notification by @mention
124 # test_regular get's notification by @mention
121 self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
125 self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
122
126
123 def test_delete(self):
127 def test_delete(self):
124 self.log_user()
128 self.log_user()
125 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
129 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
126 text = u'CommentOnRevision'
130 text = u'CommentOnRevision'
127
131
128 params = {'text': text}
132 params = {'text': text}
129 response = self.app.post(url(controller='changeset', action='comment',
133 response = self.app.post(url(controller='changeset', action='comment',
130 repo_name=HG_REPO, revision=rev),
134 repo_name=HG_REPO, revision=rev),
131 params=params)
135 params=params)
132
136
133 comments = ChangesetComment.query().all()
137 comments = ChangesetComment.query().all()
134 self.assertEqual(len(comments), 1)
138 self.assertEqual(len(comments), 1)
135 comment_id = comments[0].comment_id
139 comment_id = comments[0].comment_id
136
140
137 self.app.delete(url(controller='changeset',
141 self.app.delete(url(controller='changeset',
138 action='delete_comment',
142 action='delete_comment',
139 repo_name=HG_REPO,
143 repo_name=HG_REPO,
140 comment_id=comment_id))
144 comment_id=comment_id))
141
145
142 comments = ChangesetComment.query().all()
146 comments = ChangesetComment.query().all()
143 self.assertEqual(len(comments), 0)
147 self.assertEqual(len(comments), 0)
144
148
145 response = self.app.get(url(controller='changeset', action='index',
149 response = self.app.get(url(controller='changeset', action='index',
146 repo_name=HG_REPO, revision=rev))
150 repo_name=HG_REPO, revision=rev))
147 self.assertTrue('''<div class="comments-number">0 comment(s)'''
151 self.assertTrue('''<div class="comments-number">0 comment(s)'''
148 ''' (0 inline)</div>''' in response.body)
152 ''' (0 inline)</div>''' in response.body)
General Comments 0
You need to be logged in to leave comments. Login now