mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
test cases for admin user management, analytics and notification
This commit is contained in:
@ -1,6 +1,94 @@
|
|||||||
"""
|
"""
|
||||||
notification test file
|
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)
|
||||||
|
93
web_admin/tests/test_analytics.py
Normal file
93
web_admin/tests/test_analytics.py
Normal 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)
|
@ -4,10 +4,13 @@ web_admin test set up file
|
|||||||
# django imports
|
# django imports
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.conf import settings
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
|
from guardian.models import Guardian, JuniorTask
|
||||||
|
from junior.models import Junior, JuniorPoints
|
||||||
from web_admin.models import Article, ArticleCard, ArticleSurvey, SurveyOption
|
from web_admin.models import Article, ArticleCard, ArticleSurvey, SurveyOption
|
||||||
|
|
||||||
# user model
|
# user model
|
||||||
@ -102,6 +105,9 @@ base64_image = ("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBIS
|
|||||||
"rOORsR8oQkxdazE9A8QostdSBuBFvlKI6PY6ibg0z4VCscJi9WK3WzRiwmRqGHY3vndi5Hnebangse2hrpSHBEAjhE6rXj"
|
"rOORsR8oQkxdazE9A8QostdSBuBFvlKI6PY6ibg0z4VCscJi9WK3WzRiwmRqGHY3vndi5Hnebangse2hrpSHBEAjhE6rXj"
|
||||||
"GYdEC/arYms/HtkfAS7huhuDXXJmPEkn5whN4xrZ0NkYdPRpIPdLS0kG5QPdCEskKlYcIWHCEJUO3KFuUIQD3QhCB//Z")
|
"GYdEC/arYms/HtkfAS7huhuDXXJmPEkn5whN4xrZ0NkYdPRpIPdLS0kG5QPdCEskKlYcIWHCEJUO3KFuUIQD3QhCB//Z")
|
||||||
|
|
||||||
|
export_excel_path = 'analytics/ZOD_Bank_Analytics.xlsx'
|
||||||
|
export_excel_url = f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{export_excel_path}"
|
||||||
|
|
||||||
|
|
||||||
class BaseSetUp(APITestCase):
|
class BaseSetUp(APITestCase):
|
||||||
"""
|
"""
|
||||||
@ -146,7 +152,10 @@ class ArticleTestSetUp(BaseSetUp):
|
|||||||
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 1", is_answer=True)
|
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 1", is_answer=True)
|
||||||
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 2", is_answer=False)
|
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 2", is_answer=False)
|
||||||
|
|
||||||
|
# article api url used for get api
|
||||||
self.article_list_url = 'web_admin:article-list'
|
self.article_list_url = 'web_admin:article-list'
|
||||||
|
|
||||||
|
# article api url used for post api
|
||||||
self.article_detail_url = 'web_admin:article-detail'
|
self.article_detail_url = 'web_admin:article-detail'
|
||||||
|
|
||||||
# article card data with default card image
|
# article card data with default card image
|
||||||
@ -247,3 +256,124 @@ class ArticleTestSetUp(BaseSetUp):
|
|||||||
# added new articles
|
# added new articles
|
||||||
}] + self.article_survey_data
|
}] + self.article_survey_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UserManagementSetUp(BaseSetUp):
|
||||||
|
"""
|
||||||
|
test cases for user management
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
"""
|
||||||
|
data setup
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
super(UserManagementSetUp, self).setUp()
|
||||||
|
# guardian codes
|
||||||
|
self.guardian_code_1 = 'GRD123'
|
||||||
|
self.guardian_code_2 = 'GRD456'
|
||||||
|
|
||||||
|
# guardian 1
|
||||||
|
self.guardian = Guardian.objects.create(user=self.user, country_code=91, phone='8765876565',
|
||||||
|
country_name='India', gender=2, is_verified=True,
|
||||||
|
guardian_code=self.guardian_code_1)
|
||||||
|
|
||||||
|
# user 2
|
||||||
|
self.user_email_2 = 'user2@yopmail.com'
|
||||||
|
self.user_2 = User.objects.create_user(username=self.user_email_2, email=self.user_email_2)
|
||||||
|
self.user_2.set_password('user2@1234')
|
||||||
|
self.user_2.save()
|
||||||
|
|
||||||
|
# guardian 2
|
||||||
|
self.guardian_2 = Guardian.objects.create(user=self.user_2, country_code=92, phone='8765876575',
|
||||||
|
country_name='India', gender=1, is_verified=True,
|
||||||
|
guardian_code=self.guardian_code_2)
|
||||||
|
|
||||||
|
# user 3
|
||||||
|
self.user_email_3 = 'user3@yopmail.com'
|
||||||
|
self.user_3 = User.objects.create_user(username=self.user_email_3, email=self.user_email_3)
|
||||||
|
self.user_3.set_password('user3@1234')
|
||||||
|
self.user_3.save()
|
||||||
|
|
||||||
|
# junior 1
|
||||||
|
self.junior = Junior.objects.create(auth=self.user_3, country_code=91, phone='8765887643',
|
||||||
|
country_name='India', gender=2, is_verified=True,
|
||||||
|
guardian_code=[self.guardian_code_1])
|
||||||
|
|
||||||
|
# user 4
|
||||||
|
self.user_email_4 = 'user4@yopmail.com'
|
||||||
|
self.user_4 = User.objects.create_user(username=self.user_email_4, email=self.user_email_4)
|
||||||
|
self.user_4.set_password('user4@1234')
|
||||||
|
self.user_4.save()
|
||||||
|
|
||||||
|
# junior 2
|
||||||
|
self.junior_2 = Junior.objects.create(auth=self.user_4, country_code=92, phone='8768763443',
|
||||||
|
country_name='India', gender=1, is_verified=True,
|
||||||
|
guardian_code=[self.guardian_code_2])
|
||||||
|
|
||||||
|
|
||||||
|
class AnalyticsSetUp(UserManagementSetUp):
|
||||||
|
"""
|
||||||
|
test analytics
|
||||||
|
"""
|
||||||
|
def setUp(self) -> None:
|
||||||
|
"""
|
||||||
|
test data set up
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
super(AnalyticsSetUp, self).setUp()
|
||||||
|
|
||||||
|
# pending tasks
|
||||||
|
self.pending_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='Pending Task 1', task_status=1,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
self.pending_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='Pending Task 2', task_status=1,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
|
||||||
|
# in progress tasks
|
||||||
|
self.in_progress_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='In progress Task 1', task_status=2,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
self.in_progress_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='In progress Task 2', task_status=2,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
|
||||||
|
# rejected tasks
|
||||||
|
self.rejected_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='Rejected Task 1', task_status=3,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
self.rejected_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='Rejected Task 2', task_status=3,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
|
||||||
|
# requested task
|
||||||
|
self.requested_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='Requested Task 1', task_status=4,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
self.requested_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='Requested Task 2', task_status=4,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
|
||||||
|
# completed task
|
||||||
|
self.completed_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='Completed Task 1', task_status=5,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
self.completed_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='Completed Task 2', task_status=5,
|
||||||
|
due_date='2024-09-12')
|
||||||
|
|
||||||
|
# expired task
|
||||||
|
self.expired_task_1 = JuniorTask.objects.create(guardian=self.guardian, junior=self.junior,
|
||||||
|
task_name='Expired Task 1', task_status=6,
|
||||||
|
due_date='2024-09-11')
|
||||||
|
self.expired_task_2 = JuniorTask.objects.create(guardian=self.guardian_2, junior=self.junior_2,
|
||||||
|
task_name='Expired Task 2', task_status=6,
|
||||||
|
due_date='2024-09-11')
|
||||||
|
|
||||||
|
# junior point table data
|
||||||
|
JuniorPoints.objects.create(junior=self.junior_2, total_points=50)
|
||||||
|
JuniorPoints.objects.create(junior=self.junior, total_points=40)
|
||||||
|
|
||||||
|
# export excel url
|
||||||
|
self.export_excel_url = export_excel_url
|
||||||
|
255
web_admin/tests/test_user_management.py
Normal file
255
web_admin/tests/test_user_management.py
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
"""
|
||||||
|
web admin test user management file
|
||||||
|
"""
|
||||||
|
# django imports
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from rest_framework import status
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from base.constants import GUARDIAN, JUNIOR
|
||||||
|
from web_admin.tests.test_set_up import UserManagementSetUp
|
||||||
|
|
||||||
|
# user model
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class UserManagementViewSetTestCase(UserManagementSetUp):
|
||||||
|
"""
|
||||||
|
test cases for user management
|
||||||
|
"""
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super(UserManagementViewSetTestCase, self).setUp()
|
||||||
|
|
||||||
|
self.update_data = {
|
||||||
|
'email': 'user5@yopmail.com',
|
||||||
|
'country_code': 93,
|
||||||
|
'phone': '8765454235'
|
||||||
|
}
|
||||||
|
self.user_management_endpoint = "/api/v1/user-management"
|
||||||
|
|
||||||
|
def test_user_management_list_all_users(self):
|
||||||
|
"""
|
||||||
|
test user management list all users
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/"
|
||||||
|
response = self.client.get(url, format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
# Assuming four user exists in the database
|
||||||
|
self.assertEqual(len(response.data['data']), 4)
|
||||||
|
|
||||||
|
def test_user_management_list_guardians(self):
|
||||||
|
"""
|
||||||
|
test user management list guardians
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/?user_type={GUARDIAN}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
# Assuming two guardians exists in the database
|
||||||
|
self.assertEqual(len(response.data['data']), 2)
|
||||||
|
|
||||||
|
def test_user_management_list_juniors(self):
|
||||||
|
"""
|
||||||
|
test user management list juniors
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/?user_type={JUNIOR}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
# Assuming two juniors exists in the database
|
||||||
|
self.assertEqual(len(response.data['data']), 2)
|
||||||
|
|
||||||
|
def test_user_management_list_with_unauthorised_user(self):
|
||||||
|
"""
|
||||||
|
test user management list with unauthorised user
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# user unauthorised access
|
||||||
|
self.client.force_authenticate(user=self.user)
|
||||||
|
url = f"{self.user_management_endpoint}/"
|
||||||
|
response = self.client.get(url, format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
def test_user_management_retrieve_guardian(self):
|
||||||
|
"""
|
||||||
|
test user management retrieve guardian
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/?user_type={GUARDIAN}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(len(response.data['data']), 1)
|
||||||
|
|
||||||
|
def test_user_management_retrieve_junior(self):
|
||||||
|
"""
|
||||||
|
test user management retrieve junior
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/?user_type={JUNIOR}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(len(response.data['data']), 1)
|
||||||
|
|
||||||
|
def test_user_management_retrieve_without_user_type(self):
|
||||||
|
"""
|
||||||
|
test user management retrieve without user type
|
||||||
|
user status is mandatory
|
||||||
|
API will throw error
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_update_guardian(self):
|
||||||
|
"""
|
||||||
|
test user management update guardian
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/?user_type={GUARDIAN}"
|
||||||
|
response = self.client.patch(url, self.update_data, format='json',)
|
||||||
|
self.user.refresh_from_db()
|
||||||
|
self.guardian.refresh_from_db()
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(self.user.email, self.update_data['email'])
|
||||||
|
self.assertEqual(self.guardian.country_code, self.update_data['country_code'])
|
||||||
|
self.assertEqual(self.guardian.phone, self.update_data['phone'])
|
||||||
|
|
||||||
|
def test_user_management_update_guardian_with_existing_email(self):
|
||||||
|
"""
|
||||||
|
test user management update guardian with existing email
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/?user_type={GUARDIAN}"
|
||||||
|
data = {
|
||||||
|
'email': self.user_email_2
|
||||||
|
}
|
||||||
|
response = self.client.patch(url, data, format='json',)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_update_guardian_with_existing_phone(self):
|
||||||
|
"""
|
||||||
|
test user management update guardian with existing phone
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/?user_type={GUARDIAN}"
|
||||||
|
data = {
|
||||||
|
'phone': self.guardian_2.phone
|
||||||
|
}
|
||||||
|
response = self.client.patch(url, data, format='json',)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_update_junior(self):
|
||||||
|
"""
|
||||||
|
test user management update junior
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/?user_type={JUNIOR}"
|
||||||
|
response = self.client.patch(url, self.update_data, format='json',)
|
||||||
|
self.user_3.refresh_from_db()
|
||||||
|
self.junior.refresh_from_db()
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(self.user_3.email, self.update_data['email'])
|
||||||
|
self.assertEqual(self.junior.country_code, self.update_data['country_code'])
|
||||||
|
self.assertEqual(self.junior.phone, self.update_data['phone'])
|
||||||
|
|
||||||
|
def test_user_management_update_junior_with_existing_email(self):
|
||||||
|
"""
|
||||||
|
test user management update guardian with existing phone
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/?user_type={JUNIOR}"
|
||||||
|
data = {
|
||||||
|
'email': self.user_email_4
|
||||||
|
}
|
||||||
|
response = self.client.patch(url, data, format='json',)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_update_junior_with_existing_phone(self):
|
||||||
|
"""
|
||||||
|
test user management update junior with existing phone
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/?user_type={JUNIOR}"
|
||||||
|
data = {
|
||||||
|
'phone': self.junior_2.phone
|
||||||
|
}
|
||||||
|
response = self.client.patch(url, data, format='json',)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_update_without_user_type(self):
|
||||||
|
"""
|
||||||
|
test user management update without user type
|
||||||
|
user status is mandatory
|
||||||
|
API will throw error
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/"
|
||||||
|
response = self.client.patch(url, self.update_data, format='json',)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def test_user_management_change_status_guardian(self):
|
||||||
|
"""
|
||||||
|
test user management change status guardian
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/change-status/?user_type={GUARDIAN}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.guardian.refresh_from_db()
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(self.guardian.is_active, False)
|
||||||
|
|
||||||
|
def test_user_management_change_status_junior(self):
|
||||||
|
"""
|
||||||
|
test user management change status junior
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user_3.id}/change-status/?user_type={JUNIOR}"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.junior.refresh_from_db()
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(self.junior.is_active, False)
|
||||||
|
|
||||||
|
def test_user_management_change_status_without_user_type(self):
|
||||||
|
"""
|
||||||
|
test user management change status without user type
|
||||||
|
user status is mandatory
|
||||||
|
API will throw error
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# admin user authentication
|
||||||
|
self.client.force_authenticate(user=self.admin_user)
|
||||||
|
url = f"{self.user_management_endpoint}/{self.user.id}/"
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
@ -18,7 +18,7 @@ router = routers.SimpleRouter()
|
|||||||
router.register('article', ArticleViewSet, basename='article')
|
router.register('article', ArticleViewSet, basename='article')
|
||||||
router.register('default-card-images', DefaultArticleCardImagesViewSet, basename='default-card-images')
|
router.register('default-card-images', DefaultArticleCardImagesViewSet, basename='default-card-images')
|
||||||
router.register('user-management', UserManagementViewSet, basename='user')
|
router.register('user-management', UserManagementViewSet, basename='user')
|
||||||
router.register('analytics', AnalyticsViewSet, basename='user-analytics')
|
router.register('analytics', AnalyticsViewSet, basename='analytics')
|
||||||
|
|
||||||
router.register('article-list', ArticleListViewSet, basename='article-list')
|
router.register('article-list', ArticleListViewSet, basename='article-list')
|
||||||
router.register('article-card-list', ArticleCardListViewSet, basename='article-card-list')
|
router.register('article-card-list', ArticleCardListViewSet, basename='article-card-list')
|
||||||
|
Reference in New Issue
Block a user