diff --git a/.coverage b/.coverage index c5c9742..ad3ab66 100644 Binary files a/.coverage and b/.coverage differ diff --git a/base/pagination.py b/base/pagination.py index e060447..90b5c95 100644 --- a/base/pagination.py +++ b/base/pagination.py @@ -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, - } diff --git a/coverage-reports/coverage.xml b/coverage-reports/coverage.xml index d63768a..f16234c 100644 --- a/coverage-reports/coverage.xml +++ b/coverage-reports/coverage.xml @@ -1,5 +1,5 @@ - + @@ -29,7 +29,7 @@ - + @@ -265,7 +265,7 @@ - + @@ -384,26 +384,26 @@ - - - + + + - - - + + + - - + + - + - + - + @@ -569,7 +569,7 @@ - + @@ -713,7 +713,7 @@ - + @@ -721,16 +721,14 @@ - - - - + + + + + - - - @@ -1294,7 +1292,7 @@ - + @@ -1360,7 +1358,7 @@ - + @@ -1372,12 +1370,10 @@ - - - + - + @@ -1394,37 +1390,37 @@ - - - - - + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - + @@ -1909,7 +1905,7 @@ - + @@ -1937,9 +1933,9 @@ - - - + + + @@ -3860,7 +3856,7 @@ - + @@ -3928,7 +3924,7 @@ - + @@ -3941,9 +3937,9 @@ - - - + + + @@ -3951,7 +3947,7 @@ - + @@ -3962,7 +3958,44 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3976,7 +4009,7 @@ - + @@ -3993,83 +4026,71 @@ - - + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + - + @@ -4089,27 +4110,27 @@ - - - - - + + + + + - - - - + + + + - - - - + + + + - - + + @@ -4135,7 +4156,7 @@ - + @@ -4219,7 +4240,7 @@ - + @@ -4227,7 +4248,7 @@ - + @@ -4254,7 +4275,7 @@ - + @@ -4281,12 +4302,12 @@ - - - - - - + + + + + + @@ -4338,13 +4359,13 @@ - + - + @@ -4362,13 +4383,13 @@ - + - + - + @@ -4379,10 +4400,10 @@ - + - + @@ -4394,27 +4415,26 @@ - + - - + + - - - - - - - - - - - - - + + + + + + + + + + + + @@ -4701,7 +4721,7 @@ - + @@ -4723,34 +4743,34 @@ - + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + @@ -4762,33 +4782,33 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + - + - + - + - + @@ -4799,33 +4819,33 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + - + - + - + - + @@ -4835,20 +4855,20 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + @@ -4860,6 +4880,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5050,48 +5124,215 @@ - + + + - + + - - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -5122,72 +5363,72 @@ - - + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + @@ -5354,7 +5595,7 @@ - + @@ -5381,54 +5622,54 @@ - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - + + - - - - - - - - + + + + + + + + - - + + diff --git a/notifications/tests.py b/notifications/tests.py index 925d5a1..9cec499 100644 --- a/notifications/tests.py +++ b/notifications/tests.py @@ -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): """ diff --git a/notifications/utils.py b/notifications/utils.py index 83e3e95..a118cd7 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -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) diff --git a/web_admin/serializers/analytics_serializer.py b/web_admin/serializers/analytics_serializer.py index 7871615..cc81f46 100644 --- a/web_admin/serializers/analytics_serializer.py +++ b/web_admin/serializers/analytics_serializer.py @@ -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): diff --git a/web_admin/tests/test_analytics.py b/web_admin/tests/test_analytics.py index 81ff9b0..02f401e 100644 --- a/web_admin/tests/test_analytics.py +++ b/web_admin/tests/test_analytics.py @@ -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 diff --git a/web_admin/tests/test_set_up.py b/web_admin/tests/test_set_up.py index df522cd..f8e2e23 100644 --- a/web_admin/tests/test_set_up.py +++ b/web_admin/tests/test_set_up.py @@ -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)