Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for various endpoints in the external_result module #2034

Merged
merged 10 commits into from
Apr 12, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import status
from rest_framework.test import APITestCase

from care.facility.models import PatientExternalTest
from care.utils.tests.test_utils import TestUtils


Expand All @@ -12,6 +13,69 @@ def setUpTestData(cls) -> None:
cls.local_body = cls.create_local_body(cls.district)
cls.ward = cls.create_ward(cls.local_body)
cls.user = cls.create_super_user("su", cls.district)
cls.external_result = PatientExternalTest.objects.create(
district=cls.district,
srf_id="00/EKM/0000",
name="Test Upload0",
age=24,
age_in="years",
gender="m",
mobile_number=8888888888,
address="Upload test address",
ward=cls.ward,
local_body=cls.local_body,
source="Secondary contact aparna",
sample_collection_date="2020-10-14",
result_date="2020-10-14",
test_type="Antigen",
lab_name="Karothukuzhi Laboratory",
sample_type="Ag-SD_Biosensor_Standard_Q_COVID-19_Ag_detection_kit",
patient_status="Asymptomatic",
is_repeat=True,
patient_category="Cat 17: All individuals who wish to get themselves tested",
result="Negative",
)

def test_list_external_result(self):
response = self.client.get("/api/v1/external_result/")
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_retrieve_external_result(self):
response = self.client.get(
f"/api/v1/external_result/{self.external_result.id}/"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
sainak marked this conversation as resolved.
Show resolved Hide resolved

def test_update_patient_external_result(self):
sample_data = {
"address": "Upload test address Updated",
}
response = self.client.put(
f"/api/v1/external_result/{self.external_result.id}/", sample_data
)
self.external_result.refresh_from_db()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.external_result.address, sample_data["address"])

def test_update_patch_patient_external_result(self):
sample_data = {
"address": "Upload test address Updated patch",
}
response = self.client.patch(
f"/api/v1/external_result/{self.external_result.id}/", sample_data
)
self.external_result.refresh_from_db()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.external_result.address, sample_data["address"])

def test_delete_patient_external_result(self):
response = self.client.delete(
f"/api/v1/external_result/{self.external_result.id}/"
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertFalse(
PatientExternalTest.objects.filter(id=self.external_result.id).exists()
)

def test_no_data_upload(self):
response = self.client.post(
Expand Down
Loading