annotate rhodecode/tests/functional/test_admin_notifications.py @ 4183:da3c57422ee6 kallithea-2.2.5-rebrand

Change domain used for email addresses in tests
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:55 -0400
parents ffd45b185016
children 7e5f8c12a3fc
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',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
21 email='u1@example.com',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
22 firstname='u1', lastname='u1')
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
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()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
29 notif = NotificationModel().create(created_by=u1, subject=u'test_notification_1',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
30 body=u'notification_1', recipients=[cur_user])
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
31 Session().commit()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 response = self.app.get(url('notifications'))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
33 response.mustcontain('id="notification_%s"' % notif.notification_id)
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 def test_delete(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 cur_user = self._get_logged_user()
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 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
40 email='u1@example.com',
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
41 firstname='u1', lastname='u1')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
43 email='u2@example.com',
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
44 firstname='u2', lastname='u2')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
46 # make notifications
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 notification = NotificationModel().create(created_by=cur_user,
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 subject=u'test',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 body=u'hi there',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 recipients=[cur_user, u1, u2])
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
51 Session().commit()
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 u1 = User.get(u1.user_id)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 u2 = User.get(u2.user_id)
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 # 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
56 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
57 self.assertEqual(get_notif(cur_user.notifications), [notification])
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
58 self.assertEqual(get_notif(u1.notifications), [notification])
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
59 self.assertEqual(get_notif(u2.notifications), [notification])
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 cur_usr_id = cur_user.user_id
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
61
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
62 response = self.app.delete(url('notification',
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
63 notification_id=
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
64 notification.notification_id))
3141
a45191e7c7bb access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents: 2529
diff changeset
65 self.assertEqual(response.body, 'ok')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
67 cur_user = User.get(cur_usr_id)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
68 self.assertEqual(cur_user.notifications, [])
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 def test_show(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 self.log_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 cur_user = self._get_logged_user()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 u1 = UserModel().create_or_update(username='u1', password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
74 email='u1@example.com',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
75 firstname='u1', lastname='u1')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 u2 = UserModel().create_or_update(username='u2', password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
77 email='u2@example.com',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
78 firstname='u2', lastname='u2')
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
80 subject = u'test'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
81 notif_body = u'hi there'
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 notification = NotificationModel().create(created_by=cur_user,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
83 subject=subject,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
84 body=notif_body,
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 recipients=[cur_user, u1, u2])
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 response = self.app.get(url('notification',
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 notification_id=notification.notification_id))
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
89
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
90 response.mustcontain(subject)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3797
diff changeset
91 response.mustcontain(notif_body)