Skip to content

Commit

Permalink
Fix Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekGawd committed Sep 28, 2023
1 parent ca7a79a commit f138a04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 12 additions & 8 deletions care/facility/tests/test_facility_patient_external_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from enum import Enum

from rest_framework import status
from rest_framework.test import APIRequestFactory, APITestCase
from rest_framework.test import APITestCase
from rest_framework_simplejwt.tokens import RefreshToken

from care.facility.tests.mixins import TestClassMixin
from care.utils.tests.test_base import TestBase
from care.utils.tests.test_utils import TestUtils


class ExpectedPatientExternalTestListKeys(Enum):
Expand Down Expand Up @@ -72,12 +71,17 @@ class DistrictKeys(Enum):
STATE = "state"


class PatientExternalTestViewSetTestCase(TestBase, TestClassMixin, APITestCase):
class PatientExternalTestViewSetTestCase(TestUtils, APITestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.factory = APIRequestFactory()
cls.patient_external = cls.create_patient_external_test()
def setUpTestData(cls) -> None:
cls.state = cls.create_state()
cls.district = cls.create_district(cls.state)
cls.super_user = cls.create_super_user(username="su2", district=cls.district)
cls.local_body = cls.create_local_body(cls.district)
cls.ward = cls.create_ward(cls.local_body)
cls.patient_external = cls.create_patient_external_test(
district=cls.district, local_body=cls.local_body, ward=cls.ward
)

def setUp(self) -> None:
refresh_token = RefreshToken.for_user(self.super_user)
Expand Down
14 changes: 9 additions & 5 deletions care/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ def create_patient_note(

@classmethod
def create_patient_external_test(
cls, ward=None, local_body=None, district=None, **kwargs
cls,
ward: Ward = None,
local_body: LocalBody = None,
district: District = None,
**kwargs,
):
patient = PatientExternalTest(
srf_id=fake.uuid4(),
Expand All @@ -512,9 +516,9 @@ def create_patient_external_test(
result=fake.random_element(elements=("Positive", "Negative", "Pending")),
sample_collection_date=fake.date_this_year(),
result_date=fake.date_this_year(),
district=district or cls.district,
local_body=local_body or cls.local_body,
ward=ward or cls.ward,
district=district,
local_body=local_body,
ward=ward,
)
patient.save()
return patient
Expand All @@ -531,7 +535,7 @@ def create_local_body(cls, district=None, name=None, body_type=10, **kwargs):
@classmethod
def create_ward(cls, local_body=None, name=None, number=10, **kwargs):
data = {
"local_body": local_body or cls.local_body,
"local_body": local_body,
"name": "Test Ward",
"number": number,
}
Expand Down

0 comments on commit f138a04

Please sign in to comment.