From 08f54f28a4d9301bfeca424cd5c48e5ab3417823 Mon Sep 17 00:00:00 2001 From: abutalib-kiwi Date: Tue, 12 Sep 2023 23:08:17 +0530 Subject: [PATCH] added a test case, updated coverage file --- .coverage | Bin 86016 -> 86016 bytes base/pagination.py | 12 - coverage-reports/coverage.xml | 356 +++++++++--------- notifications/tests.py | 12 +- notifications/utils.py | 30 -- web_admin/serializers/analytics_serializer.py | 2 - web_admin/tests/test_analytics.py | 16 + web_admin/tests/test_set_up.py | 80 ++-- 8 files changed, 253 insertions(+), 255 deletions(-) diff --git a/.coverage b/.coverage index cfe9abdb0be3e2dbddd74aecf82bf68af4e342d8..ad3ab6617849e76cfbb418dc5a98f0bc4a21ebcd 100644 GIT binary patch delta 3420 zcmY+Hc~sQb702iP_HAYuL^dZl8W%JwhzqFfE)24RxB|l}0y7K)qH$?(aEVQ#5#Kp^ z<{WLXY5!<)LNv5$+NLIHPSfVNYiy1hx2TOKK@CZc*`V+K#Mtr&eBSrnd*6Ha-TQvJ zsaxFCEgtx$z!=tUu~;0%>{m$KTZOOKAe3}hdHLq`UHKX9;R!$Mf*V2Ob%)xfmZ|gA zMCFchLD{8jRu(F0%4GS^a;F@S>*QiNMV>6XqzBR$(n;yJ(k`i8S}skJq7HW570AeK zC;3EgB)Pw>cz$S55;%2?W!vsqY5ZWqPaWGj1|cLUGSOw(dcFVTqz60v4|akY6qpoh z*-~B1+k!k}r)Be7>bM7q>F-V^Tc3SLS33ky!#b*`Eq>6OzkLEkN3LN)!kX*HJUv=j2{V3W0#O*>ond^Gs|$&LY84WN6#-T#WLv@i^9arcAbNAmBv z#jDLY-TZXpfL-yS=yUhm6fcq&4V#dfkQ$L1ks6R1m>t>lTv&&;k`2RG?m01dlvnE* zht;|J-;tGCw5oOYrzkZ@HRxH5RE<=HRE1QDRLMy9FpBiBtqfiPxq=NsD%|}_InI}( zWf@W#(h8&%7<)NpCv-Uz)n$yrmYHiWMR6%wE9qr6gzVku59LRy4W zf>eTsFGeaxtq7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FfK@a+2KMsx^>&$<+i1D5j;$)kRfP3XzO5E_XcH{0hQ9j>+j!*Hz+pF<~uQeryGE)`>Y$`Up&sTb7T8)GW6w8^vOF zk2LIAeEm`kqYV27?_Gkad-<*kyvSXA=VC0OeY@SXWFl)1tIC;!Lh4hYh;A2P3=6Rg zLmahXziU!Y2EbE-RH3$VQU2`kQ%A - + @@ -1292,7 +1292,7 @@ - + @@ -1358,7 +1358,7 @@ - + @@ -1371,11 +1371,9 @@ - - - + @@ -1399,25 +1397,25 @@ - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + @@ -3858,7 +3856,7 @@ - + @@ -3963,39 +3961,41 @@ - + - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + + - - - + + + - - + + - - + + + + @@ -4009,7 +4009,7 @@ - + @@ -4034,75 +4034,63 @@ - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + - + @@ -4135,10 +4123,10 @@ - - - - + + + + @@ -4168,7 +4156,7 @@ - + @@ -4287,7 +4275,7 @@ - + @@ -4315,8 +4303,8 @@ - - + + @@ -4371,13 +4359,13 @@ - + - + @@ -4439,15 +4427,14 @@ - - - - + + + + - - - - + + + @@ -4920,24 +4907,31 @@ - - + - - + - + + + - - + + - - - + + + + + + + + + + @@ -5136,75 +5130,75 @@ - - - - - - - + + + + - - - - - - - - - + + + + + + - + + + + + - - - - - - - - - + + + + + + - - - - + + - - - - + + + - - + + + - + + - - - - - + + + + + - - - + + + - - + - + + + + + + + + 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)