Coverage for benefits/enrollment/analytics.py: 74%
21 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 18:00 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 18:00 +0000
1"""
2The enrollment application: analytics implementation.
3"""
5from benefits.core import analytics as core, models
8class ReturnedEnrollmentEvent(core.Event):
9 """Analytics event representing the end of transit processor enrollment request."""
11 def __init__(
12 self,
13 request,
14 status,
15 error=None,
16 enrollment_group=None,
17 enrollment_method=models.EnrollmentMethods.DIGITAL,
18 extra_claims=None,
19 ):
20 super().__init__(request, "returned enrollment", enrollment_method)
21 if str(status).lower() in ("error", "retry", "success"): 21 ↛ 23line 21 didn't jump to line 23 because the condition on line 21 was always true
22 self.update_event_properties(status=status, error=error, extra_claims=extra_claims)
23 if enrollment_group is not None: 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true
24 self.update_event_properties(enrollment_group=enrollment_group)
27class FailedAccessTokenRequestEvent(core.Event):
28 """Analytics event representing a failure to acquire an access token for card tokenization."""
30 def __init__(self, request, status_code=None, enrollment_method=models.EnrollmentMethods.DIGITAL):
31 super().__init__(request, "failed access token request", enrollment_method)
32 if status_code is not None: 32 ↛ exitline 32 didn't return from function '__init__' because the condition on line 32 was always true
33 self.update_event_properties(status_code=status_code)
36def returned_error(request, error, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
37 """Send the "returned enrollment" analytics event with an error status and message."""
38 core.send_event(ReturnedEnrollmentEvent(request, status="error", error=error, enrollment_method=enrollment_method))
41def returned_retry(request, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
42 """Send the "returned enrollment" analytics event with a retry status."""
43 core.send_event(ReturnedEnrollmentEvent(request, status="retry", enrollment_method=enrollment_method))
46def returned_success(request, enrollment_group, enrollment_method: str = models.EnrollmentMethods.DIGITAL, extra_claims=None):
47 """Send the "returned enrollment" analytics event with a success status."""
48 core.send_event(
49 ReturnedEnrollmentEvent(
50 request,
51 status="success",
52 enrollment_group=enrollment_group,
53 enrollment_method=enrollment_method,
54 extra_claims=extra_claims,
55 )
56 )
59def failed_access_token_request(request, status_code=None, enrollment_method: str = models.EnrollmentMethods.DIGITAL):
60 """Send the "failed access token request" analytics event with the response status code."""
61 core.send_event(FailedAccessTokenRequestEvent(request, status_code=status_code, enrollment_method=enrollment_method))