mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 10:26:16 +00:00
Merge branch 'dev' of https://github.com/KiwiTechLLC/ZODBank-Backend into dev
This commit is contained in:
@ -32,15 +32,3 @@ class CustomPageNumberPagination(PageNumberPagination):
|
||||
|
||||
|
||||
]))
|
||||
|
||||
def get_paginated_dict_response(self, data):
|
||||
"""
|
||||
:param data: queryset to be paginated
|
||||
:return: return a simple dict obj
|
||||
"""
|
||||
return {
|
||||
'count': self.page.paginator.count,
|
||||
'data': data,
|
||||
'current_page': self.page.number,
|
||||
'total_pages': self.page.paginator.num_pages,
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@ from fcm_django.models import FCMDevice
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
from account.models import UserNotification
|
||||
# local imports
|
||||
from account.serializers import GuardianSerializer
|
||||
from notifications.models import Notification
|
||||
@ -25,8 +26,11 @@ class NotificationTestCase(AnalyticsSetUp):
|
||||
"""
|
||||
super(NotificationTestCase, self).setUp()
|
||||
|
||||
# notification settings create
|
||||
UserNotification.objects.create(user=self.user)
|
||||
|
||||
# notification create
|
||||
self.notification = Notification.objects.create(notification_to=self.user)
|
||||
self.notification = Notification.objects.create(notification_to=self.user, notification_from=self.user_3)
|
||||
|
||||
# to get guardian/user auth token
|
||||
self.guardian_data = GuardianSerializer(
|
||||
@ -73,11 +77,11 @@ class NotificationTestCase(AnalyticsSetUp):
|
||||
test send test notification
|
||||
:return:
|
||||
"""
|
||||
url = reverse('notifications:notifications-list')
|
||||
url = reverse('notifications:notifications-test')
|
||||
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)
|
||||
# Assuming one notification exists in the database and two created after api run
|
||||
self.assertEqual(Notification.objects.filter(notification_to=self.user).count(), 3)
|
||||
|
||||
def test_mark_as_read(self):
|
||||
"""
|
||||
|
@ -145,33 +145,3 @@ def send_notification_multiple_user(notification_type, from_user_id, from_user_t
|
||||
Notification.objects.bulk_create(notification_list)
|
||||
to_user_list = to_user_list.filter(user_notification__push_notification=True)
|
||||
send_multiple_push(to_user_list, push_data)
|
||||
|
||||
|
||||
@shared_task()
|
||||
def send_notification_to_guardian(notification_type, from_user_id, to_user_id, extra_data):
|
||||
"""
|
||||
:param notification_type:
|
||||
:param from_user_id:
|
||||
:param to_user_id:
|
||||
:param extra_data:
|
||||
:return:
|
||||
"""
|
||||
if from_user_id:
|
||||
from_user = Junior.objects.filter(auth_id=from_user_id).first()
|
||||
extra_data['from_user_image'] = from_user.image
|
||||
send_notification(notification_type, from_user_id, to_user_id, extra_data)
|
||||
|
||||
|
||||
@shared_task()
|
||||
def send_notification_to_junior(notification_type, from_user_id, to_user_id, extra_data):
|
||||
"""
|
||||
:param notification_type:
|
||||
:param from_user_id:
|
||||
:param to_user_id:
|
||||
:param extra_data:
|
||||
:return:
|
||||
"""
|
||||
if from_user_id:
|
||||
from_user = Guardian.objects.filter(user_id=from_user_id).first()
|
||||
extra_data['from_user_image'] = from_user.image
|
||||
send_notification(notification_type, from_user_id, to_user_id, extra_data)
|
||||
|
@ -128,8 +128,6 @@ class UserCSVReportSerializer(serializers.ModelSerializer):
|
||||
return dict(USER_TYPE).get('2').capitalize()
|
||||
elif obj.junior_profile.all().first():
|
||||
return dict(USER_TYPE).get('1').capitalize()
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_is_active(obj):
|
||||
|
@ -49,6 +49,22 @@ class AnalyticsViewSetTestCase(AnalyticsSetUp):
|
||||
# Assuming four users exists in the database
|
||||
self.assertEqual(response.data['data'][0]['signups'], 4)
|
||||
|
||||
def test_new_user_sign_ups_between_given_dates(self):
|
||||
"""
|
||||
test new user sign-ups
|
||||
:return:
|
||||
"""
|
||||
self.client.force_authenticate(self.admin_user)
|
||||
url = reverse('web_admin:analytics-new-signups')
|
||||
query_params = {
|
||||
'start_date': '2023-09-12',
|
||||
'end_date': '2023-09-13'
|
||||
}
|
||||
response = self.client.get(url, query_params)
|
||||
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
|
||||
|
@ -105,6 +105,8 @@ base64_image = ("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBIS
|
||||
"rOORsR8oQkxdazE9A8QostdSBuBFvlKI6PY6ibg0z4VCscJi9WK3WzRiwmRqGHY3vndi5Hnebangse2hrpSHBEAjhE6rXj"
|
||||
"GYdEC/arYms/HtkfAS7huhuDXXJmPEkn5whN4xrZ0NkYdPRpIPdLS0kG5QPdCEskKlYcIWHCEJUO3KFuUIQD3QhCB//Z")
|
||||
|
||||
# export excel path and
|
||||
# export excel url
|
||||
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}"
|
||||
|
||||
@ -119,12 +121,17 @@ class BaseSetUp(APITestCase):
|
||||
user data
|
||||
:return:
|
||||
"""
|
||||
# user and admin email
|
||||
self.user_email = 'user@example.com'
|
||||
self.admin_email = 'admin@example.com'
|
||||
self.client = APIClient()
|
||||
|
||||
# create user
|
||||
self.user = User.objects.create_user(username=self.user_email, email=self.user_email)
|
||||
self.user.set_password('user@1234')
|
||||
self.user.save()
|
||||
|
||||
# create admin
|
||||
self.admin_user = User.objects.create_user(username=self.admin_email, email=self.admin_email,
|
||||
is_staff=True, is_superuser=True)
|
||||
self.admin_user.set_password('admin@1234')
|
||||
@ -133,22 +140,31 @@ class BaseSetUp(APITestCase):
|
||||
|
||||
class ArticleTestSetUp(BaseSetUp):
|
||||
"""
|
||||
test cases data set up for article create, update
|
||||
test cases data set up
|
||||
for article create, update, list, retrieve and
|
||||
remove card, survey and add test card, list test card and
|
||||
default image upload and list
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
set up data for test
|
||||
create user and admin
|
||||
create article, article card and article survey and survey options
|
||||
:return:
|
||||
"""
|
||||
super(ArticleTestSetUp, self).setUp()
|
||||
|
||||
# create article
|
||||
self.article = Article.objects.create(title="Existing Article", description="Existing Description",
|
||||
is_published=True)
|
||||
# create article card
|
||||
self.article_card = ArticleCard.objects.create(article=self.article, title="Existing Card 1",
|
||||
description="Existing Card 1 Description")
|
||||
# create article survey
|
||||
self.article_survey = ArticleSurvey.objects.create(article=self.article, points=5,
|
||||
question="Existing Survey Question 1")
|
||||
# create article survey options
|
||||
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)
|
||||
|
||||
@ -261,11 +277,12 @@ class ArticleTestSetUp(BaseSetUp):
|
||||
class UserManagementSetUp(BaseSetUp):
|
||||
"""
|
||||
test cases for user management
|
||||
users count, new sign-ups,
|
||||
"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
"""
|
||||
data setup
|
||||
create new guardian and junior
|
||||
:return:
|
||||
"""
|
||||
super(UserManagementSetUp, self).setUp()
|
||||
@ -278,8 +295,9 @@ class UserManagementSetUp(BaseSetUp):
|
||||
country_name='India', gender=2, is_verified=True,
|
||||
guardian_code=self.guardian_code_1)
|
||||
|
||||
# user 2
|
||||
# user 2 email
|
||||
self.user_email_2 = 'user2@yopmail.com'
|
||||
# create user 2
|
||||
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()
|
||||
@ -289,19 +307,20 @@ class UserManagementSetUp(BaseSetUp):
|
||||
country_name='India', gender=1, is_verified=True,
|
||||
guardian_code=self.guardian_code_2)
|
||||
|
||||
# user 3
|
||||
# user 3 email
|
||||
self.user_email_3 = 'user3@yopmail.com'
|
||||
# create user 3
|
||||
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])
|
||||
self.junior = Junior.objects.create(auth=self.user_3, country_name='India', gender=2,
|
||||
is_verified=True, guardian_code=[self.guardian_code_1])
|
||||
|
||||
# user 4
|
||||
# user 4 email
|
||||
self.user_email_4 = 'user4@yopmail.com'
|
||||
# create user 4
|
||||
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()
|
||||
@ -315,61 +334,70 @@ class UserManagementSetUp(BaseSetUp):
|
||||
class AnalyticsSetUp(UserManagementSetUp):
|
||||
"""
|
||||
test analytics
|
||||
task assign report, junior leaderboard
|
||||
"""
|
||||
def setUp(self) -> None:
|
||||
"""
|
||||
test data set up
|
||||
create task and assigned to junior
|
||||
create junior points data
|
||||
:return:
|
||||
"""
|
||||
super(AnalyticsSetUp, self).setUp()
|
||||
|
||||
# pending tasks
|
||||
# pending tasks 1
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
# pending tasks 2
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
|
||||
# in progress tasks
|
||||
# in progress tasks 1
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
# in progress tasks 2
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
|
||||
# rejected tasks
|
||||
# rejected tasks 1
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
# rejected tasks 2
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
|
||||
# requested task
|
||||
# requested task 1
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
# requested task 2
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
|
||||
# completed task
|
||||
# completed task 1
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
# completed task 2
|
||||
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')
|
||||
due_date='2023-09-12')
|
||||
|
||||
# expired task
|
||||
# expired task 1
|
||||
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')
|
||||
due_date='2023-09-11')
|
||||
# expired task 2
|
||||
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')
|
||||
due_date='2023-09-11')
|
||||
|
||||
# junior point table data
|
||||
JuniorPoints.objects.create(junior=self.junior_2, total_points=50)
|
||||
|
Reference in New Issue
Block a user