generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/develop' into 1003-admin-backend-management-…
…with-search-and-filter-capabilities # Conflicts: # BackEnd/administration/filters.py # BackEnd/administration/serializers.py # BackEnd/administration/views.py
- Loading branch information
Showing
47 changed files
with
1,335 additions
and
861 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
||
from administration.factories import ( | ||
AdminCategoryFactory, | ||
AdminUserFactory, | ||
) | ||
|
||
from utils.dump_response import dump # noqa | ||
from utils.unittest_helper import AnyInt, AnyStr | ||
|
||
|
||
class TestAdminCategoryAPIUserNotStaff(APITestCase): | ||
def setUp(self): | ||
self.user = AdminUserFactory( | ||
is_staff=False, | ||
is_active=True, | ||
) | ||
self.category = AdminCategoryFactory() | ||
|
||
def test_get_category_users_not_staff(self): | ||
self.client.force_authenticate(self.user) | ||
response = self.client.get(path="/api/admin/categories/") | ||
self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) | ||
|
||
def test_get_category_id_users_not_staff(self): | ||
self.client.force_authenticate(self.user) | ||
response = self.client.get(path="/api/admin/categories/1/") | ||
self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) | ||
|
||
|
||
class TestAdminCategoryAPIUserStaff(APITestCase): | ||
def setUp(self): | ||
self.user = AdminUserFactory( | ||
is_staff=True, | ||
is_active=True, | ||
) | ||
self.categories = AdminCategoryFactory.create_batch(2) | ||
|
||
def test_get_categories_users_staff(self): | ||
self.client.force_authenticate(self.user) | ||
response = self.client.get(path="/api/admin/categories/") | ||
data = [ | ||
{ | ||
"id": AnyInt(), | ||
"name": AnyStr(), | ||
}, | ||
{ | ||
"id": AnyInt(), | ||
"name": AnyStr(), | ||
}, | ||
] | ||
self.assertEqual(data, response.json()["results"]) | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) | ||
|
||
def test_get_categories_id_users_staff(self): | ||
self.client.force_authenticate(self.user) | ||
response = self.client.get(path="/api/admin/categories/3/") | ||
data = {"name": AnyStr()} | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) | ||
self.assertEqual(data, response.json()) | ||
|
||
def test_post_new_categories_users_staff(self): | ||
self.client.force_authenticate(self.user) | ||
data = {"name": "some category"} | ||
response = self.client.post(path="/api/admin/categories/", data=data) | ||
self.assertEqual(status.HTTP_201_CREATED, response.status_code) | ||
self.assertEqual(response.json()["name"], data["name"]) | ||
self.assertIn("id", response.json()) | ||
|
||
def test_post_unique_categories_users_staff(self): | ||
self.existing_name = AdminCategoryFactory.create( | ||
name="existing category" | ||
) | ||
self.client.force_authenticate(self.user) | ||
data = {"name": "existing category"} | ||
message = "Category with this name already exists." | ||
response = self.client.post(path="/api/admin/categories/", data=data) | ||
self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) | ||
self.assertEqual(response.json()["name"][0], message) | ||
|
||
def test_put_categories_id_users_staff(self): | ||
self.category = AdminCategoryFactory.create() | ||
self.client.force_authenticate(self.user) | ||
data = {"name": "category 1212"} | ||
response = self.client.put( | ||
path=f"/api/admin/categories/{self.category.id}/", data=data | ||
) | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) | ||
self.assertEqual(response.json()["name"], data["name"]) | ||
|
||
def test_patch_categories_id_users_staff(self): | ||
self.category = AdminCategoryFactory.create() | ||
self.client.force_authenticate(self.user) | ||
data = {"name": "category 77"} | ||
response = self.client.patch( | ||
path=f"/api/admin/categories/{self.category.id}/", data=data | ||
) | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) | ||
self.assertEqual(response.json()["name"], data["name"]) |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
AdminProfileFactory, | ||
) | ||
|
||
from utils.unittest_helper import AnyInt, AnyStr | ||
from utils.dump_response import dump # noqa | ||
|
||
|
||
|
@@ -52,14 +53,14 @@ def test_get_profiles_structure_json(self): | |
response = self.client.get(path="/api/admin/profiles/") | ||
data = [ | ||
{ | ||
"id": 4, | ||
"id": AnyInt(), | ||
"name": "Test person", | ||
"is_registered": True, | ||
"is_startup": True, | ||
"person": { | ||
"name": "Test person 7", | ||
"surname": "Test person 7 surname", | ||
"email": "[email protected]", | ||
"name": AnyStr(), | ||
"surname": AnyStr(), | ||
"email": AnyStr(), | ||
"is_active": True, | ||
"is_staff": True, | ||
"is_superuser": False, | ||
|
@@ -89,9 +90,9 @@ def test_get_profile_id_authenticated(self): | |
"categories": [], | ||
"activities": [], | ||
"person": { | ||
"name": "Test person 1", | ||
"surname": "Test person 1 surname", | ||
"email": "[email protected]", | ||
"name": AnyStr(), | ||
"surname": AnyStr(), | ||
"email": AnyStr(), | ||
"is_active": True, | ||
"is_staff": True, | ||
"is_superuser": False, | ||
|
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,49 @@ | ||
from rest_framework.test import APITestCase | ||
from rest_framework import status | ||
|
||
from administration.factories import AdminUserFactory, AdminProfileFactory | ||
|
||
|
||
class TestProfileStatisticsStaff(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.investor_company = AdminProfileFactory( | ||
person_id=self.test_investor_user.id, is_startup=False | ||
) | ||
self.blocked_company = AdminProfileFactory( | ||
person_id=self.test_blocked_company_user.id, status="blocked" | ||
) | ||
|
||
def test_get_profile_statistics(self): | ||
response = self.client.get("/api/admin/profiles/statistics/") | ||
data = { | ||
"companies_count": 3, | ||
"investors_count": 2, | ||
"startups_count": 2, | ||
"blocked_companies_count": 1, | ||
} | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, data) | ||
|
||
|
||
class TestProfileStatisticsNotStaff(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/") | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
|
||
class TestProfileStatisticsUnauthorized(APITestCase): | ||
def test_get_profile_statistics(self): | ||
response = self.client.get("/api/admin/profiles/statistics/") | ||
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
Oops, something went wrong.