annotate rhodecode/tests/functional/test_admin_notifications.py @ 1712:cac5109ac3b6 beta

Notification system improvements - deleting - tests - ui - moved to separate controller
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 23 Nov 2011 00:55:05 +0200
parents
children 54687aa00724
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 *
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 from rhodecode.model.db import Notification, User, UserNotification
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
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 class TestNotificationsController(TestController):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 def test_index(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 email='u1@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 name='u1', lastname='u1').user_id
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 email='u2@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 name='u2', lastname='u2').user_id
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 response = self.app.get(url('notifications'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 self.assertTrue('''<div class="table">No notifications here yet</div>'''
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 in response.body)
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 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 NotificationModel().create(created_by=u1, subject=u'test',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 body=u'notification_1',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 recipients=[cur_user])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 response = self.app.get(url('notifications'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 self.assertTrue(u'notification_1' in response.body)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 User.delete(u1)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 User.delete(u2)
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',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 name='u1', lastname='u1')
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',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 name='u2', lastname='u2')
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 # make two notifications
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])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
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
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 self.assertEqual(u1.notifications, [notification])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 self.assertEqual(u2.notifications, [notification])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 cur_usr_id = cur_user.user_id
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 response = self.app.delete(url('notification',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 notification_id=cur_usr_id))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 self.assertEqual(cur_user.notifications, [])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 User.delete(u1.user_id)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 User.delete(u2.user_id)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 # def test_delete_browser_fakeout(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 # response = self.app.post(url('notification', notification_id=1), params=dict(_method='delete'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 def test_show(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 email='u1@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 name='u1', lastname='u1')
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 email='u2@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 name='u2', lastname='u2')
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 notification = NotificationModel().create(created_by=cur_user,
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 subject='test',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 body='hi there',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 recipients=[cur_user, u1, u2])
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 response = self.app.get(url('notification',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 notification_id=notification.notification_id))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 # def test_show_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 # response = self.app.get(url('formatted_notification', notification_id=1, format='xml'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 # def test_edit(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 # response = self.app.get(url('edit_notification', notification_id=1))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 # def test_edit_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 # response = self.app.get(url('formatted_edit_notification', notification_id=1, format='xml'))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117