Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Jul 28, 2023
1 parent 234cf36 commit bc7e71a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime
from enum import Enum

from django.utils.timezone import make_aware
from rest_framework import status
from rest_framework.test import APIRequestFactory, APITestCase
from rest_framework_simplejwt.tokens import RefreshToken
Expand Down Expand Up @@ -186,3 +188,55 @@ def test_patient_notes(self):
created_by_object_content.keys(),
[item.value for item in ExpectedCreatedByObjectKeys],
)


class PatientFilterTestCase(TestBase, TestClassMixin, APITestCase):
def setUp(self):
self.factory = APIRequestFactory()
state = self.create_state()
district = self.create_district(state=state)

self.user = self.create_super_user(district=district, username="test user")
facility = self.create_facility(district=district, user=self.user)
self.user.home_facility = facility
self.user.save()

self.patient = self.create_patient(district=district.id, created_by=self.user)
self.consultation = self.create_consultation(
op_no="OP1234",
ip_no="IP5678",
patient=self.patient,
facility=facility,
created_by=self.user,
suggestion="A",
admission_date=make_aware(datetime(2020, 4, 1, 15, 30, 00)),
)
self.patient.last_consultation = self.consultation
self.patient.save()
refresh_token = RefreshToken.for_user(self.user)
self.client.credentials(
HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}"
)

def test_filter_by_op_no(self):
response = self.client.get("/api/v1/patient/?op_no=OP1234")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)
self.assertEqual(
response.data["results"][0]["id"], str(self.patient.external_id)
)

def test_filter_by_ip_OR_op_no(self):
response = self.client.get("/api/v1/patient/?ip_or_op_no=IP5678")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)
self.assertEqual(
response.data["results"][0]["id"], str(self.patient.external_id)
)

response = self.client.get("/api/v1/patient/?ip_or_op_no=OP1234")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)
self.assertEqual(
response.data["results"][0]["id"], str(self.patient.external_id)
)

0 comments on commit bc7e71a

Please sign in to comment.