From 5d7983957e97b3eb21a4a04221500549e804c7c7 Mon Sep 17 00:00:00 2001 From: Brianna Cerkiewicz Date: Thu, 23 Jan 2025 15:32:17 -0800 Subject: [PATCH] chore: apply more suggestions from code review --- bc_obps/registration/schema/v2/operation.py | 1 - bc_obps/service/contact_service_v2.py | 8 ++------ bc_obps/service/tests/test_contact_service_v2.py | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/bc_obps/registration/schema/v2/operation.py b/bc_obps/registration/schema/v2/operation.py index c3d50c2094..1025b50238 100644 --- a/bc_obps/registration/schema/v2/operation.py +++ b/bc_obps/registration/schema/v2/operation.py @@ -194,7 +194,6 @@ class Meta: 'status', 'activities', 'opted_in_operation', - # 'contacts', ] from_attributes = True diff --git a/bc_obps/service/contact_service_v2.py b/bc_obps/service/contact_service_v2.py index b5960505bd..4981d2e609 100644 --- a/bc_obps/service/contact_service_v2.py +++ b/bc_obps/service/contact_service_v2.py @@ -32,13 +32,9 @@ def list_contacts_v2( ) return cast(QuerySet[Contact], queryset) - @classmethod - def get_by_id(cls, contact_id: int) -> Contact: - return Contact.objects.get(id=contact_id) - @classmethod def get_with_places_assigned_v2(cls, contact_id: int) -> Optional[ContactWithPlacesAssigned]: - contact = cls.get_by_id(contact_id) + contact = ContactDataAccessService.get_by_id(contact_id) places_assigned = [] if contact: role_name = contact.business_role.role_name @@ -58,7 +54,7 @@ def get_with_places_assigned_v2(cls, contact_id: int) -> Optional[ContactWithPla @classmethod def raise_exception_if_contact_missing_address_information(cls, contact_id: int) -> None: """This function checks that a contact has a complete address record (contact.address exists and all fields in the address model have a value). In general in the app, address is not mandatory, but in certain cases (e.g., when a contact is assigned to an operation as the Operation Representative), the business area requires the contact to have an address.""" - contact = cls.get_by_id(contact_id) + contact = ContactDataAccessService.get_by_id(contact_id) address = contact.address if not address or any( not getattr(address, field, None) for field in ['street_address', 'municipality', 'province', 'postal_code'] diff --git a/bc_obps/service/tests/test_contact_service_v2.py b/bc_obps/service/tests/test_contact_service_v2.py index cdbb31b9d1..ac18f8e239 100644 --- a/bc_obps/service/tests/test_contact_service_v2.py +++ b/bc_obps/service/tests/test_contact_service_v2.py @@ -47,7 +47,7 @@ def test_get_with_places_assigned_with_contacts(): operation = baker.make_recipe('utils.operation', operator=approved_user_operator.operator) operation.contacts.set([contact]) - result = ContactServiceV2.get_with_places_assigned_v2(approved_user_operator.user.user_guid, contact.id) + result = ContactServiceV2.get_with_places_assigned_v2(contact.id) assert result.places_assigned == [ PlacesAssigned( role_name=contact.business_role.role_name, operation_name=operation.name, operation_id=operation.id @@ -63,7 +63,7 @@ def test_get_with_places_assigned_with_no_contacts(): # add contact to operator (they have to be associated with the operator or will throw unauthorized) approved_user_operator.operator.contacts.set([contact]) - result = ContactServiceV2.get_with_places_assigned_v2(approved_user_operator.user.user_guid, contact.id) + result = ContactServiceV2.get_with_places_assigned_v2(contact.id) assert not hasattr(result, 'places_assigned') @staticmethod