diff --git a/care/facility/tests/test_asset_api.py b/care/facility/tests/test_asset_api.py index b09bc0137e..4958eb61ac 100644 --- a/care/facility/tests/test_asset_api.py +++ b/care/facility/tests/test_asset_api.py @@ -2,7 +2,7 @@ from django.db import transaction from rest_framework import status -from rest_framework.test import APIRequestFactory, APITestCase +from rest_framework.test import APIRequestFactory from rest_framework_simplejwt.tokens import RefreshToken from care.facility.api.viewsets.asset import AssetViewSet @@ -59,7 +59,7 @@ class ExpectedAssetRetrieveKeys(Enum): NOTES = "notes" -class AssetViewSetTestCase(TestBase, TestClassMixin, APITestCase): +class AssetViewSetTestCase(TestBase, TestClassMixin): endpoint = "/api/v1/asset/" asset_id = None @@ -71,12 +71,6 @@ def setUpClass(cls): district = cls.create_district(state=state) cls.user = cls.create_user(district=district, username="test user") facility = cls.create_facility(district=district, user=cls.user) - # Refresh token to header - refresh_token = RefreshToken.for_user(cls.user) - cls.client.credentials( - HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" - ) - cls.asset1_location = AssetLocation.objects.create( name="asset1 location", location_type=1, facility=facility ) @@ -84,6 +78,13 @@ def setUpClass(cls): name="Test Asset", current_location=cls.asset1_location, asset_type=50 ) + def setUp(self): + # Refresh token to header + refresh_token = RefreshToken.for_user(self.user) + self.client.credentials( + HTTP_AUTHORIZATION=f"Bearer {refresh_token.access_token}" + ) + def test_list_assets(self): response = self.client.get(self.endpoint) diff --git a/care/utils/tests/test_base.py b/care/utils/tests/test_base.py index 3ed212c1b2..8ba6c7b4d8 100644 --- a/care/utils/tests/test_base.py +++ b/care/utils/tests/test_base.py @@ -438,12 +438,13 @@ def create_consultation( data.update(kwargs) return PatientConsultation.objects.create(**data) + @classmethod def create_patient_note( - self, patient=None, facility=None, note="Patient is doing find", **kwargs + cls, patient=None, facility=None, note="Patient is doing find", **kwargs ): data = { - "patient": patient or self.patient, - "facility": facility or self.facility, + "patient": patient or cls.patient, + "facility": facility or cls.facility, "note": note, } data.update(kwargs)