Mercurial > kallithea
annotate rhodecode/tests/functional/test_admin_notifications.py @ 3141:a45191e7c7bb beta
access control: fix owner checks - they were always true
The lambda expressions seems to be left over from something else. They were no
longer executed and thus always evaluated to true.
Some of the functions also failed if they were executed.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jan 2013 13:56:44 +0100 |
parents | 40b3a54391f9 |
children | 63e49418a4cc |
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')) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 self.assertTrue('''<div class="table">No notifications here yet</div>''' |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 in response.body) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 cur_user = self._get_logged_user() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
30 NotificationModel().create(created_by=u1, subject=u'test_notification_1', |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 body=u'notification_1', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 recipients=[cur_user]) |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2513
diff
changeset
|
33 self.Session().commit() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 response = self.app.get(url('notifications')) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
35 self.assertTrue(u'test_notification_1' in response.body) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 # def test_index_as_xml(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 # response = self.app.get(url('formatted_notifications', format='xml')) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 # |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 # def test_create(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 # response = self.app.post(url('notifications')) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 # |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 # def test_new(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 # response = self.app.get(url('new_notification')) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 # |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 # def test_new_as_xml(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 # response = self.app.get(url('formatted_new_notification', format='xml')) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 # |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 # def test_update(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 # response = self.app.put(url('notification', notification_id=1)) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 # |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 # def test_update_browser_fakeout(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 # 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
|
54 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 def test_delete(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 self.log_user() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 cur_user = self._get_logged_user() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 u1 = UserModel().create_or_update(username='u1', password='qweqwe', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 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
|
61 firstname='u1', lastname='u1') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 u2 = UserModel().create_or_update(username='u2', password='qweqwe', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 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
|
64 firstname='u2', lastname='u2') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
66 # make notifications |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 notification = NotificationModel().create(created_by=cur_user, |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 subject=u'test', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 body=u'hi there', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 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
|
71 self.Session().commit() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 u1 = User.get(u1.user_id) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 u2 = User.get(u2.user_id) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 # 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
|
76 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
|
77 self.assertEqual(get_notif(cur_user.notifications), [notification]) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
78 self.assertEqual(get_notif(u1.notifications), [notification]) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
79 self.assertEqual(get_notif(u2.notifications), [notification]) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 cur_usr_id = cur_user.user_id |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
81 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
82 response = self.app.delete(url('notification', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
83 notification_id= |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
84 notification.notification_id)) |
3141
a45191e7c7bb
access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents:
2529
diff
changeset
|
85 self.assertEqual(response.body, 'ok') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
87 cur_user = User.get(cur_usr_id) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
88 self.assertEqual(cur_user.notifications, []) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 def test_show(self): |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 self.log_user() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 cur_user = self._get_logged_user() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 u1 = UserModel().create_or_update(username='u1', password='qweqwe', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 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
|
95 firstname='u1', lastname='u1') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 u2 = UserModel().create_or_update(username='u2', password='qweqwe', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 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
|
98 firstname='u2', lastname='u2') |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 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
|
101 subject=u'test', |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
102 body=u'hi there', |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 recipients=[cur_user, u1, u2]) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 response = self.app.get(url('notification', |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 notification_id=notification.notification_id)) |