# Copyright (C) 2010-2024 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License, version 3 # (only), as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ import pytest from rhodecode.tests import ( TestController, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) from rhodecode.tests.fixtures.rc_fixture import Fixture from rhodecode.tests.routes import route_path from rhodecode.model.db import Notification, User from rhodecode.model.notification import NotificationModel from rhodecode.model.meta import Session fixture = Fixture() class TestNotificationsController(TestController): def teardown_method(self, method): for n in Notification.query().all(): inst = Notification.get(n.notification_id) Session().delete(inst) Session().commit() def test_mark_all_read(self, user_util): user = user_util.create_user(password='qweqwe') self.log_user(user.username, 'qweqwe') self.app.post( route_path('notifications_mark_all_read'), status=302, params={'csrf_token': self.csrf_token} ) 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') response = self.app.get( route_path('notifications_show_all', params={'type': '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]) Session().commit() 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('