##// END OF EJS Templates
codingstyle: trivial whitespace fixes...
codingstyle: trivial whitespace fixes Reported by flake8.

File last commit:

r6789:76912908 default
r6789:76912908 default
Show More
test_admin_notifications.py
172 lines | 7.4 KiB | text/x-python | PythonLexer
/ kallithea / tests / functional / test_admin_notifications.py
Thomas De Schampheleire
tests: add as little code as possible in __init__.py...
r6180 from kallithea.tests.base import *
Mads Kiilerich
cleanup: remove unused imports...
r5397 from kallithea.model.db import User
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
from kallithea.model.user import UserModel
from kallithea.model.notification import NotificationModel
from kallithea.model.meta import Session
Peter Vitt
notifications: use different strings for descriptions with age and datetime...
r5114 from kallithea.lib import helpers as h
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Alessandro Molina
backend: replace Pylons with TurboGears2...
r6522 from tg.util.webtest import test_context
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Lars Kruse
codingstyle: trivial whitespace fixes...
r6789
Thomas De Schampheleire
pytest migration: rename TestControllerPytest back to TestController...
r5885 class TestNotificationsController(TestController):
Thomas De Schampheleire
pytest migration: convert functional tests with setup/teardown methods...
r5764 def setup_method(self, method):
Thomas De Schampheleire
pytest migration: backout declassification of remove_all_notifications...
r5883 self.remove_all_notifications()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Konstantin Veretennicov
tests: cleanup test users
r5940 def test_index(self, create_test_user):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.log_user()
Konstantin Veretennicov
tests: cleanup test users
r5940 u1 = create_test_user(dict(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1',
active=True))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 u1 = u1.user_id
Thomas De Schampheleire
test_admin_notifications: fix index test dependency...
r5763 Session().commit()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
response = self.app.get(url('notifications'))
Mads Kiilerich
style: rename div.table to Bootstrap .panel-body...
r6383 response.mustcontain('<div>No notifications here yet</div>')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
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()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 response = self.app.get(url('notifications'))
response.mustcontain('id="notification_%s"' % notif.notification_id)
Konstantin Veretennicov
tests: cleanup test users
r5940 def test_delete(self, create_test_user):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.log_user()
cur_user = self._get_logged_user()
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
u1 = create_test_user(dict(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1',
active=True))
u2 = create_test_user(dict(username='u2', password='qweqwe',
email='u2@example.com',
firstname=u'u2', lastname=u'u2',
active=True))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 # 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)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
# check DB
get_notif = lambda un: [x.notification for x in un]
Thomas De Schampheleire
pytest migration: functional: switch to standard assert statements...
r5877 assert get_notif(cur_user.notifications) == [notification]
assert get_notif(u1.notifications) == [notification]
assert get_notif(u2.notifications) == [notification]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 cur_usr_id = cur_user.user_id
Søren Løvborg
security: apply CSRF check to all non-GET requests...
r5471 response = self.app.post(
Mads Kiilerich
routing: introduce 'notification_delete' url and use POST instead of DELETE
r6039 url('notification_delete', notification_id=notification.notification_id),
params={'_authentication_token': self.authentication_token()})
Thomas De Schampheleire
pytest migration: functional: switch to standard assert statements...
r5877 assert response.body == 'ok'
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
cur_user = User.get(cur_usr_id)
Thomas De Schampheleire
pytest migration: functional: switch to standard assert statements...
r5877 assert cur_user.notifications == []
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Konstantin Veretennicov
tests: cleanup test users
r5940 def test_show(self, create_test_user):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.log_user()
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
cur_user = self._get_logged_user()
u1 = create_test_user(dict(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1',
active=True))
u2 = create_test_user(dict(username='u2', password='qweqwe',
email='u2@example.com',
firstname=u'u2', lastname=u'u2',
active=True))
Session().commit()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 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])
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
response = self.app.get(url('notification',
notification_id=notification.notification_id))
response.mustcontain(subject)
response.mustcontain(notif_body)
Peter Vitt
notifications: use different strings for descriptions with age and datetime...
r5114
def test_description_with_age(self):
self.log_user()
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
cur_user = self._get_logged_user()
subject = u'test'
notify_body = u'hi there'
Peter Vitt
notifications: use different strings for descriptions with age and datetime...
r5114
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 notification = NotificationModel().create(created_by = cur_user,
subject = subject,
body = notify_body)
description = NotificationModel().make_description(notification)
assert description == "{0} sent message {1}".format(
cur_user.username,
h.age(notification.created_on)
)
Peter Vitt
notifications: use different strings for descriptions with age and datetime...
r5114
def test_description_with_datetime(self):
self.log_user()
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
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)
Peter Vitt
notifications: use different strings for descriptions with age and datetime...
r5114
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 description = NotificationModel().make_description(notification, False)
assert description == "{0} sent message at {1}".format(
cur_user.username,
h.fmt_date(notification.created_on)
)
Konstantin Veretennicov
tests: add basic test for mark_all_read action of notifications...
r5941
def test_mark_all_read(self, create_test_user):
self.log_user()
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 with test_context(self.app):
u0 = self._get_logged_user()
u1 = create_test_user(dict(username='u1', password='qweqwe',
email='u1@example.com',
firstname=u'u1', lastname=u'u1',
active=True))
u2 = create_test_user(dict(username='u2', password='qweqwe',
email='u2@example.com',
firstname=u'u2', lastname=u'u2',
active=True))
notif = NotificationModel().create(created_by=u1,
subject=u'subject',
body=u'body',
recipients=[u0, u2])
u0_id, u1_id, u2_id = u0.user_id, u1.user_id, u2.user_id
Konstantin Veretennicov
tests: add basic test for mark_all_read action of notifications...
r5941
Thomas De Schampheleire
tests: use test_context for tests needing internationalization...
r6305 assert [n.read for n in u0.notifications] == [False]
assert u1.notifications == []
assert [n.read for n in u2.notifications] == [False]
Konstantin Veretennicov
tests: add basic test for mark_all_read action of notifications...
r5941
# Mark all read for current user.
response = self.app.get(url('notifications_mark_all_read'), # TODO: should be POST
extra_environ=dict(HTTP_X_PARTIAL_XHR='1'))
assert response.status_int == 200
response.mustcontain('id="notification_%s"' % notif.notification_id)
u0 = User.get(u0_id)
u1 = User.get(u1_id)
u2 = User.get(u2_id)
assert [n.read for n in u0.notifications] == [True]
assert u1.notifications == []
assert [n.read for n in u2.notifications] == [False]