Skip to content

Commit

Permalink
refactor(models): flow property for the verifier string
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Sep 19, 2024
1 parent 901ba9f commit 86cf78f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ def uses_claims_verification(self):
"""True if this flow verifies via the claims provider and has a scope and claim. False otherwise."""
return self.claims_provider is not None and bool(self.claims_scope) and bool(self.claims_claim)

@property
def eligibility_verifier(self):
"""A str representing the entity that verifies eligibility for this flow.
Either the client name of the flow's claims provider, or the URL to the eligibility API.
"""
if self.uses_claims_verification:
return self.claims_provider.client_name
else:
return self.eligibility_api_url

def eligibility_form_instance(self, *args, **kwargs):
"""Return an instance of this flow's EligibilityForm, or None."""
if not bool(self.eligibility_form_class):
Expand Down
3 changes: 1 addition & 2 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ def index(request):
agency = session.agency(request)
flow = session.flow(request)
expiry = session.enrollment_expiry(request)
verified_by = flow.claims_provider.client_name if flow.uses_claims_verification else flow.eligibility_api_url
event = models.EnrollmentEvent.objects.create(
transit_agency=agency,
enrollment_flow=flow,
enrollment_method=models.EnrollmentMethods.DIGITAL,
verified_by=verified_by,
verified_by=flow.eligibility_verifier,
expiration_datetime=expiry,
)
event.save()
Expand Down
12 changes: 12 additions & 0 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ def test_EnrollmentFlow_by_id_nonmatching():
def test_EnrollmentFlow_with_scope_and_claim(model_EnrollmentFlow_with_scope_and_claim):

assert model_EnrollmentFlow_with_scope_and_claim.uses_claims_verification
assert (
model_EnrollmentFlow_with_scope_and_claim.eligibility_verifier
== model_EnrollmentFlow_with_scope_and_claim.claims_provider.client_name
)


@pytest.mark.django_db
Expand All @@ -254,6 +258,14 @@ def test_EnrollmentFlow_no_scope_and_claim_no_sign_out(model_EnrollmentFlow, mod
assert not model_EnrollmentFlow.uses_claims_verification


@pytest.mark.django_db
def test_EnrollmentFlow_eligibility_api(model_EnrollmentFlow_with_eligibility_api):
assert (
model_EnrollmentFlow_with_eligibility_api.eligibility_verifier
== model_EnrollmentFlow_with_eligibility_api.eligibility_api_url
)


@pytest.mark.django_db
def test_EnrollmentFlow_eligibility_api_auth_key(model_EnrollmentFlow_with_eligibility_api, mock_models_get_secret_by_name):
secret_value = model_EnrollmentFlow_with_eligibility_api.eligibility_api_auth_key
Expand Down

0 comments on commit 86cf78f

Please sign in to comment.