Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Oct 23, 2023
1 parent cd7de5c commit f9fe441
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUpTestData(cls) -> None:
cls.local_body = cls.create_local_body(cls.district)
cls.super_user = cls.create_super_user("su", cls.district)
cls.facility = cls.create_facility(cls.super_user, cls.district, cls.local_body)
cls.location = cls.create_asset_location(cls.facility)
cls.user = cls.create_user("staff1", cls.district, home_facility=cls.facility)
cls.doctor = cls.create_user(
"doctor", cls.district, home_facility=cls.facility, user_type=15
Expand All @@ -41,6 +42,21 @@ def get_url(self, consultation=None):
return f"/api/v1/consultation/{consultation.external_id}/"
return "/api/v1/consultation/"

def create_route_to_facility_consultation(
self, patient=None, route_to_facility=10, **kwargs
):
patient = patient or self.create_patient(self.district, self.facility)
data = self.get_default_data().copy()
kwargs.update(
{
"patient": patient.external_id,
"facility": self.facility.external_id,
"route_to_facility": route_to_facility,
}
)
data.update(kwargs)
return self.client.post(self.get_url(), data)

def create_admission_consultation(self, patient=None, **kwargs):
patient = patient or self.create_patient(self.district, self.facility)
data = self.get_default_data().copy()
Expand Down Expand Up @@ -258,6 +274,40 @@ def test_referred_to_external_valid_value(self):
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

def test_route_to_facility_referred_from_facility_empty(self):
res = self.create_route_to_facility_consultation(route_to_facility=20)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

def test_route_to_facility_referred_from_facility_external(self):
res = self.create_route_to_facility_consultation(
route_to_facility=20, referred_from_facility_external="Test"
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)

def test_route_to_facility_referred_from_facility(self):
res = self.create_route_to_facility_consultation(
route_to_facility=20, referred_from_facility=self.facility.external_id
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)

def test_route_to_facility_referred_from_facility_and_external_together(self):
res = self.create_route_to_facility_consultation(
route_to_facility=20,
referred_from_facility="123",
referred_from_facility_external="Test",
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

def test_route_to_facility_transfer_within_facility_empty(self):
res = self.create_route_to_facility_consultation(route_to_facility=30)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

def test_route_to_facility_transfer_within_facility(self):
res = self.create_route_to_facility_consultation(
route_to_facility=30, transferred_from_location=self.location.external_id
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)

def test_medico_legal_case(self):
consultation = self.create_admission_consultation(
medico_legal_case=True,
Expand Down

0 comments on commit f9fe441

Please sign in to comment.