Skip to content

Commit

Permalink
test: make assertion about expiry date more specific
Browse files Browse the repository at this point in the history
we know that we should be using the value from session.enrollment_expiry
  • Loading branch information
angela-tran committed Mar 28, 2024
1 parent eae13a5 commit 5b1c1ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tests/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5b1c1ba

Please sign in to comment.