mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
test cases for admin user management, analytics and notification
This commit is contained in:
@ -1,6 +1,94 @@
|
||||
"""
|
||||
notification test file
|
||||
"""
|
||||
from django.test import TestCase
|
||||
# third party imports
|
||||
from fcm_django.models import FCMDevice
|
||||
|
||||
# Create your tests here.
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user