Skip to content

Commit

Permalink
feat(models): EligibilityType stores its enrollment index template
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Mar 22, 2024
1 parent cc0a6d3 commit 41f9526
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-03-22 17:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0005_move_help_template_to_eligibilityverifier"),
]

operations = [
migrations.AddField(
model_name="eligibilitytype",
name="enrollment_index_template",
field=models.TextField(default="enrollment/index.html"),
),
]
1 change: 1 addition & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class EligibilityType(models.Model):
supports_expiration = models.BooleanField(default=False)
expiration_days = models.PositiveSmallIntegerField(null=True, blank=True)
expiration_reenrollment_days = models.PositiveSmallIntegerField(null=True, blank=True)
enrollment_index_template = models.TextField(default="enrollment/index.html")

def __str__(self):
return self.label
Expand Down
9 changes: 3 additions & 6 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from littlepay.api.client import Client
from requests.exceptions import HTTPError

from benefits.core import models, session
from benefits.core import session
from benefits.core.middleware import (
EligibleSessionRequired,
VerifierSessionRequired,
Expand All @@ -26,7 +26,6 @@
ROUTE_SUCCESS = "enrollment:success"
ROUTE_TOKEN = "enrollment:token"

TEMPLATE_INDEX = "enrollment/index.html"
TEMPLATE_RETRY = "enrollment/retry.html"
TEMPLATE_SUCCESS = "enrollment/success.html"

Expand Down Expand Up @@ -61,6 +60,7 @@ def index(request):
session.update(request, origin=reverse(ROUTE_INDEX))

agency = session.agency(request)
eligibility = session.eligibility(request)
payment_processor = agency.payment_processor

# POST back after payment processor form, process card token
Expand All @@ -69,9 +69,6 @@ def index(request):
if not form.is_valid():
raise Exception("Invalid card token form")

eligibility = session.eligibility(request)
logger.debug(f"Session contains an {models.EligibilityType.__name__}")

logger.debug("Read tokenized card")
card_token = form.cleaned_data.get("card_token")

Expand Down Expand Up @@ -122,7 +119,7 @@ def index(request):

logger.debug(f'card_tokenize_url: {context["card_tokenize_url"]}')

return TemplateResponse(request, TEMPLATE_INDEX, context)
return TemplateResponse(request, eligibility.enrollment_index_template, context)


@decorator_from_middleware(EligibleSessionRequired)
Expand Down
10 changes: 10 additions & 0 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ def test_EligibilityType_supports_expiration(model_EligibilityType_supports_expi
model_EligibilityType_supports_expiration.full_clean()


@pytest.mark.django_db
def test_EligibilityType_enrollment_index_template(model_EligibilityType):
assert model_EligibilityType.enrollment_index_template == "enrollment/index.html"

model_EligibilityType.enrollment_index_template = "test/enrollment.html"
model_EligibilityType.save()

assert model_EligibilityType.enrollment_index_template == "test/enrollment.html"


class SampleFormClass:
"""A class for testing EligibilityVerifier form references."""

Expand Down
5 changes: 2 additions & 3 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ROUTE_TOKEN,
ROUTE_SUCCESS,
ROUTE_RETRY,
TEMPLATE_INDEX,
TEMPLATE_SUCCESS,
TEMPLATE_RETRY,
)
Expand Down Expand Up @@ -101,12 +100,12 @@ def test_token_valid(mocker, client):

@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_verifier", "mocked_session_eligibility")
def test_index_eligible_get(client):
def test_index_eligible_get(client, model_EligibilityType):
path = reverse(ROUTE_INDEX)
response = client.get(path)

assert response.status_code == 200
assert response.template_name == TEMPLATE_INDEX
assert response.template_name == model_EligibilityType.enrollment_index_template
assert "forms" in response.context_data
assert "cta_button" in response.context_data
assert "card_tokenize_env" in response.context_data
Expand Down

0 comments on commit 41f9526

Please sign in to comment.