|
1 | 1 | from django.conf import settings |
| 2 | +from django.urls import reverse |
2 | 3 | import pytest |
3 | 4 | from requests import HTTPError |
4 | 5 | from benefits.enrollment.enrollment import Status |
|
8 | 9 | get_registration_status, |
9 | 10 | request_registration, |
10 | 11 | get_latest_active_token_value, |
| 12 | + _generate_redirect_uri, |
11 | 13 | ) |
| 14 | +from benefits.routes import routes |
12 | 15 |
|
13 | 16 |
|
14 | 17 | @pytest.fixture |
@@ -51,13 +54,42 @@ def mocked_group_expiry_with_expiry(): |
51 | 54 |
|
52 | 55 | @pytest.mark.django_db |
53 | 56 | @pytest.mark.usefixtures("mocked_api_base_url") |
54 | | -def test_request_registration_success(mocker, app_request, model_SwitchioConfig, mocked_registration): |
55 | | - mocker.patch( |
56 | | - "benefits.enrollment_switchio.enrollment.TokenizationClient.request_registration", return_value=mocked_registration |
57 | | - ) |
| 57 | +def test_request_registration_success__default_redirect( |
| 58 | + mocker, app_request, model_SwitchioConfig, mocked_registration, settings |
| 59 | +): |
| 60 | + tokenization_client = mocker.patch("benefits.enrollment_switchio.enrollment.TokenizationClient").return_value |
| 61 | + tokenization_client.request_registration.return_value = mocked_registration |
| 62 | + expected_redirect = _generate_redirect_uri(app_request, reverse(routes.ENROLLMENT_SWITCHIO_INDEX)) |
58 | 63 |
|
59 | 64 | registration_response = request_registration(app_request, model_SwitchioConfig) |
60 | 65 |
|
| 66 | + tokenization_client.request_registration.assert_called_once_with( |
| 67 | + eshopRedirectUrl=expected_redirect, |
| 68 | + mode=RegistrationMode.REGISTER, |
| 69 | + eshopResponseMode=EshopResponseMode.QUERY, |
| 70 | + timeout=settings.REQUESTS_TIMEOUT, |
| 71 | + ) |
| 72 | + assert registration_response.status == Status.SUCCESS |
| 73 | + assert registration_response.registration == mocked_registration |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.django_db |
| 77 | +@pytest.mark.usefixtures("mocked_api_base_url") |
| 78 | +def test_request_registration_success__custom_redirect( |
| 79 | + mocker, app_request, model_SwitchioConfig, mocked_registration, settings |
| 80 | +): |
| 81 | + tokenization_client = mocker.patch("benefits.enrollment_switchio.enrollment.TokenizationClient").return_value |
| 82 | + tokenization_client.request_registration.return_value = mocked_registration |
| 83 | + expected_redirect = _generate_redirect_uri(app_request, reverse(routes.INDEX)) |
| 84 | + |
| 85 | + registration_response = request_registration(app_request, model_SwitchioConfig, routes.INDEX) |
| 86 | + |
| 87 | + tokenization_client.request_registration.assert_called_once_with( |
| 88 | + eshopRedirectUrl=expected_redirect, |
| 89 | + mode=RegistrationMode.REGISTER, |
| 90 | + eshopResponseMode=EshopResponseMode.QUERY, |
| 91 | + timeout=settings.REQUESTS_TIMEOUT, |
| 92 | + ) |
61 | 93 | assert registration_response.status == Status.SUCCESS |
62 | 94 | assert registration_response.registration == mocked_registration |
63 | 95 |
|
|
0 commit comments