Files
@ ebf5f02f13e2
Branch filter:
Location: kallithea/kallithea/tests/functional/test_admin_notifications.py
ebf5f02f13e2
5.1 KiB
text/x-python
i18n: updated translation for Chinese (China)
Currently translated at 39.8% (452 of 1135 strings)
Currently translated at 39.8% (452 of 1135 strings)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | from kallithea.tests import *
from kallithea.model.db import User
from kallithea.model.user import UserModel
from kallithea.model.notification import NotificationModel
from kallithea.model.meta import Session
from kallithea.lib import helpers as h
class TestNotificationsController(TestController):
def setUp(self):
remove_all_notifications()
def test_index(self):
self.log_user()
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1')
u1 = u1.user_id
response = self.app.get(url('notifications'))
response.mustcontain('<div class="table">No notifications here yet</div>')
cur_user = self._get_logged_user()
notif = NotificationModel().create(created_by=u1, subject=u'test_notification_1',
body=u'notification_1', recipients=[cur_user])
Session().commit()
response = self.app.get(url('notifications'))
response.mustcontain('id="notification_%s"' % notif.notification_id)
def test_delete(self):
self.log_user()
cur_user = self._get_logged_user()
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1')
u2 = UserModel().create_or_update(username='u2', password='qweqwe',
email='u2@example.com',
firstname=u'u2', lastname=u'u2')
# make notifications
notification = NotificationModel().create(created_by=cur_user,
subject=u'test',
body=u'hi there',
recipients=[cur_user, u1, u2])
Session().commit()
u1 = User.get(u1.user_id)
u2 = User.get(u2.user_id)
# check DB
get_notif = lambda un: [x.notification for x in un]
self.assertEqual(get_notif(cur_user.notifications), [notification])
self.assertEqual(get_notif(u1.notifications), [notification])
self.assertEqual(get_notif(u2.notifications), [notification])
cur_usr_id = cur_user.user_id
response = self.app.post(
url('notification', notification_id=notification.notification_id),
params={'_method': 'delete', '_authentication_token': self.authentication_token()})
self.assertEqual(response.body, 'ok')
cur_user = User.get(cur_usr_id)
self.assertEqual(cur_user.notifications, [])
def test_show(self):
self.log_user()
cur_user = self._get_logged_user()
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1')
u2 = UserModel().create_or_update(username='u2', password='qweqwe',
email='u2@example.com',
firstname=u'u2', lastname=u'u2')
subject = u'test'
notif_body = u'hi there'
notification = NotificationModel().create(created_by=cur_user,
subject=subject,
body=notif_body,
recipients=[cur_user, u1, u2])
response = self.app.get(url('notification',
notification_id=notification.notification_id))
response.mustcontain(subject)
response.mustcontain(notif_body)
def test_description_with_age(self):
self.log_user()
cur_user = self._get_logged_user()
subject = u'test'
notify_body = u'hi there'
notification = NotificationModel().create(created_by = cur_user,
subject = subject,
body = notify_body)
description = NotificationModel().make_description(notification)
self.assertEqual(
description,
"{0} sent message {1}".format(
cur_user.username,
h.age(notification.created_on)
)
)
def test_description_with_datetime(self):
self.log_user()
cur_user = self._get_logged_user()
subject = u'test'
notify_body = u'hi there'
notification = NotificationModel().create(created_by = cur_user,
subject = subject,
body = notify_body)
description = NotificationModel().make_description(notification, False)
self.assertEqual(
description,
"{0} sent message at {1}".format(
cur_user.username,
h.fmt_date(notification.created_on)
)
)
|