comparison 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
comparison
equal deleted inserted replaced
1711:b369bec5d468 1712:cac5109ac3b6
1 from rhodecode.tests import *
2 from rhodecode.model.db import Notification, User, UserNotification
3
4 from rhodecode.model.user import UserModel
5 from rhodecode.model.notification import NotificationModel
6
7 class TestNotificationsController(TestController):
8
9 def test_index(self):
10 self.log_user()
11
12
13 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
14 email='u1@rhodecode.org',
15 name='u1', lastname='u1').user_id
16 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
17 email='u2@rhodecode.org',
18 name='u2', lastname='u2').user_id
19
20 response = self.app.get(url('notifications'))
21 self.assertTrue('''<div class="table">No notifications here yet</div>'''
22 in response.body)
23
24 cur_user = self._get_logged_user()
25
26 NotificationModel().create(created_by=u1, subject=u'test',
27 body=u'notification_1',
28 recipients=[cur_user])
29 response = self.app.get(url('notifications'))
30
31 self.assertTrue(u'notification_1' in response.body)
32
33 User.delete(u1)
34 User.delete(u2)
35
36 # def test_index_as_xml(self):
37 # response = self.app.get(url('formatted_notifications', format='xml'))
38 #
39 # def test_create(self):
40 # response = self.app.post(url('notifications'))
41 #
42 # def test_new(self):
43 # response = self.app.get(url('new_notification'))
44 #
45 # def test_new_as_xml(self):
46 # response = self.app.get(url('formatted_new_notification', format='xml'))
47 #
48 # def test_update(self):
49 # response = self.app.put(url('notification', notification_id=1))
50 #
51 # def test_update_browser_fakeout(self):
52 # response = self.app.post(url('notification', notification_id=1), params=dict(_method='put'))
53
54 def test_delete(self):
55 self.log_user()
56 cur_user = self._get_logged_user()
57
58 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
59 email='u1@rhodecode.org',
60 name='u1', lastname='u1')
61 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
62 email='u2@rhodecode.org',
63 name='u2', lastname='u2')
64
65 # make two notifications
66 notification = NotificationModel().create(created_by=cur_user,
67 subject=u'test',
68 body=u'hi there',
69 recipients=[cur_user, u1, u2])
70
71 u1 = User.get(u1.user_id)
72 u2 = User.get(u2.user_id)
73
74 # check DB
75 self.assertEqual(u1.notifications, [notification])
76 self.assertEqual(u2.notifications, [notification])
77 cur_usr_id = cur_user.user_id
78 response = self.app.delete(url('notification',
79 notification_id=cur_usr_id))
80
81 cur_user = self._get_logged_user()
82 self.assertEqual(cur_user.notifications, [])
83
84 User.delete(u1.user_id)
85 User.delete(u2.user_id)
86
87
88 # def test_delete_browser_fakeout(self):
89 # response = self.app.post(url('notification', notification_id=1), params=dict(_method='delete'))
90
91 def test_show(self):
92 self.log_user()
93 cur_user = self._get_logged_user()
94 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
95 email='u1@rhodecode.org',
96 name='u1', lastname='u1')
97 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
98 email='u2@rhodecode.org',
99 name='u2', lastname='u2')
100
101 notification = NotificationModel().create(created_by=cur_user,
102 subject='test',
103 body='hi there',
104 recipients=[cur_user, u1, u2])
105
106 response = self.app.get(url('notification',
107 notification_id=notification.notification_id))
108
109 # def test_show_as_xml(self):
110 # response = self.app.get(url('formatted_notification', notification_id=1, format='xml'))
111 #
112 # def test_edit(self):
113 # response = self.app.get(url('edit_notification', notification_id=1))
114 #
115 # def test_edit_as_xml(self):
116 # response = self.app.get(url('formatted_edit_notification', notification_id=1, format='xml'))
117