-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for the list and retrieve endpoint
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from enum import Enum | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APIRequestFactory, APITestCase | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
from care.facility.tests.mixins import TestClassMixin | ||
from care.utils.tests.test_base import TestBase | ||
|
||
|
||
class ExpectedBedRetrieveKeys(Enum): | ||
ID = "id" | ||
BED_TYPE = "bed_type" | ||
LOCATION_OBJECT = "location_object" | ||
IS_OCCUPIED = "is_occupied" | ||
CREATED_DATE = "created_date" | ||
MODIFIED_DATE = "modified_date" | ||
NAME = "name" | ||
DESCRIPTION = "description" | ||
META = "meta" | ||
|
||
|
||
class ExpectedLocationObjectKeys(Enum): | ||
ID = "id" | ||
FACILITY = "facility" | ||
CREATED_DATE = "created_date" | ||
MODIFIED_DATE = "modified_date" | ||
NAME = "name" | ||
DESCRIPTION = "description" | ||
LOCATION_TYPE = "location_type" | ||
|
||
|
||
class ExpectedFacilityKeys(Enum): | ||
ID = "id" | ||
NAME = "name" | ||
|
||
|
||
class ExpectedBedListKeys(Enum): | ||
ID = "id" | ||
BED_TYPE = "bed_type" | ||
DESCRIPTION = "description" | ||
NAME = "name" | ||
IS_OCCUPIED = "is_occupied" | ||
|
||
|
||
class BedTestCase(TestBase, TestClassMixin, APITestCase): | ||
def setUp(self): | ||
self.factory = APIRequestFactory() | ||
self.bed = self.create_bed() | ||
|
||
refresh_token = RefreshToken.for_user(self.user) | ||
self.client.credentials( | ||
HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" | ||
) | ||
|
||
def test_retrieve_bed(self): | ||
bedId = self.bed.external_id | ||
response = self.client.get(f"/api/v1/bed/{bedId}/") | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
data = response.json() | ||
|
||
self.assertCountEqual( | ||
data.keys(), [item.value for item in ExpectedBedRetrieveKeys] | ||
) | ||
|
||
location_object_content = data["location_object"] | ||
|
||
if location_object_content is not None: | ||
self.assertCountEqual( | ||
location_object_content.keys(), | ||
[item.value for item in ExpectedLocationObjectKeys], | ||
) | ||
|
||
facility_content = location_object_content["facility"] | ||
|
||
if facility_content is not None: | ||
self.assertCountEqual( | ||
facility_content.keys(), [item.value for item in ExpectedFacilityKeys] | ||
) | ||
|
||
def test_bed_list(self): | ||
response = self.client.get("/api/v1/bed/") | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
data = response.json() | ||
|
||
results = data["results"] | ||
self.assertIsInstance(results, list) | ||
|
||
for bed in results: | ||
self.assertCountEqual( | ||
bed.keys(), [item.value for item in ExpectedBedListKeys] | ||
) |
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