-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
fixtures/select_organization/objects_by_organization.json
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,147 @@ | ||
[ | ||
{ | ||
"model": "auth.user", | ||
"pk": 1, | ||
"fields": { | ||
"password": "user1pass", | ||
"last_login": "2023-01-10T22:49:30.603Z", | ||
"is_superuser": false, | ||
"username": "user1", | ||
"first_name": "User", | ||
"last_name": "1", | ||
"email": "[email protected]", | ||
"is_staff": false, | ||
"is_active": true, | ||
"date_joined": "2018-07-09T19:45:29Z", | ||
"groups": [], | ||
"user_permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth.user", | ||
"pk": 2, | ||
"fields": { | ||
"password": "user2pass", | ||
"last_login": "2023-01-10T22:49:30.603Z", | ||
"is_superuser": false, | ||
"username": "user2", | ||
"first_name": "User", | ||
"last_name": "2", | ||
"email": "[email protected]", | ||
"is_staff": false, | ||
"is_active": true, | ||
"date_joined": "2018-07-09T19:45:29Z", | ||
"groups": [], | ||
"user_permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "laboratory.organizationstructure", | ||
"pk": 1, | ||
"fields": { | ||
"parent": null, | ||
"name": "Organization 1", | ||
"position": 0, | ||
"level": 0, | ||
"rol": [ | ||
], | ||
"users": [1] | ||
} | ||
}, | ||
{ | ||
"model": "laboratory.organizationstructure", | ||
"pk": 2, | ||
"fields": { | ||
"parent": null, | ||
"name": "Organization 2", | ||
"position": 0, | ||
"level": 0, | ||
"rol": [ | ||
], | ||
"users": [2] | ||
} | ||
}, | ||
{ | ||
"model": "auth_and_perms.profile", | ||
"pk": 1, | ||
"fields": { | ||
"user": 1, | ||
"phone_number": "8888-8888", | ||
"id_card": "0-0000-0000", | ||
"job_position": "Administrator", | ||
"laboratories": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth_and_perms.profile", | ||
"pk": 2, | ||
"fields": { | ||
"user": 2, | ||
"phone_number": "7777-7777", | ||
"id_card": "0-0000-0000", | ||
"job_position": "Administrator", | ||
"laboratories": [ | ||
] | ||
} | ||
}, | ||
{ | ||
"model": "laboratory.object", | ||
"pk": 1, | ||
"fields": { | ||
"organization": 1, | ||
"creation_date": "2023-01-10T22:48:14.125Z", | ||
"last_update": "2023-01-10T22:48:14.166Z", | ||
"created_by": 1, | ||
"code": "TA1000", | ||
"name": "Tanque 1000 mL", | ||
"synonym": null, | ||
"type": "0", | ||
"is_public": true, | ||
"description": "", | ||
"model": "", | ||
"serie": "", | ||
"plaque": "", | ||
"features": [] | ||
} | ||
}, | ||
{ | ||
"model": "laboratory.object", | ||
"pk": 2, | ||
"fields": { | ||
"organization": 1, | ||
"creation_date": "2023-01-10T22:48:14.125Z", | ||
"last_update": "2023-01-10T22:48:14.166Z", | ||
"created_by": 1, | ||
"code": "TA1000", | ||
"name": "Tanque 1000 mL", | ||
"synonym": null, | ||
"type": "0", | ||
"is_public": true, | ||
"description": "", | ||
"model": "", | ||
"serie": "", | ||
"plaque": "", | ||
"features": [] | ||
} | ||
}, | ||
{ | ||
"model": "laboratory.object", | ||
"pk": 3, | ||
"fields": { | ||
"organization": 1, | ||
"creation_date": "2023-01-10T22:48:14.125Z", | ||
"last_update": "2023-01-10T22:48:14.166Z", | ||
"created_by": 1, | ||
"code": "B1000", | ||
"name": "Botella 1000 mL", | ||
"synonym": null, | ||
"type": "1", | ||
"is_public": true, | ||
"description": "", | ||
"model": "", | ||
"serie": "", | ||
"plaque": "", | ||
"features": [] | ||
} | ||
} | ||
] |
Empty file.
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,129 @@ | ||
from django.test import TestCase, Client | ||
from django.urls import reverse | ||
from django.contrib.auth import get_user_model | ||
|
||
from laboratory.models import OrganizationStructure, Object | ||
|
||
|
||
class TestCaseBase(TestCase): | ||
fixtures = ["select_organization/objects_by_organization.json"] | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
# ORG | ||
self.org1 = OrganizationStructure.objects.filter(name="Organization 1").first() | ||
self.org2 = OrganizationStructure.objects.filter(name="Organization 2").first() | ||
|
||
self.user1 = get_user_model().objects.filter(username="user1").first() | ||
self.user2 = get_user_model().objects.filter(username="user2").first() | ||
|
||
# PROFILE | ||
self.profile1 = self.user1.profile | ||
self.profile2 = self.user2.profile | ||
|
||
self.client1 = Client() | ||
self.client2 = Client() | ||
|
||
self.client1.force_login(self.user1) | ||
self.client2.force_login(self.user2) | ||
|
||
# DEFAULT DATA | ||
self.org = self.org1 | ||
self.user = self.user1 | ||
self.client = self.client1 | ||
self.object = Object.objects.get(pk=1) | ||
self.data = { | ||
"organization": self.org.pk | ||
} | ||
|
||
|
||
def check_user_in_organization(self, user=None, client=None, user_is_in_org=False, status_code=400): | ||
if user and client: | ||
self.user = user | ||
self.client = client | ||
response = self.client.get(self.url, data=self.data) | ||
self.assertEqual(response.status_code, status_code) | ||
if self.org: | ||
user_in_org = self.org.users.filter(pk=self.user.pk).exists() | ||
self.assertEqual(user_in_org, user_is_in_org) | ||
|
||
|
||
class ObjectsByOrganizationViewTest(TestCaseBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.url = reverse("objbyorg-list") | ||
|
||
def check_objects_result(self): | ||
pass | ||
|
||
def check_tests(self, user=None, client=None, user_in_org=False, status_code=400): | ||
self.check_user_in_organization(user, client, user_in_org, status_code) | ||
self.check_objects_result() | ||
|
||
|
||
class OrgDoesNotExists(TestCaseBase): | ||
def setUp(self): | ||
super().setUp() | ||
self.org = None | ||
self.data.update({ | ||
"organization": 9867 | ||
}) | ||
|
||
|
||
class WithoutOrg(TestCaseBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.org = None | ||
del self.data["organization"] | ||
|
||
class OrganizationsByUserViewTest(TestCaseBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.url = reverse("orgtree-list") | ||
|
||
def check_organizations_result(self): | ||
pass | ||
|
||
def check_tests(self, user=None, client=None, user_in_org=False, status_code=400): | ||
#self.check_user_in_organization(user, client, user_in_org, status_code) | ||
self.check_organizations_result() | ||
|
||
|
||
class ShelfObjectsByObjectViewTest(TestCaseBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.data.update({ | ||
"object": self.object.pk | ||
}) | ||
self.url = reverse("auth_and_perms:api-searchshelfobjectorg-list") | ||
|
||
def check_shelfobject_result(self): | ||
pass | ||
|
||
def check_tests(self, user=None, client=None, user_in_org=False, status_code=400): | ||
self.check_user_in_organization(user, client, user_in_org, status_code) | ||
self.check_shelfobject_result() | ||
|
||
|
||
class ObjectDoesNotExists(ShelfObjectsByObjectViewTest): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.object = None | ||
self.data.update({ | ||
"object": 9867 | ||
}) | ||
|
||
class WithoutObject(ShelfObjectsByObjectViewTest): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.object = None | ||
del self.data["object"] | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
src/auth_and_perms/tests/select_organization/test_objects_by_organization.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,36 @@ | ||
from auth_and_perms.tests.select_organization.base import ObjectsByOrganizationViewTest, \ | ||
OrgDoesNotExists, WithoutOrg | ||
|
||
|
||
class ObjectsByOrganizationViewTest1(ObjectsByOrganizationViewTest): | ||
""" | ||
Organization exists | ||
Case 1: User is an organization member | ||
Case 2: User is not an organization member | ||
""" | ||
|
||
def test_get_objects_by_org_case1(self): | ||
self.check_tests(user_in_org=True, status_code=200) | ||
|
||
def test_get_objects_by_org_case2(self): | ||
self.check_tests(self.user2, self.client2, status_code=403) | ||
|
||
|
||
class ObjectsByOrganizationViewTest2(ObjectsByOrganizationViewTest, OrgDoesNotExists): | ||
""" | ||
Organization does not exist | ||
Case 1: User is trying to get objects by not valid organization pk | ||
""" | ||
|
||
def test_get_objects_by_org_case1(self): | ||
self.check_tests() | ||
|
||
|
||
class ObjectsByOrganizationViewTest3(ObjectsByOrganizationViewTest, WithoutOrg): | ||
""" | ||
Without organization | ||
Case 1: User is trying to get objects without organization pk parameter | ||
""" | ||
|
||
def test_get_objects_by_org_case1(self): | ||
self.check_tests() |
5 changes: 5 additions & 0 deletions
5
src/auth_and_perms/tests/select_organization/test_organizations_by_user.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,5 @@ | ||
from auth_and_perms.tests.select_organization.base import OrganizationsByUserViewTest | ||
|
||
|
||
class OrganizationsByUserViewTest1(OrganizationsByUserViewTest): | ||
pass |
76 changes: 76 additions & 0 deletions
76
src/auth_and_perms/tests/select_organization/test_shelfobjects_by_object_and_organization.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,76 @@ | ||
from auth_and_perms.tests.select_organization.base import ShelfObjectsByObjectViewTest, \ | ||
OrgDoesNotExists, ObjectDoesNotExists, WithoutObject, WithoutOrg | ||
|
||
|
||
class ShelfObjectsByObjectViewTest1(ShelfObjectsByObjectViewTest): | ||
""" | ||
Organization and object exists | ||
Case 1: User is an organization member | ||
Case 2: User is not an organization member | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests(user_in_org=True, status_code=200) | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case2(self): | ||
self.check_tests(self.user2, self.client2, status_code=403) | ||
|
||
|
||
class ShelfObjectsByObjectViewTest2(OrgDoesNotExists, ObjectDoesNotExists): | ||
""" | ||
Organization and object do not exist | ||
Case 1: User is trying to get shelf objects by not valid organization and object pk | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests() | ||
|
||
|
||
class ShelfObjectsByObjectViewTest3(ObjectDoesNotExists): | ||
""" | ||
Object does not exist | ||
Case 1: User is trying to get shelf objects by not valid object pk | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests(user_in_org=True) | ||
|
||
|
||
class ShelfObjectsByObjectViewTest4(ShelfObjectsByObjectViewTest, OrgDoesNotExists): | ||
""" | ||
Organization does not exist | ||
Case 1: User is trying to get shelf objects by not valid organization pk | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests() | ||
|
||
|
||
class ShelfObjectsByObjectViewTest5(WithoutOrg, WithoutObject): | ||
""" | ||
Without organization and object | ||
Case 1: User is trying to get shelf objects without organization and object | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests() | ||
|
||
|
||
class ShelfObjectsByObjectViewTest6(ShelfObjectsByObjectViewTest, WithoutOrg): | ||
""" | ||
Without organization | ||
Case 1: User is trying to get shelf objects without organization | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests() | ||
|
||
|
||
class ShelfObjectsByObjectViewTest7(WithoutObject): | ||
""" | ||
Without object | ||
Case 1: User is trying to get shelf objects without object | ||
""" | ||
|
||
def test_get_shelfobjects_by_objects_and_org_case1(self): | ||
self.check_tests() |