generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:ita-social-projects/Forum into #…
…1056-IncorrectHeaderElementsOnAdminPage
- Loading branch information
Showing
44 changed files
with
1,168 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
BackEnd/administration/tests/test_monthly_profile_statistics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from rest_framework.test import APITestCase | ||
from rest_framework import status | ||
from administration.factories import AdminUserFactory, AdminProfileFactory | ||
from utils.unittest_helper import utc_datetime | ||
|
||
|
||
class TestMonthlyProfileStatisticsStaff(APITestCase): | ||
def setUp(self): | ||
self.user = AdminUserFactory() | ||
self.client.force_authenticate(self.user) | ||
self.test_startup_user = AdminUserFactory(is_staff=False) | ||
self.test_investor_user = AdminUserFactory(is_staff=False) | ||
self.test_blocked_company_user = AdminUserFactory(is_staff=False) | ||
self.startup_company = AdminProfileFactory( | ||
person_id=self.test_startup_user.id, is_registered=False | ||
) | ||
self.startup_company.created_at = utc_datetime(2023, 12, 7) | ||
self.startup_company.save() | ||
self.investor_company = AdminProfileFactory( | ||
person_id=self.test_investor_user.id, is_startup=False | ||
) | ||
self.investor_company.created_at = utc_datetime(2024, 5, 10) | ||
self.investor_company.save() | ||
self.blocked_company = AdminProfileFactory( | ||
person_id=self.test_blocked_company_user.id, status="blocked" | ||
) | ||
self.blocked_company.created_at = utc_datetime(2024, 12, 12) | ||
self.blocked_company.save() | ||
|
||
def test_get_monthly_profile_statistics(self): | ||
response = self.client.get("/api/admin/profiles/statistics/monthly/") | ||
data = [ | ||
{ | ||
"month": 12, | ||
"year": 2023, | ||
"investors_count": 0, | ||
"startups_count": 1, | ||
"startup_investor_count": 0, | ||
}, | ||
{ | ||
"month": 5, | ||
"year": 2024, | ||
"investors_count": 1, | ||
"startups_count": 0, | ||
"startup_investor_count": 0, | ||
}, | ||
{ | ||
"month": 12, | ||
"year": 2024, | ||
"investors_count": 0, | ||
"startups_count": 0, | ||
"startup_investor_count": 1, | ||
}, | ||
] | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, data) | ||
|
||
def test_get_monthly_statistics_incorrect_year(self): | ||
response = self.client.get( | ||
"/api/admin/profiles/statistics/monthly/?year=2002" | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, []) | ||
|
||
def test_get_monthly_statistics_correct_year(self): | ||
response = self.client.get( | ||
"/api/admin/profiles/statistics/monthly/?year=2024" | ||
) | ||
data = [ | ||
{ | ||
"month": 5, | ||
"year": 2024, | ||
"investors_count": 1, | ||
"startups_count": 0, | ||
"startup_investor_count": 0, | ||
}, | ||
{ | ||
"month": 12, | ||
"year": 2024, | ||
"investors_count": 0, | ||
"startups_count": 0, | ||
"startup_investor_count": 1, | ||
}, | ||
] | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, data) | ||
|
||
|
||
class TestMonthlyProfileStatisticsNotStaff(APITestCase): | ||
def setUp(self): | ||
self.user = AdminUserFactory(is_staff=False) | ||
self.client.force_authenticate(self.user) | ||
|
||
def test_get_profile_statistics(self): | ||
response = self.client.get("/api/admin/profiles/statistics/monthly/") | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
|
||
class TestMonthlyProfileStatisticsUnauthorized(APITestCase): | ||
def test_get_profile_statistics(self): | ||
response = self.client.get("/api/admin/profiles/statistics/monthly/") | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.