test cases for admin user management, analytics and notification

This commit is contained in:
abutalib-kiwi
2023-09-12 14:40:50 +05:30
parent 373c1b70ab
commit 2444b6f55e
5 changed files with 569 additions and 3 deletions

View File

@ -0,0 +1,93 @@
"""
web admin test analytics file
"""
# django imports
from django.urls import reverse
from rest_framework import status
# local imports
from web_admin.tests.test_set_up import AnalyticsSetUp
class AnalyticsViewSetTestCase(AnalyticsSetUp):
"""
test cases for analytics, users count, new sign-ups,
assign tasks report, junior leaderboard, export excel
"""
def setUp(self) -> None:
"""
test data set up
:return:
"""
super(AnalyticsViewSetTestCase, self).setUp()
def test_total_sign_up_count(self):
"""
test total sign up count
:return:
"""
self.client.force_authenticate(self.admin_user)
url = reverse('web_admin:analytics-users-count')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assuming four users exists in the database
self.assertEqual(response.data['data']['total_users'], 4)
# Assuming two guardians exists in the database
self.assertEqual(response.data['data']['total_guardians'], 2)
# Assuming two juniors exists in the database
self.assertEqual(response.data['data']['total_juniors'], 2)
def test_new_user_sign_ups(self):
"""
test new user sign-ups
:return:
"""
self.client.force_authenticate(self.admin_user)
url = reverse('web_admin:analytics-new-signups')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assuming four users exists in the database
self.assertEqual(response.data['data'][0]['signups'], 4)
def test_assign_tasks_report(self):
"""
test assign tasks report
:return:
"""
self.client.force_authenticate(self.admin_user)
url = reverse('web_admin:analytics-assign-tasks')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assuming two completed tasks exists in the database
self.assertEqual(response.data['data']['task_completed'], 2)
# Assuming two pending tasks exists in the database
self.assertEqual(response.data['data']['task_pending'], 2)
# Assuming two in progress tasks exists in the database
self.assertEqual(response.data['data']['task_in_progress'], 2)
# Assuming two requested tasks exists in the database
self.assertEqual(response.data['data']['task_requested'], 2)
# Assuming two rejected tasks exists in the database
self.assertEqual(response.data['data']['task_rejected'], 2)
# Assuming two expired tasks exists in the database
self.assertEqual(response.data['data']['task_expired'], 2)
def test_junior_leaderboard(self):
"""
test junior leaderboard
:return:
"""
self.client.force_authenticate(self.admin_user)
url = reverse('web_admin:analytics-junior-leaderboard')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_export_excel(self):
"""
test export excel
:return:
"""
self.client.force_authenticate(self.admin_user)
url = reverse('web_admin:analytics-export-excel')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertURLEqual(response.data['data'], self.export_excel_url)