Coverage for benefits/eligibility/analytics.py: 83%
27 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-02 19:29 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-02 19:29 +0000
1"""
2The eligibility application: analytics implementation.
3"""
5from benefits.core import analytics as core, models
8class EligibilityEvent(core.Event):
9 """Base analytics event for eligibility verification."""
11 def __init__(self, request, event_type, flow: models.EnrollmentFlow, enrollment_method=models.EnrollmentMethods.DIGITAL):
12 super().__init__(request, event_type, enrollment_method)
13 # overwrite core.Event enrollment flow
14 self.update_enrollment_flows(flow)
17class SelectedFlowEvent(EligibilityEvent):
18 """Analytics event representing the user selecting an enrollment flow."""
20 def __init__(self, request, flow: models.EnrollmentFlow, enrollment_method=models.EnrollmentMethods.DIGITAL):
21 super().__init__(request, "selected enrollment flow", flow, enrollment_method)
24class StartedEligibilityEvent(EligibilityEvent):
25 """Analytics event representing the beginning of an eligibility verification check."""
27 def __init__(self, request, flow: models.EnrollmentFlow, enrollment_method=models.EnrollmentMethods.DIGITAL):
28 super().__init__(request, "started eligibility", flow, enrollment_method)
31class ReturnedEligibilityEvent(EligibilityEvent):
32 """Analytics event representing the end of an eligibility verification check."""
34 def __init__(
35 self, request, flow: models.EnrollmentFlow, status, error=None, enrollment_method=models.EnrollmentMethods.DIGITAL
36 ):
37 super().__init__(request, "returned eligibility", flow, enrollment_method)
38 status = str(status).lower()
39 if status in ("error", "fail", "success"): 39 ↛ exitline 39 didn't return from function '__init__' because the condition on line 39 was always true
40 self.update_event_properties(status=status, error=error)
43def selected_flow(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
44 """Send the "selected enrollment flow" analytics event."""
45 core.send_event(SelectedFlowEvent(request, flow, enrollment_method=enrollment_method))
48def started_eligibility(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
49 """Send the "started eligibility" analytics event."""
50 core.send_event(StartedEligibilityEvent(request, flow, enrollment_method=enrollment_method))
53def returned_error(request, flow: models.EnrollmentFlow, error):
54 """Send the "returned eligibility" analytics event with an error status."""
55 core.send_event(ReturnedEligibilityEvent(request, flow, status="error", error=error))
58def returned_fail(request, flow: models.EnrollmentFlow):
59 """Send the "returned eligibility" analytics event with a fail status."""
60 core.send_event(ReturnedEligibilityEvent(request, flow, status="fail"))
63def returned_success(request, flow: models.EnrollmentFlow, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
64 """Send the "returned eligibility" analytics event with a success status."""
65 core.send_event(ReturnedEligibilityEvent(request, flow, enrollment_method=enrollment_method, status="success"))