Skip to content

Commit

Permalink
refactor(verify): return a boolean instead of an eligibility_type
Browse files Browse the repository at this point in the history
  • Loading branch information
lalver1 committed Aug 16, 2024
1 parent ae79d86 commit 681176c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
12 changes: 6 additions & 6 deletions benefits/eligibility/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ def eligibility_from_api(flow: models.EnrollmentFlow, form, agency: models.Trans
timeout=settings.REQUESTS_TIMEOUT,
)

response = client.verify(sub, name, agency.type_names_to_verify(flow))
response = client.verify(sub, name, [flow.system_name])

if response.error and any(response.error):
return None
elif any(response.eligibility):
return list(response.eligibility)
elif [flow.system_name] == response.eligibility:
return True
else:
return []
return False


def eligibility_from_oauth(flow: models.EnrollmentFlow, oauth_claim, agency: models.TransitAgency):
if flow.uses_claims_verification and flow.claims_claim == oauth_claim:
return agency.type_names_to_verify(flow)
return True
else:
return []
return False
23 changes: 10 additions & 13 deletions tests/pytest/eligibility/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def test_eligibility_from_api_error(mocker, model_TransitAgency, model_Enrollmen

@pytest.mark.django_db
def test_eligibility_from_api_verified_types(mocker, model_TransitAgency, model_EnrollmentFlow, mock_api_client_verify, form):
verified_types = ["type1", "type2"]
verified_types = ["Test Flow"]
api_response = mocker.Mock(eligibility=verified_types, error=None)
mock_api_client_verify.return_value = api_response

response = eligibility_from_api(model_EnrollmentFlow, form, model_TransitAgency)

assert response == verified_types
assert response is True


@pytest.mark.django_db
Expand All @@ -46,7 +46,7 @@ def test_eligibility_from_api_no_verified_types(

response = eligibility_from_api(model_EnrollmentFlow, form, model_TransitAgency)

assert response == verified_types
assert response is False


@pytest.mark.django_db
Expand All @@ -56,9 +56,9 @@ def test_eligibility_from_oauth_does_not_use_claims_verification(
# mocked_session_flow_does_not_use_claims_verification is Mocked version of the session.flow() function
flow = mocked_session_flow_does_not_use_claims_verification.return_value

types = eligibility_from_oauth(flow, "claim", model_TransitAgency)
response = eligibility_from_oauth(flow, "claim", model_TransitAgency)

assert types == []
assert response is False


@pytest.mark.django_db
Expand All @@ -67,20 +67,17 @@ def test_eligibility_from_oauth_claim_mismatch(mocked_session_flow_uses_claims_v
flow = mocked_session_flow_uses_claims_verification.return_value
flow.claims_claim = "claim"

types = eligibility_from_oauth(flow, "some_other_claim", model_TransitAgency)
response = eligibility_from_oauth(flow, "some_other_claim", model_TransitAgency)

assert types == []
assert response is False


@pytest.mark.django_db
def test_eligibility_from_oauth_claim_match(
mocked_session_flow_uses_claims_verification, model_EligibilityType, model_TransitAgency
):
def test_eligibility_from_oauth_claim_match(mocked_session_flow_uses_claims_verification, model_TransitAgency):
# mocked_session_flow_uses_claims_verification is Mocked version of the session.flow() function
flow = mocked_session_flow_uses_claims_verification.return_value
flow.claims_claim = "claim"
flow.eligibility_type = model_EligibilityType

types = eligibility_from_oauth(flow, "claim", model_TransitAgency)
response = eligibility_from_oauth(flow, "claim", model_TransitAgency)

assert types == [model_EligibilityType.name]
assert response is True

0 comments on commit 681176c

Please sign in to comment.