diff --git a/rhodecode/apps/my_account/__init__.py b/rhodecode/apps/my_account/__init__.py --- a/rhodecode/apps/my_account/__init__.py +++ b/rhodecode/apps/my_account/__init__.py @@ -95,6 +95,28 @@ def includeme(config): name='my_account_pullrequests_data', pattern=ADMIN_PREFIX + '/my_account/pull_requests/data') + # notifications + config.add_route( + name='notifications_show_all', + pattern=ADMIN_PREFIX + '/notifications') + + # notifications + config.add_route( + name='notifications_mark_all_read', + pattern=ADMIN_PREFIX + '/notifications/mark_all_read') + + config.add_route( + name='notifications_show', + pattern=ADMIN_PREFIX + '/notifications/{notification_id}') + + config.add_route( + name='notifications_update', + pattern=ADMIN_PREFIX + '/notifications/{notification_id}/update') + + config.add_route( + name='notifications_delete', + pattern=ADMIN_PREFIX + '/notifications/{notification_id}/delete') + # channelstream test config.add_route( name='my_account_notifications_test_channelstream', diff --git a/rhodecode/tests/functional/test_admin_notifications.py b/rhodecode/apps/my_account/tests/test_my_account_notifications.py rename from rhodecode/tests/functional/test_admin_notifications.py rename to rhodecode/apps/my_account/tests/test_my_account_notifications.py --- a/rhodecode/tests/functional/test_admin_notifications.py +++ b/rhodecode/apps/my_account/tests/test_my_account_notifications.py @@ -20,7 +20,10 @@ import pytest -from rhodecode.tests import * +from rhodecode.apps._base import ADMIN_PREFIX +from rhodecode.tests import ( + TestController, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, + TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) from rhodecode.tests.fixture import Fixture from rhodecode.model.db import Notification, User @@ -31,12 +34,25 @@ from rhodecode.model.meta import Session fixture = Fixture() -class TestNotificationsController(TestController): - destroy_users = set() +def route_path(name, params=None, **kwargs): + import urllib + from rhodecode.apps._base import ADMIN_PREFIX - @classmethod - def teardown_class(cls): - fixture.destroy_users(cls.destroy_users) + base_url = { + 'notifications_show_all': ADMIN_PREFIX + '/notifications', + 'notifications_mark_all_read': ADMIN_PREFIX + '/notifications/mark_all_read', + 'notifications_show': ADMIN_PREFIX + '/notifications/{notification_id}', + 'notifications_update': ADMIN_PREFIX + '/notifications/{notification_id}/update', + 'notifications_delete': ADMIN_PREFIX + '/notifications/{notification_id}/delete', + + }[name].format(**kwargs) + + if params: + base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) + return base_url + + +class TestNotificationsController(TestController): def teardown_method(self, method): for n in Notification.query().all(): @@ -44,43 +60,61 @@ class TestNotificationsController(TestCo Session().delete(inst) Session().commit() - def test_index(self): - u1 = UserModel().create_or_update( - username='u1', password='qweqwe', email='u1@rhodecode.org', - firstname='u1', lastname='u1') - u1 = u1.user_id - self.destroy_users.add('u1') + def test_show_all(self, user_util): + user = user_util.create_user(password='qweqwe') + user_id = user.user_id + self.log_user(user.username, 'qweqwe') - self.log_user('u1', 'qweqwe') - - response = self.app.get(url('notifications')) + response = self.app.get( + route_path('notifications_show_all', params={'type': 'all'})) response.mustcontain( '
No notifications here yet
') - cur_user = self._get_logged_user() - notif = NotificationModel().create( - created_by=u1, notification_subject=u'test_notification_1', - notification_body=u'notification_1', recipients=[cur_user]) + notification = NotificationModel().create( + created_by=user_id, notification_subject=u'test_notification_1', + notification_body=u'notification_1', recipients=[user_id]) Session().commit() - response = self.app.get(url('notifications')) - response.mustcontain('id="notification_%s"' % notif.notification_id) + notification_id = notification.notification_id + + response = self.app.get(route_path('notifications_show_all', + params={'type': 'all'})) + response.mustcontain('id="notification_%s"' % notification_id) + + def test_show_unread(self, user_util): + user = user_util.create_user(password='qweqwe') + user_id = user.user_id + self.log_user(user.username, 'qweqwe') + + response = self.app.get(route_path('notifications_show_all')) + response.mustcontain( + '
No notifications here yet
') + + notification = NotificationModel().create( + created_by=user_id, notification_subject=u'test_notification_1', + notification_body=u'notification_1', recipients=[user_id]) + + # mark the USER notification as unread + user_notification = NotificationModel().get_user_notification( + user_id, notification) + user_notification.read = False + + Session().commit() + notification_id = notification.notification_id + + response = self.app.get(route_path('notifications_show_all')) + response.mustcontain('id="notification_%s"' % notification_id) + response.mustcontain(' - + diff --git a/rhodecode/templates/admin/notifications/notifications.mako b/rhodecode/templates/admin/notifications/notifications_show_all.mako rename from rhodecode/templates/admin/notifications/notifications.mako rename to rhodecode/templates/admin/notifications/notifications_show_all.mako --- a/rhodecode/templates/admin/notifications/notifications.mako +++ b/rhodecode/templates/admin/notifications/notifications_show_all.mako @@ -13,66 +13,56 @@ <%def name="menu_bar_nav()"> - ${self.menu_items(active='admin')} + ${self.menu_items(active='my_account')} <%def name="main()">
- -
- ${self.breadcrumbs()} - ## - +
+ ${self.breadcrumbs()}
- ${_('All')} - ${_('Comments')} - ${_('Pull Requests')} - %if c.notifications: - - ${_('Mark all as read')} - + + %else: + %endif
+
+ + + diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -359,11 +359,7 @@
%if c.rhodecode_user.username != h.DEFAULT_USER:
- % if c.unread_notifications == 0: - ${c.unread_notifications} - % else: - ${c.unread_notifications} - % endif + ${c.unread_notifications}
% endif