Skip to content

Commit

Permalink
improved coverage for condition viewsets
Browse files Browse the repository at this point in the history
  • Loading branch information
DraKen0009 committed Jan 20, 2025
1 parent 8d33a6f commit 9c68f3c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
52 changes: 52 additions & 0 deletions care/emr/tests/test_diagnosis_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from secrets import choice
from unittest.mock import patch

Expand Down Expand Up @@ -344,6 +345,57 @@ def test_create_diagnosis_with_permissions_and_no_association_with_facility(self
response = self.client.post(self.base_url, diagnosis_data_dict, format="json")
self.assertEqual(response.status_code, 403)

def test_create_diagnosis_with_permissions_with_mismatched_patient_id(self):
"""
Users with `can_write_encounter` on a encounter with different patient => (HTTP 400).
"""
permissions = [EncounterPermissions.can_write_encounter.name]
role = self.create_role_with_permissions(permissions)
self.attach_role_facility_organization_user(self.organization, self.user, role)

encounter = self.create_encounter(
patient=self.create_patient(),
facility=self.facility,
organization=self.organization,
status=None,
)
diagnosis_data_dict = self.generate_data_for_diagnosis(encounter)

response = self.client.post(self.base_url, diagnosis_data_dict, format="json")
response_data = response.json()
self.assertEqual(response.status_code, 400)
self.assertIn("errors", response_data)
error = response_data["errors"][0]
self.assertEqual(error["type"], "validation_error")
self.assertIn(
"Patient external ID mismatch with encounter's patient", error["msg"]
)

def test_create_diagnosis_with_permissions_with_invalid_encounter_id(self):
"""
Users with `can_write_encounter` on a incomplete encounter => (HTTP 400).
"""
permissions = [EncounterPermissions.can_write_encounter.name]
role = self.create_role_with_permissions(permissions)
self.attach_role_facility_organization_user(self.organization, self.user, role)

encounter = self.create_encounter(
patient=self.create_patient(),
facility=self.facility,
organization=self.organization,
status=None,
)
diagnosis_data_dict = self.generate_data_for_diagnosis(encounter)
diagnosis_data_dict["encounter"] = uuid.uuid4()

response = self.client.post(self.base_url, diagnosis_data_dict, format="json")
response_data = response.json()
self.assertEqual(response.status_code, 400)
self.assertIn("errors", response_data)
error = response_data["errors"][0]
self.assertEqual(error["type"], "value_error")
self.assertIn("Encounter not found", error["msg"])

# RETRIEVE TESTS
def test_retrieve_diagnosis_with_permissions(self):
"""
Expand Down
52 changes: 52 additions & 0 deletions care/emr/tests/test_symptom_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from secrets import choice
from unittest.mock import patch

Expand Down Expand Up @@ -344,6 +345,57 @@ def test_create_symptom_with_permissions_and_no_association_with_facility(self):
response = self.client.post(self.base_url, symptom_data_dict, format="json")
self.assertEqual(response.status_code, 403)

def test_create_symptoms_with_permissions_with_mismatched_patient_id(self):
"""
Users with `can_write_encounter` on a encounter with different patient => (HTTP 400).
"""
permissions = [EncounterPermissions.can_write_encounter.name]
role = self.create_role_with_permissions(permissions)
self.attach_role_facility_organization_user(self.organization, self.user, role)

encounter = self.create_encounter(
patient=self.create_patient(),
facility=self.facility,
organization=self.organization,
status=None,
)
symptom_data_dict = self.generate_data_for_symptom(encounter)

response = self.client.post(self.base_url, symptom_data_dict, format="json")
response_data = response.json()
self.assertEqual(response.status_code, 400)
self.assertIn("errors", response_data)
error = response_data["errors"][0]
self.assertEqual(error["type"], "validation_error")
self.assertIn(
"Patient external ID mismatch with encounter's patient", error["msg"]
)

def test_create_symptom_with_permissions_with_invalid_encounter_id(self):
"""
Users with `can_write_encounter` on a incomplete encounter => (HTTP 400).
"""
permissions = [EncounterPermissions.can_write_encounter.name]
role = self.create_role_with_permissions(permissions)
self.attach_role_facility_organization_user(self.organization, self.user, role)

encounter = self.create_encounter(
patient=self.create_patient(),
facility=self.facility,
organization=self.organization,
status=None,
)
symptom_data_dict = self.generate_data_for_symptom(encounter)
symptom_data_dict["encounter"] = uuid.uuid4()

response = self.client.post(self.base_url, symptom_data_dict, format="json")
response_data = response.json()
self.assertEqual(response.status_code, 400)
self.assertIn("errors", response_data)
error = response_data["errors"][0]
self.assertEqual(error["type"], "value_error")
self.assertIn("Encounter not found", error["msg"])

# RETRIEVE TESTS
def test_retrieve_symptom_with_permissions(self):
"""
Expand Down

0 comments on commit 9c68f3c

Please sign in to comment.