annotate rhodecode/tests/functional/test_admin_notifications.py @ 3646:63e49418a4cc beta

Use only mustcontain for testing response body
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 31 Mar 2013 21:44:27 +0200
parents a45191e7c7bb
children d7488551578e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 from rhodecode.tests import *
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2513
diff changeset
2 from rhodecode.model.db import Notification, User
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from rhodecode.model.user import UserModel
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from rhodecode.model.notification import NotificationModel
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
7
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 class TestNotificationsController(TestController):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
10 def tearDown(self):
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
11 for n in Notification.query().all():
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
12 inst = Notification.get(n.notification_id)
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2513
diff changeset
13 self.Session().delete(inst)
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2513
diff changeset
14 self.Session().commit()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
15
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 def test_index(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 email='u1@rhodecode.org',
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
21 firstname='u1', lastname='u1')
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
22 u1 = u1.user_id
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 response = self.app.get(url('notifications'))
3646
63e49418a4cc Use only mustcontain for testing response body
Marcin Kuzminski <marcin@python-works.com>
parents: 3141
diff changeset
25 response.mustcontain('<div class="table">No notifications here yet</div>')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
29 NotificationModel().create(created_by=u1, subject=u'test_notification_1',
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 body=u'notification_1',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 recipients=[cur_user])
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2513
diff changeset
32 self.Session().commit()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 response = self.app.get(url('notifications'))
3646
63e49418a4cc Use only mustcontain for testing response body
Marcin Kuzminski <marcin@python-works.com>
parents: 3141
diff changeset
34 response.mustcontain(u'test_notification_1')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 # def test_index_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 # response = self.app.get(url('formatted_notifications', format='xml'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 # def test_create(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 # response = self.app.post(url('notifications'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 # def test_new(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 # response = self.app.get(url('new_notification'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 # def test_new_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 # response = self.app.get(url('formatted_new_notification', format='xml'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 # def test_update(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 # response = self.app.put(url('notification', notification_id=1))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 # def test_update_browser_fakeout(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 # response = self.app.post(url('notification', notification_id=1), params=dict(_method='put'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 def test_delete(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 email='u1@rhodecode.org',
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
60 firstname='u1', lastname='u1')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 email='u2@rhodecode.org',
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
63 firstname='u2', lastname='u2')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
65 # make notifications
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 notification = NotificationModel().create(created_by=cur_user,
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 subject=u'test',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 body=u'hi there',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 recipients=[cur_user, u1, u2])
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2513
diff changeset
70 self.Session().commit()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 u1 = User.get(u1.user_id)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 u2 = User.get(u2.user_id)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 # check DB
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
75 get_notif = lambda un: [x.notification for x in un]
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
76 self.assertEqual(get_notif(cur_user.notifications), [notification])
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
77 self.assertEqual(get_notif(u1.notifications), [notification])
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
78 self.assertEqual(get_notif(u2.notifications), [notification])
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 cur_usr_id = cur_user.user_id
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
80
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
81 response = self.app.delete(url('notification',
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
82 notification_id=
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
83 notification.notification_id))
3141
a45191e7c7bb access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents: 2529
diff changeset
84 self.assertEqual(response.body, 'ok')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
86 cur_user = User.get(cur_usr_id)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
87 self.assertEqual(cur_user.notifications, [])
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 def test_show(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 email='u1@rhodecode.org',
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
94 firstname='u1', lastname='u1')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 email='u2@rhodecode.org',
2513
388843a3a3c0 Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
97 firstname='u2', lastname='u2')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 notification = NotificationModel().create(created_by=cur_user,
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
100 subject=u'test',
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
101 body=u'hi there',
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 recipients=[cur_user, u1, u2])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 response = self.app.get(url('notification',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 notification_id=notification.notification_id))