Skip to content

Commit 5ba74cc

Browse files
committed
feat: add IndexView and GatewayUrlView to enrollment_switchio
IndexView currently handles the bare minimum to render the index page for the enrollment_switchio app. GatewayUrlView is a placeholder for the future implementation of the Switchio tokenization gateway registration. As a result of how IndexView is implemented, remove unnecessary context methods from the SwitchioConfig model.
1 parent 7cdbfbf commit 5ba74cc

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

benefits/enrollment_switchio/models.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ def api_secret(self):
5151
secret_field = self._meta.get_field("api_secret_name")
5252
return secret_field.secret_value(self)
5353

54-
@property
55-
def transit_processor_context(self):
56-
return dict(name="Switchio", website="https://switchio.com/transport/")
57-
58-
@property
59-
def enrollment_index_template(self):
60-
return "enrollment_switchio/index.html"
61-
6254
def clean(self, agency=None):
6355
field_errors = {}
6456

benefits/enrollment_switchio/views.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.http import JsonResponse
2+
from django.views.generic import TemplateView, View
3+
4+
from benefits.core import models, session
5+
from benefits.core.mixins import EligibleSessionRequiredMixin
6+
7+
8+
class IndexView(EligibleSessionRequiredMixin, TemplateView):
9+
"""View for the enrollment landing page."""
10+
11+
template_name = "enrollment_switchio/index.html"
12+
13+
def get_context_data(self, **kwargs):
14+
context = super().get_context_data(**kwargs)
15+
16+
flow = session.flow(self.request)
17+
18+
context.update(
19+
{
20+
**flow.enrollment_index_context,
21+
"cta_button": "tokenize_card",
22+
"enrollment_method": models.EnrollmentMethods.DIGITAL,
23+
"transit_processor": {"name": "Switchio", "website": "https://switchio.com/transport/"},
24+
}
25+
)
26+
return context
27+
28+
29+
class GatewayUrlView(EligibleSessionRequiredMixin, View):
30+
"""View for the tokenization gateway registration"""
31+
32+
def get(self, request, *args, **kwargs):
33+
data = {"gateway_url": "https://server/gateway/uuid"}
34+
return JsonResponse(data)

tests/pytest/enrollment_switchio/__init__.py

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import json
2+
import pytest
3+
4+
from benefits.enrollment_switchio.views import GatewayUrlView, IndexView
5+
6+
7+
class TestIndexView:
8+
@pytest.fixture
9+
def view(self, app_request):
10+
"""Fixture to create an instance of IndexView."""
11+
v = IndexView()
12+
v.setup(app_request)
13+
14+
return v
15+
16+
@pytest.mark.django_db
17+
@pytest.mark.usefixtures("mocked_session_flow")
18+
def test_get_context_data(self, view):
19+
20+
context = view.get_context_data()
21+
22+
assert "cta_button" in context
23+
assert "enrollment_method" in context
24+
assert "headline" in context
25+
assert "next_step" in context
26+
assert "partner_post_link" in context
27+
assert "alert_include" in context
28+
assert "transit_processor" in context.keys()
29+
transit_processor_context = context["transit_processor"]
30+
assert "name" in transit_processor_context
31+
assert "website" in transit_processor_context
32+
33+
34+
class TestGatewayUrlView:
35+
@pytest.fixture
36+
def view(self, app_request):
37+
"""Fixture to create an instance of GatewayUrlView."""
38+
v = GatewayUrlView()
39+
v.setup(app_request)
40+
41+
return v
42+
43+
@pytest.mark.django_db
44+
def test_get_gateway_url(self, view, app_request):
45+
46+
response = view.get(app_request)
47+
48+
assert response.status_code == 200
49+
assert json.loads(response.content) == {"gateway_url": "https://server/gateway/uuid"}

0 commit comments

Comments
 (0)