Skip to content

Commit e3f015f

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.
1 parent 2ee7267 commit e3f015f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

benefits/enrollment_switchio/views.py

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

tests/pytest/enrollment_switchio/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import pytest
3+
4+
from benefits.enrollment_switchio.views import GatewayUrlView, IndexView
5+
6+
7+
class TestIndexView:
8+
@pytest.mark.django_db
9+
def test_get_context_data(self, app_request, mocker, model_EnrollmentFlow):
10+
view = IndexView()
11+
view.setup(app_request)
12+
mocker.patch("benefits.core.session.flow", return_value=model_EnrollmentFlow)
13+
context = view.get_context_data()
14+
15+
assert "cta_button" in context
16+
assert "enrollment_method" in context
17+
assert "headline" in context
18+
assert "next_step" in context
19+
assert "partner_post_link" in context
20+
assert "alert_include" in context
21+
assert "transit_processor" in context
22+
23+
24+
class TestGatewayUrlView:
25+
@pytest.mark.django_db
26+
def test_get_gateway_url(self, app_request):
27+
28+
response = GatewayUrlView.as_view()(app_request)
29+
30+
assert response.status_code == 200
31+
assert json.loads(response.content) == {"gateway_url": "https://server/gateway/uuid"}

0 commit comments

Comments
 (0)