annotate rhodecode/tests/functional/test_admin_notifications.py @ 1749:8ecc6b8229a5 beta

commit less models - models don't do any commits(with few exceptions) - all db transactions should be handled by higher level modules like controllers, celery tasks
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 02 Dec 2011 22:31:13 +0200
parents 64e91067b996
children 388843a3a3c0
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
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
6 from rhodecode.model.meta import Session
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
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
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)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
14 Session.delete(inst)
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
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',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 name='u1', lastname='u1').user_id
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])
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
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'))
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',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 name='u1', lastname='u1')
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',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 name='u2', lastname='u2')
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])
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
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
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
76 get_notif = lambda un:[x.notification for x in un]
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
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
83 response = self.app.delete(url('notification',
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
84 notification_id=
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
85 notification.notification_id))
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
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 # def test_delete_browser_fakeout(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 # 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
93
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 def test_show(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 email='u1@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 name='u1', lastname='u1')
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 email='u2@rhodecode.org',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 name='u2', lastname='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 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
105 subject=u'test',
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
106 body=u'hi there',
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 recipients=[cur_user, u1, u2])
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 response = self.app.get(url('notification',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 notification_id=notification.notification_id))
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_show_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 # 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
114 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 # def test_edit(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 # response = self.app.get(url('edit_notification', notification_id=1))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 #
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 # def test_edit_as_xml(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 # response = self.app.get(url('formatted_edit_notification', notification_id=1, format='xml'))