annotate rhodecode/tests/functional/test_admin_notifications.py @ 3797:d7488551578e beta

synced vcs with upstream - moved subprocessio module to VCS - many small changes to make embedded vcs as similar to to external lib - use only absolute imports - patch vcs config during load pylons env
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 27 Apr 2013 11:24:25 +0200
parents 63e49418a4cc
children ffd45b185016
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
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
6 from rhodecode.model.meta import Session
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
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
8
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 class TestNotificationsController(TestController):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
11 def tearDown(self):
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
12 for n in Notification.query().all():
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
13 inst = Notification.get(n.notification_id)
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
14 Session().delete(inst)
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
15 Session().commit()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
16
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 def test_index(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 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
22 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
23 u1 = u1.user_id
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 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
26 response.mustcontain('<div class="table">No notifications here yet</div>')
1712
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])
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
33 Session().commit()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 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
35 response.mustcontain(u'test_notification_1')
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])
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
71 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))