Skip to content

Commit

Permalink
chore: apply more suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jan 23, 2025
1 parent 882d900 commit 5d79839
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 0 additions & 1 deletion bc_obps/registration/schema/v2/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class Meta:
'status',
'activities',
'opted_in_operation',
# 'contacts',
]
from_attributes = True

Expand Down
8 changes: 2 additions & 6 deletions bc_obps/service/contact_service_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions bc_obps/service/tests/test_contact_service_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5d79839

Please sign in to comment.