From cd5450db0c85b974fa445c8015f5b64f63b4f1ca Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Thu, 28 Mar 2024 20:09:06 +0000 Subject: [PATCH] test: make assertion about expiry date more specific we know that we should be using the value from session.enrollment_expiry --- tests/pytest/conftest.py | 10 ++++++++++ tests/pytest/enrollment/test_views.py | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index c10093d6df..aea5920b3c 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -1,6 +1,7 @@ from unittest.mock import create_autospec from django.contrib.sessions.middleware import SessionMiddleware from django.middleware.locale import LocaleMiddleware +from django.utils import timezone import pytest from pytest_socket import disable_socket @@ -256,6 +257,15 @@ def mocked_session_oauth_token(mocker): return mocker.patch("benefits.core.session.oauth_token", autospec=True, return_value="token") +@pytest.fixture +def mocked_session_enrollment_expiry(mocker): + return mocker.patch( + "benefits.core.session.enrollment_expiry", + autospec=True, + return_value=timezone.make_aware(timezone.datetime(2024, 1, 1), timezone=timezone.get_default_timezone()), + ) + + @pytest.fixture def mocked_session_verifier(mocker, model_EligibilityVerifier): return mocker.patch("benefits.core.session.verifier", autospec=True, return_value=model_EligibilityVerifier) diff --git a/tests/pytest/enrollment/test_views.py b/tests/pytest/enrollment/test_views.py index 8bddb982a0..cb5a0b1009 100644 --- a/tests/pytest/enrollment/test_views.py +++ b/tests/pytest/enrollment/test_views.py @@ -293,6 +293,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration( mocked_analytics_module, model_EligibilityType_supports_expiration, mocked_funding_source, + mocked_session_enrollment_expiry, ): mock_client_cls = mocker.patch("benefits.enrollment.views.Client") mock_client = mock_client_cls.return_value @@ -304,7 +305,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration( mock_client.link_concession_group_funding_source.assert_called_once_with( funding_source_id=mocked_funding_source.id, group_id=model_EligibilityType_supports_expiration.group_id, - expiry_date=mocker.ANY, + expiry_date=mocked_session_enrollment_expiry.return_value, ) assert response.status_code == 200 assert response.template_name == TEMPLATE_SUCCESS @@ -322,6 +323,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_no_expiratio model_EligibilityType_supports_expiration, mocked_funding_source, mocked_group_funding_source_no_expiration, + mocked_session_enrollment_expiry, ): mock_client_cls = mocker.patch("benefits.enrollment.views.Client") mock_client = mock_client_cls.return_value @@ -335,7 +337,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_no_expiratio mock_client.link_concession_group_funding_source.assert_called_once_with( funding_source_id=mocked_funding_source.id, group_id=model_EligibilityType_supports_expiration.group_id, - expiry_date=mocker.ANY, + expiry_date=mocked_session_enrollment_expiry.return_value, ) assert response.status_code == 200 assert response.template_name == TEMPLATE_SUCCESS @@ -389,6 +391,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_expired( model_EligibilityType_supports_expiration, mocked_funding_source, mocked_group_funding_source_with_expiration, + mocked_session_enrollment_expiry, ): mock_client_cls = mocker.patch("benefits.enrollment.views.Client") mock_client = mock_client_cls.return_value @@ -407,7 +410,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_expired( mock_client.link_concession_group_funding_source.assert_called_once_with( funding_source_id=mocked_funding_source.id, group_id=model_EligibilityType_supports_expiration.group_id, - expiry_date=mocker.ANY, + expiry_date=mocked_session_enrollment_expiry.return_value, ) assert response.status_code == 200 assert response.template_name == TEMPLATE_SUCCESS @@ -500,6 +503,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_within_re model_EligibilityType_supports_expiration, mocked_funding_source, mocked_group_funding_source_with_expiration, + mocked_session_enrollment_expiry, ): mock_client_cls = mocker.patch("benefits.enrollment.views.Client") mock_client = mock_client_cls.return_value @@ -518,7 +522,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_within_re mock_client.link_concession_group_funding_source.assert_called_once_with( funding_source_id=mocked_funding_source.id, group_id=model_EligibilityType_supports_expiration.group_id, - expiry_date=mocker.ANY, + expiry_date=mocked_session_enrollment_expiry.return_value, ) assert response.status_code == 200 assert response.template_name == TEMPLATE_SUCCESS