Skip to content

Commit

Permalink
refactor(models): default agency card templates
Browse files Browse the repository at this point in the history
further simplify template requirements for flows

rename agency card templates into standard naming pattern:

  {prefix}--{agency.slug}--agency-card.html

where {prefix} is e.g. eligibility/start or enrollment/success
  • Loading branch information
thekaveman committed Oct 29, 2024
1 parent 50cd65f commit 8d1cd32
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 53 deletions.
8 changes: 4 additions & 4 deletions benefits/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def get_readonly_fields(self, request, obj=None):
return [
"claims_provider",
"eligibility_api_url",
"eligibility_start_template",
"eligibility_unverified_template",
"eligibility_start_template_override",
"eligibility_unverified_template_override",
"help_template",
"selection_label_template",
"selection_label_template_override",
"claims_scheme_override",
"enrollment_index_template",
"reenrollment_error_template",
"enrollment_success_template",
"enrollment_success_template_override",
]
else:
return super().get_readonly_fields(request, obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ class Migration(migrations.Migration):
old_name="eligibility_start_template",
new_name="eligibility_start_template_override",
),
migrations.RenameField(
model_name="enrollmentflow",
old_name="eligibility_unverified_template",
new_name="eligibility_unverified_template_override",
),
migrations.RenameField(
model_name="enrollmentflow",
old_name="enrollment_index_template",
new_name="enrollment_index_template_override",
),
migrations.RenameField(
model_name="enrollmentflow",
old_name="enrollment_success_template",
Expand Down Expand Up @@ -121,6 +131,16 @@ class Migration(migrations.Migration):
blank=True, help_text="A human readable label, used as the display text in Admin.", null=True
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="selection_label_template_override",
field=models.TextField(
blank=True,
default=None,
help_text="Override the default template that defines the end-user UI for selecting this flow among other options.", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_start_template_override",
Expand All @@ -133,21 +153,31 @@ class Migration(migrations.Migration):
),
migrations.AlterField(
model_name="enrollmentflow",
name="enrollment_success_template_override",
name="eligibility_unverified_template_override",
field=models.TextField(
blank=True,
default="enrollment/success.html",
help_text="Override the default template for a successful enrollment associated with the enrollment flow",
default=None,
help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="selection_label_template_override",
name="enrollment_index_template_override",
field=models.TextField(
blank=True,
default=None,
help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="enrollment_success_template_override",
field=models.TextField(
blank=True,
default=None,
help_text="Override the default template that defines the end-user UI for selecting this flow among other options.", # noqa
help_text="Override the default template for a successful enrollment associated with the enrollment flow",
null=True,
),
),
Expand Down
6 changes: 1 addition & 5 deletions benefits/core/migrations/local_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
"system_name": "agency_card",
"label": "Agency Card",
"group_id": "group123",
"enrollment_index_template": "enrollment/index--agency-card.html",
"enrollment_success_template_override": "enrollment/success--cst-agency-card.html",
"display_order": 4,
"eligibility_api_url": "http://server:8000/verify",
"eligibility_api_auth_header": "X-Server-API-Key",
Expand All @@ -117,10 +115,7 @@
"eligibility_api_jwe_cek_enc": "A256CBC-HS512",
"eligibility_api_jwe_encryption_alg": "RSA-OAEP",
"eligibility_api_jws_signing_alg": "RS256",
"selection_label_template_override": "eligibility/includes/selection-label--cst-agency-card.html",
"eligibility_start_template_override": "eligibility/start--cst-agency-card.html",
"eligibility_form_class": "benefits.eligibility.forms.CSTAgencyCard",
"eligibility_unverified_template": "eligibility/unverified--cst-agency-card.html",
"help_template": "core/includes/help--cst-agency-card.html",
"supported_enrollment_methods": ["digital", "in_person"],
"transit_agency": 1
Expand All @@ -136,6 +131,7 @@
"supports_expiration": "True",
"expiration_days": 5,
"expiration_reenrollment_days": 3,
"enrollment_index_template_override": "enrollment/index--calfresh.html",
"reenrollment_error_template": "enrollment/reenrollment-error--calfresh.html",
"display_order": 2,
"claims_provider": 1,
Expand Down
57 changes: 48 additions & 9 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ class EnrollmentFlow(models.Model):
blank=True,
help_text="The fully qualified Python path of a form class used by this flow, e.g. benefits.eligibility.forms.FormClass", # noqa: E501
)
eligibility_unverified_template = models.TextField(
default="eligibility/unverified.html",
help_text="Path to a Django template that defines the page when a user fails eligibility verification for this flow.",
eligibility_unverified_template_override = models.TextField(
help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501
blank=True,
null=True,
default=None,
)
help_template = models.TextField(
null=True,
Expand All @@ -404,9 +406,11 @@ class EnrollmentFlow(models.Model):
blank=True,
help_text="If the enrollment supports expiration, number of days preceding the expiration date during which a user can re-enroll in the eligibilty", # noqa: E501
)
enrollment_index_template = models.TextField(
default="enrollment/index.html",
help_text="Template for the Eligibility Confirmation page (which is the index of the enrollment Django app)",
enrollment_index_template_override = models.TextField(
help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)",
null=True,
blank=True,
default=None,
)
reenrollment_error_template = models.TextField(
null=True, blank=True, help_text="Template for a re-enrollment error associated with the enrollment flow"
Expand All @@ -432,6 +436,13 @@ class Meta:
def __str__(self):
return self.label

@property
def agency_card_name(self):
if self.uses_claims_verification:
return ""
else:
return f"{self.transit_agency.slug}-agency-card"

@property
def eligibility_api_auth_key(self):
if self.eligibility_api_auth_key_secret_name is not None:
Expand All @@ -446,11 +457,27 @@ def eligibility_api_public_key_data(self):

@property
def selection_label_template(self):
return self.selection_label_template_override or f"eligibility/includes/selection-label--{self.system_name}.html"
prefix = "eligibility/includes/selection-label"
if self.uses_claims_verification:
return self.selection_label_template_override or f"{prefix}--{self.system_name}.html"
else:
return self.selection_label_template_override or f"{prefix}--{self.agency_card_name}.html"

@property
def eligibility_start_template(self):
return self.eligibility_start_template_override or f"eligibility/start--{self.system_name}.html"
prefix = "eligibility/start"
if self.uses_claims_verification:
return self.eligibility_start_template_override or f"{prefix}--{self.system_name}.html"
else:
return self.eligibility_start_template_override or f"{prefix}--{self.agency_card_name}.html"

@property
def eligibility_unverified_template(self):
prefix = "eligibility/unverified"
if self.uses_claims_verification:
return self.eligibility_unverified_template_override or f"{prefix}.html"
else:
return self.eligibility_unverified_template_override or f"{prefix}--{self.agency_card_name}.html"

@property
def uses_claims_verification(self):
Expand All @@ -468,9 +495,21 @@ def eligibility_verifier(self):
else:
return self.eligibility_api_url

@property
def enrollment_index_template(self):
prefix = "enrollment/index"
if self.uses_claims_verification:
return self.enrollment_index_template_override or f"{prefix}.html"
else:
return self.enrollment_index_template_override or f"{prefix}--agency-card.html"

@property
def enrollment_success_template(self):
return self.enrollment_success_template_override or f"enrollment/success--{self.transit_agency.slug}.html"
prefix = "enrollment/success"
if self.uses_claims_verification:
return self.enrollment_success_template_override or f"{prefix}--{self.transit_agency.slug}.html"
else:
return self.enrollment_success_template_override or f"{prefix}--{self.agency_card_name}.html"

def eligibility_form_instance(self, *args, **kwargs):
"""Return an instance of this flow's EligibilityForm, or None."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>{% translate "You selected a Courtesy Card transit benefit." %}</h1>
{% endblock headline %}

{% block media-item %}
{% include "eligibility/includes/media-item--idcardcheck--start--mst-courtesy-card.html" %}
{% include "eligibility/includes/media-item--idcardcheck--start--mst-agency-card.html" %}
{% endblock media-item %}

{% block call-to-action %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>{% translate "You selected a Reduced Fare Mobility ID transit benefit." %}</
{% endblock headline %}

{% block media-item %}
{% include "eligibility/includes/media-item--idcardcheck--start--sbmtd-mobility-pass.html" %}
{% include "eligibility/includes/media-item--idcardcheck--start--sbmtd-agency-card.html" %}
{% endblock media-item %}

{% block call-to-action %}
Expand Down
2 changes: 2 additions & 0 deletions tests/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def model_EnrollmentFlow(model_TransitAgency):
system_name="test",
selection_label_template_override="eligibility/includes/selection-label.html",
eligibility_start_template_override="eligibility/start.html",
eligibility_unverified_template_override="eligibility/unverified.html",
label="Test flow label",
group_id="group123",
enrollment_index_template_override="enrollment/index.html",
enrollment_success_template_override="enrollment/success.html",
transit_agency=model_TransitAgency,
)
Expand Down
102 changes: 74 additions & 28 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,23 @@ def test_EnrollmentFlow_supports_expiration(model_EnrollmentFlow_supports_expira


@pytest.mark.django_db
def test_EnrollmentFlow_enrollment_index_template(model_TransitAgency):
new_flow = EnrollmentFlow.objects.create(transit_agency=model_TransitAgency)
def test_EnrollmentFlow_enrollment_index_template(model_EnrollmentFlow_with_scope_and_claim):
assert model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template == "enrollment/index.html"

assert new_flow.enrollment_index_template == "enrollment/index.html"

new_flow.enrollment_index_template = "test/enrollment.html"
new_flow.save()
model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template_override = "test/enrollment.html"
model_EnrollmentFlow_with_scope_and_claim.save()

assert new_flow.enrollment_index_template == "test/enrollment.html"
assert model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template == "test/enrollment.html"


@pytest.mark.django_db
def test_EnrollmentFlow_enrollment_success_template(model_TransitAgency):
new_flow = EnrollmentFlow.objects.create(transit_agency=model_TransitAgency)

assert new_flow.enrollment_success_template == "enrollment/success.html"
def test_EnrollmentFlow_enrollment_success_template(model_EnrollmentFlow_with_scope_and_claim):
assert model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template == "enrollment/success.html"


@pytest.mark.django_db
def test_EnrollmentFlow_supported_enrollment_methods(model_TransitAgency):
new_flow = EnrollmentFlow.objects.create(transit_agency=model_TransitAgency)

assert new_flow.supported_enrollment_methods == ["digital", "in_person"]
def test_EnrollmentFlow_supported_enrollment_methods(model_EnrollmentFlow_with_scope_and_claim):
assert model_EnrollmentFlow_with_scope_and_claim.supported_enrollment_methods == ["digital", "in_person"]


@pytest.mark.django_db
Expand Down Expand Up @@ -312,24 +306,76 @@ def test_EnrollmentFlow_with_claims_scheme(model_EnrollmentFlow_with_claims_sche


@pytest.mark.django_db
def test_EnrollmentFlow_template_overrides(model_EnrollmentFlow):
assert model_EnrollmentFlow.selection_label_template == model_EnrollmentFlow.selection_label_template_override
assert model_EnrollmentFlow.eligibility_start_template == model_EnrollmentFlow.eligibility_start_template_override
assert model_EnrollmentFlow.enrollment_success_template == model_EnrollmentFlow.enrollment_success_template_override
def test_EnrollmentFlow_template_overrides_claims(model_EnrollmentFlow_with_scope_and_claim):
assert (
model_EnrollmentFlow_with_scope_and_claim.selection_label_template
== model_EnrollmentFlow_with_scope_and_claim.selection_label_template_override
)
assert (
model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template
== model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template_override
)
assert (
model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template
== model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template_override
)
assert (
model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template
== model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template_override
)
assert (
model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template
== model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template_override
)

model_EnrollmentFlow.selection_label_template_override = None
model_EnrollmentFlow.eligibility_start_template_override = None
model_EnrollmentFlow.enrollment_success_template_override = None
model_EnrollmentFlow.save()
model_EnrollmentFlow_with_scope_and_claim.selection_label_template_override = None
model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template_override = None
model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template_override = None
model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template_override = None
model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template_override = None
model_EnrollmentFlow_with_scope_and_claim.save()

assert (
model_EnrollmentFlow_with_scope_and_claim.selection_label_template
== f"eligibility/includes/selection-label--{model_EnrollmentFlow_with_scope_and_claim.system_name}.html"
)
assert (
model_EnrollmentFlow_with_scope_and_claim.eligibility_start_template
== f"eligibility/start--{model_EnrollmentFlow_with_scope_and_claim.system_name}.html"
)
assert model_EnrollmentFlow_with_scope_and_claim.eligibility_unverified_template == "eligibility/unverified.html"
assert model_EnrollmentFlow_with_scope_and_claim.enrollment_index_template == "enrollment/index.html"
assert (
model_EnrollmentFlow_with_scope_and_claim.enrollment_success_template
== f"enrollment/success--{model_EnrollmentFlow_with_scope_and_claim.transit_agency.slug}.html"
)


@pytest.mark.django_db
def test_EnrollmentFlow_template_overrides_eligibility_api(model_EnrollmentFlow_with_eligibility_api):
model_EnrollmentFlow_with_eligibility_api.selection_label_template_override = None
model_EnrollmentFlow_with_eligibility_api.eligibility_start_template_override = None
model_EnrollmentFlow_with_eligibility_api.eligibility_unverified_template_override = None
model_EnrollmentFlow_with_eligibility_api.enrollment_index_template_override = None
model_EnrollmentFlow_with_eligibility_api.enrollment_success_template_override = None
model_EnrollmentFlow_with_eligibility_api.save()

assert (
model_EnrollmentFlow_with_eligibility_api.selection_label_template
== f"eligibility/includes/selection-label--{model_EnrollmentFlow_with_eligibility_api.agency_card_name}.html"
)
assert (
model_EnrollmentFlow_with_eligibility_api.eligibility_start_template
== f"eligibility/start--{model_EnrollmentFlow_with_eligibility_api.agency_card_name}.html"
)
assert (
model_EnrollmentFlow.selection_label_template
== f"eligibility/includes/selection-label--{model_EnrollmentFlow.system_name}.html"
model_EnrollmentFlow_with_eligibility_api.eligibility_unverified_template
== f"eligibility/unverified--{model_EnrollmentFlow_with_eligibility_api.agency_card_name}.html"
)
assert model_EnrollmentFlow.eligibility_start_template == f"eligibility/start--{model_EnrollmentFlow.system_name}.html"
assert model_EnrollmentFlow_with_eligibility_api.enrollment_index_template == "enrollment/index--agency-card.html"
assert (
model_EnrollmentFlow.enrollment_success_template
== f"enrollment/success--{model_EnrollmentFlow.transit_agency.slug}.html"
model_EnrollmentFlow_with_eligibility_api.enrollment_success_template
== f"enrollment/success--{model_EnrollmentFlow_with_eligibility_api.agency_card_name}.html"
)


Expand Down

0 comments on commit 8d1cd32

Please sign in to comment.