1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 07:55:36 +00:00

fix bug of user notification (#3230)

* fix bug of user notification

add checks, add test cases for notifications
This commit is contained in:
Leo
2019-04-12 10:36:22 +08:00
committed by lian
parent 5d2a2b238c
commit e23fd72fc7
2 changed files with 45 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import json
from seahub.test_utils import BaseTestCase
from seahub.notifications.models import UserNotification
from seahub.base.accounts import UserManager
class NotificationsTest(BaseTestCase):
def setUp(self):
@@ -58,3 +59,29 @@ class NotificationTest(BaseTestCase):
self.assertEqual(200, resp.status_code)
assert UserNotification.objects.count_unseen_user_notifications(self.username) == 0
def test_argument_check_notice_id_invalid(self):
self.login_as(self.user)
data = 'notice_id=%s' % 'a'
resp = self.client.put(self.endpoint, data, 'application/x-www-form-urlencoded')
self.assertEqual(400, resp.status_code)
def test_resource_check_notification_not_found(self):
self.login_as(self.user)
notice1 = UserNotification.objects.add_user_message(self.username, 'test1')
notice2 = UserNotification.objects.add_user_message(self.username, 'test2')
data = 'notice_id=%s' % str(notice2.id + 1)
resp = self.client.put(self.endpoint, data, 'application/x-www-form-urlencoded')
self.assertEqual(404, resp.status_code)
def test_permission_check_permission_denied(self):
self.login_as(self.user)
new_user = UserManager().create_user(email='new@new.com', password='root')
notice_to_new_user = UserNotification.objects.add_user_message(new_user.name, 'test for new user')
data = 'notice_id=%s' % notice_to_new_user.id
resp = self.client.put(self.endpoint, data, 'application/x-www-form-urlencoded')
self.assertEqual(403, resp.status_code)