Skip to content

Commit

Permalink
feat: added tests for log update API
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Sep 9, 2023
1 parent 6c567d9 commit ea5ac78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
32 changes: 31 additions & 1 deletion care/facility/tests/test_patient_daily_rounds_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import datetime

from rest_framework import status

from care.facility.models import PatientRegistration
from care.utils.tests.test_base import TestBase


class TestDailyRoundApi(TestBase):
class TestDailyRound(TestBase):
def setUp(self) -> None:
super().setUp()
self.consultation = self.create_consultation()

def get_url(self, external_consultation_id=None):
return f"/api/v1/consultation/{external_consultation_id}/daily_rounds/analyse/"

def test_external_consultation_does_not_exists_returns_404(self):
sample_uuid = "e4a3d84a-d678-4992-9287-114f029046d8"
response = self.client.get(self.get_url(sample_uuid))
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_action_in_log_update(
self,
):
log_update = {
"clone_last": False,
"rounds_type": "NORMAL",
"patient_category": "Comfort",
"action": "DISCHARGE_RECOMMENDED",
"taken_at": datetime.datetime.now().isoformat(),
}
response = self.client.post(
f"/api/v1/consultation/{self.consultation.external_id}/daily_rounds/",
data=log_update,
format="json",
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.data["patient_category"], "Comfort Care")
self.assertEqual(response.data["rounds_type"], "NORMAL")
patient = PatientRegistration.objects.get(id=self.consultation.patient_id)
self.assertEqual(
patient.action, PatientRegistration.ActionEnum.DISCHARGE_RECOMMENDED.value
)
7 changes: 4 additions & 3 deletions care/utils/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ def create_facility(
"created_by": user,
}
data.update(kwargs)
f = Facility(**data)
f.save()
return f
facility = Facility.objects.create(**data)
facility.users.add(user)
User.objects.filter(id=user.id).update(home_facility=facility)
return facility

@classmethod
def create_patient(cls, facility=None, **kwargs):
Expand Down

0 comments on commit ea5ac78

Please sign in to comment.