diff --git a/care/facility/tests/test_bed_api.py b/care/facility/tests/test_bed_api.py index 545631a8a1..62eb099dd5 100644 --- a/care/facility/tests/test_bed_api.py +++ b/care/facility/tests/test_bed_api.py @@ -53,7 +53,7 @@ def setUp(self): HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" ) - def test_retrieve_bed(self): + def tes_bed_retrieve(self): bedId = self.bed.external_id response = self.client.get(f"/api/v1/bed/{bedId}/") self.assertEqual(response.status_code, status.HTTP_200_OK) diff --git a/care/facility/tests/test_consultation_bed_api.py b/care/facility/tests/test_consultation_bed_api.py new file mode 100644 index 0000000000..2a6c5fa000 --- /dev/null +++ b/care/facility/tests/test_consultation_bed_api.py @@ -0,0 +1,136 @@ +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 ExpectedConsultationBedRetrieveKeys(Enum): + ID = "id" + BED_OBJECT = "bed_object" + CREATED_DATE = "created_date" + MODIFIED_DATE = "modified_date" + START_DATE = "start_date" + END_DATE = "end_date" + META = "meta" + + +class ExpectedBedKeys(Enum): + ID = "id" + BED_TYPE = "bed_type" + IS_OCCUPIED = "is_occupied" + LOCATION_OBJECT = "location_object" + 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 ExpectedConsultationBedListKeys(Enum): + ID = "id" + BED_OBJECT = "bed_object" + START_DATE = "start_date" + END_DATE = "end_date" + + +class ExpectedBareMinimumBedKeys(Enum): + ID = "id" + NAME = "name" + LOCATION_OBJECT = "location_object" + + +class ExpectedBareMinimumLocationObjectKeys(Enum): + ID = "id" + NAME = "name" + + +class ConsultationBedTestCase(TestBase, TestClassMixin, APITestCase): + def setUp(self): + self.factory = APIRequestFactory() + self.consultation_bed = self.create_consultation_bed() + + refresh_token = RefreshToken.for_user(self.user) + self.client.credentials( + HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" + ) + + def test_consultation_bed_retrieve(self): + bedAssignmentId = self.consultation_bed.external_id + response = self.client.get(f"/api/v1/consultationbed/{bedAssignmentId}/") + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + + self.assertCountEqual( + data.keys(), [item.value for item in ExpectedConsultationBedRetrieveKeys] + ) + + bed_object_content = data["bed_object"] + + if bed_object_content is not None: + self.assertCountEqual( + bed_object_content.keys(), [item.value for item in ExpectedBedKeys] + ) + + location_object_content = bed_object_content["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_consultation_bed_list(self): + response = self.client.get("/api/v1/consultationbed/") + self.assertEqual(response.status_code, status.HTTP_200_OK) + data = response.json() + + results = data["results"] + self.assertIsInstance(results, list) + + for consultation_bed in results: + self.assertCountEqual( + consultation_bed.keys(), + [item.value for item in ExpectedConsultationBedListKeys], + ) + + bed_object_content = consultation_bed["bed_object"] + + if bed_object_content is not None: + self.assertCountEqual( + bed_object_content.keys(), + [item.value for item in ExpectedBareMinimumBedKeys], + ) + + location_object_content = bed_object_content["location_object"] + + if location_object_content is not None: + self.assertCountEqual( + location_object_content.keys(), + [item.value for item in ExpectedBareMinimumLocationObjectKeys], + ) diff --git a/care/utils/tests/test_base.py b/care/utils/tests/test_base.py index d425ee9b0d..7f1370601d 100644 --- a/care/utils/tests/test_base.py +++ b/care/utils/tests/test_base.py @@ -16,6 +16,7 @@ SYMPTOM_CHOICES, AssetLocation, Bed, + ConsultationBed, Disease, DiseaseStatusEnum, Facility, @@ -471,3 +472,12 @@ def create_bed(self, facility=None, room_type=1, room_number="1", **kwargs): } data.update(kwargs) return Bed.objects.create(**data) + + def create_consultation_bed(self, **kwargs): + data = { + "consultation": self.create_consultation(), + "bed": self.create_bed(), + "start_date": make_aware(datetime.datetime(2020, 4, 7, 15, 30)), + } + data.update(kwargs) + return ConsultationBed.objects.create(**data)