mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
"""
|
|
notification test file
|
|
"""
|
|
# third party imports
|
|
from fcm_django.models import FCMDevice
|
|
|
|
# django imports
|
|
from django.urls import reverse
|
|
from rest_framework import status
|
|
|
|
# local imports
|
|
from account.serializers import GuardianSerializer
|
|
from notifications.models import Notification
|
|
from web_admin.tests.test_set_up import AnalyticsSetUp
|
|
|
|
|
|
class NotificationTestCase(AnalyticsSetUp):
|
|
"""
|
|
test notification
|
|
"""
|
|
def setUp(self) -> None:
|
|
"""
|
|
test data up
|
|
:return:
|
|
"""
|
|
super(NotificationTestCase, self).setUp()
|
|
|
|
# notification create
|
|
self.notification = Notification.objects.create(notification_to=self.user)
|
|
|
|
# to get guardian/user auth token
|
|
self.guardian_data = GuardianSerializer(
|
|
self.guardian, context={'user_type': 2}
|
|
).data
|
|
self.auth_token = self.guardian_data['auth_token']
|
|
|
|
# api header
|
|
self.header = {
|
|
'HTTP_AUTHORIZATION': f'Bearer {self.auth_token}',
|
|
'Content-Type': "Application/json"
|
|
}
|
|
|
|
def test_notification_list(self):
|
|
"""
|
|
test notification list
|
|
:return:
|
|
"""
|
|
|
|
url = reverse('notifications:notifications-list')
|
|
response = self.client.get(url, **self.header)
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
# Assuming only one notification exists in the database
|
|
self.assertEqual(Notification.objects.filter(notification_to=self.user).count(), 1)
|
|
|
|
def test_fcm_register(self):
|
|
"""
|
|
test fcm register
|
|
:return:
|
|
"""
|
|
url = reverse('notifications:notifications-device')
|
|
data = {
|
|
'registration_id': 'registration_id',
|
|
'device_id': 'device_id',
|
|
'type': 'ios'
|
|
}
|
|
response = self.client.post(url, data, **self.header)
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
# device created for user
|
|
self.assertEqual(FCMDevice.objects.count(), 1)
|
|
|
|
def test_send_test_notification(self):
|
|
"""
|
|
test send test notification
|
|
:return:
|
|
"""
|
|
url = reverse('notifications:notifications-list')
|
|
response = self.client.get(url, **self.header)
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
# Assuming only one notification exists in the database
|
|
self.assertEqual(Notification.objects.filter(notification_to=self.user).count(), 1)
|
|
|
|
def test_mark_as_read(self):
|
|
"""
|
|
test mark as read
|
|
:return:
|
|
"""
|
|
url = reverse('notifications:notifications-mark-as-read')
|
|
data = {
|
|
'id': [self.notification.id]
|
|
}
|
|
response = self.client.patch(url, data, **self.header)
|
|
self.notification.refresh_from_db()
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
self.assertEqual(self.notification.is_read, True)
|