Coverage for benefits / eligibility / verify.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 19:35 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 19:35 +0000
1from django.conf import settings
2from eligibility_api.client import Client
4from benefits.core import models
7def eligibility_from_api(flow: models.EnrollmentFlow, form, agency: models.TransitAgency):
8 sub, name = form.cleaned_data.get("sub"), form.cleaned_data.get("name")
10 client = Client(
11 verify_url=flow.api_request.api_url,
12 headers={flow.api_request.api_auth_header: flow.api_request.api_auth_key},
13 issuer=settings.ALLOWED_HOSTS[0],
14 agency=agency.slug,
15 jws_signing_alg=flow.api_request.api_jws_signing_alg,
16 client_private_key=flow.api_request.client_private_key_data,
17 jwe_encryption_alg=flow.api_request.api_jwe_encryption_alg,
18 jwe_cek_enc=flow.api_request.api_jwe_cek_enc,
19 server_public_key=flow.api_request.api_public_key_data,
20 timeout=settings.REQUESTS_TIMEOUT,
21 )
23 response = client.verify(sub, name, [flow.system_name])
25 if response.error and any(response.error):
26 return None
27 # response.eligibility is a single item list containing the type of eligibility we are trying to verify, e.g. ["senior"]
28 elif flow.system_name in response.eligibility:
29 return True
30 else:
31 return False