test_admin_notifications.py
91 lines
| 3.9 KiB
| text/x-python
|
PythonLexer
r1712 | from rhodecode.tests import * | |||
r2529 | from rhodecode.model.db import Notification, User | |||
r1712 | ||||
from rhodecode.model.user import UserModel | ||||
from rhodecode.model.notification import NotificationModel | ||||
r3797 | from rhodecode.model.meta import Session | |||
r1712 | ||||
r2513 | ||||
r1712 | class TestNotificationsController(TestController): | |||
r1713 | def tearDown(self): | |||
for n in Notification.query().all(): | ||||
inst = Notification.get(n.notification_id) | ||||
r3797 | Session().delete(inst) | |||
Session().commit() | ||||
r1713 | ||||
r1712 | def test_index(self): | |||
self.log_user() | ||||
u1 = UserModel().create_or_update(username='u1', password='qweqwe', | ||||
|
r4116 | email='u1@rhodecode.org', | ||
firstname='u1', lastname='u1') | ||||
r2513 | u1 = u1.user_id | |||
r1712 | ||||
response = self.app.get(url('notifications')) | ||||
r3646 | response.mustcontain('<div class="table">No notifications here yet</div>') | |||
r1712 | ||||
cur_user = self._get_logged_user() | ||||
|
r4116 | notif = NotificationModel().create(created_by=u1, subject=u'test_notification_1', | ||
body=u'notification_1', recipients=[cur_user]) | ||||
r3797 | Session().commit() | |||
r1712 | response = self.app.get(url('notifications')) | |||
|
r4116 | response.mustcontain('id="notification_%s"' % notif.notification_id) | ||
r1712 | ||||
def test_delete(self): | ||||
self.log_user() | ||||
cur_user = self._get_logged_user() | ||||
u1 = UserModel().create_or_update(username='u1', password='qweqwe', | ||||
email='u1@rhodecode.org', | ||||
r2513 | firstname='u1', lastname='u1') | |||
r1712 | u2 = UserModel().create_or_update(username='u2', password='qweqwe', | |||
email='u2@rhodecode.org', | ||||
r2513 | firstname='u2', lastname='u2') | |||
r1712 | ||||
r1713 | # make notifications | |||
r1712 | notification = NotificationModel().create(created_by=cur_user, | |||
subject=u'test', | ||||
body=u'hi there', | ||||
recipients=[cur_user, u1, u2]) | ||||
r3797 | Session().commit() | |||
r1712 | u1 = User.get(u1.user_id) | |||
u2 = User.get(u2.user_id) | ||||
# check DB | ||||
r2513 | get_notif = lambda un: [x.notification for x in un] | |||
r1713 | self.assertEqual(get_notif(cur_user.notifications), [notification]) | |||
self.assertEqual(get_notif(u1.notifications), [notification]) | ||||
self.assertEqual(get_notif(u2.notifications), [notification]) | ||||
r1712 | cur_usr_id = cur_user.user_id | |||
r1713 | ||||
response = self.app.delete(url('notification', | ||||
notification_id= | ||||
notification.notification_id)) | ||||
|
r3141 | self.assertEqual(response.body, 'ok') | ||
r1712 | ||||
r1713 | cur_user = User.get(cur_usr_id) | |||
self.assertEqual(cur_user.notifications, []) | ||||
r1712 | ||||
def test_show(self): | ||||
self.log_user() | ||||
cur_user = self._get_logged_user() | ||||
u1 = UserModel().create_or_update(username='u1', password='qweqwe', | ||||
|
r4116 | email='u1@rhodecode.org', | ||
firstname='u1', lastname='u1') | ||||
r1712 | u2 = UserModel().create_or_update(username='u2', password='qweqwe', | |||
|
r4116 | email='u2@rhodecode.org', | ||
firstname='u2', lastname='u2') | ||||
r1712 | ||||
|
r4116 | subject = u'test' | ||
notif_body = u'hi there' | ||||
r1712 | notification = NotificationModel().create(created_by=cur_user, | |||
|
r4116 | subject=subject, | ||
body=notif_body, | ||||
r1712 | recipients=[cur_user, u1, u2]) | |||
response = self.app.get(url('notification', | ||||
notification_id=notification.notification_id)) | ||||
|
r4116 | |||
response.mustcontain(subject) | ||||
response.mustcontain(notif_body) | ||||