Skip to content

Commit

Permalink
chore(deps): bump calitp-littlepay from 2024.3.3 to 2024.4.1 (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalver1 authored Apr 18, 2024
2 parents 420fb6c + 2674923 commit 04dea37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
20 changes: 10 additions & 10 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def index(request):

if eligibility.supports_expiration:
# set expiry on session
if already_enrolled and group_funding_source.concession_expiry is not None:
session.update(request, enrollment_expiry=group_funding_source.concession_expiry)
if already_enrolled and group_funding_source.expiry_date is not None:
session.update(request, enrollment_expiry=group_funding_source.expiry_date)
else:
session.update(request, enrollment_expiry=_calculate_expiry(eligibility.expiration_days))

Expand All @@ -106,7 +106,7 @@ def index(request):
)
return success(request)
else: # already_enrolled
if group_funding_source.concession_expiry is None:
if group_funding_source.expiry_date is None:
# update expiration of existing enrollment, return success
client.update_concession_group_funding_source_expiry(
group_id=group_id,
Expand All @@ -115,9 +115,9 @@ def index(request):
)
return success(request)
else:
is_expired = _is_expired(group_funding_source.concession_expiry)
is_expired = _is_expired(group_funding_source.expiry_date)
is_within_reenrollment_window = _is_within_reenrollment_window(
group_funding_source.concession_expiry, session.enrollment_reenrollment(request)
group_funding_source.expiry_date, session.enrollment_reenrollment(request)
)

if is_expired or is_within_reenrollment_window:
Expand All @@ -137,7 +137,7 @@ def index(request):
client.link_concession_group_funding_source(group_id=group_id, funding_source_id=funding_source.id)
return success(request)
else: # already_enrolled
if group_funding_source.concession_expiry is None:
if group_funding_source.expiry_date is None:
# no action, return success
return success(request)
else:
Expand Down Expand Up @@ -183,14 +183,14 @@ def _get_group_funding_source(client: Client, group_id, funding_source_id):
return matching_group_funding_source


def _is_expired(concession_expiry):
def _is_expired(expiry_date):
"""Returns whether the passed in datetime is expired or not."""
return concession_expiry <= timezone.now()
return expiry_date <= timezone.now()


def _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date):
def _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date):
"""Returns if we are currently within the reenrollment window."""
return enrollment_reenrollment_date <= timezone.now() < concession_expiry
return enrollment_reenrollment_date <= timezone.now() < expiry_date


def _calculate_expiry(expiration_days):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = [
"django-admin-sortable2==2.1.10",
"django-google-sso==6.1.1",
"eligibility-api==2023.9.1",
"calitp-littlepay==2024.3.3",
"calitp-littlepay==2024.4.1",
"requests==2.31.0",
"sentry-sdk==1.44.1",
"six==1.16.0",
Expand Down
64 changes: 31 additions & 33 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,19 @@ def mocked_funding_source():
def mocked_group_funding_source_no_expiry(mocked_funding_source):
return GroupFundingSourceResponse(
id=mocked_funding_source.id,
participant_id=mocked_funding_source.participant_id,
concession_expiry=None,
concession_created_at=None,
concession_updated_at=None,
created_date=None,
updated_date=None,
expiry_date=None,
)


@pytest.fixture
def mocked_group_funding_source_with_expiry(mocked_funding_source):
return GroupFundingSourceResponse(
id=mocked_funding_source.id,
participant_id=mocked_funding_source.participant_id,
concession_expiry="2023-01-01T00:00:00Z",
concession_created_at="2021-01-01T00:00:00Z",
concession_updated_at="2021-01-01T00:00:00Z",
created_date="2023-01-01T00:00:00Z",
updated_date="2021-01-01T00:00:00Z",
expiry_date="2021-01-01T00:00:00Z",
)


Expand Down Expand Up @@ -353,40 +351,40 @@ def test_index_eligible_post_valid_form_success_supports_expiration_no_expiry(
assert model_EligibilityType_supports_expiration.group_id in mocked_analytics_module.returned_success.call_args.args


def test_is_expired_concession_expiry_is_in_the_past(mocker):
concession_expiry = timezone.make_aware(timezone.datetime(2023, 12, 31), timezone.get_default_timezone())
def test_is_expired_expiry_date_is_in_the_past(mocker):
expiry_date = timezone.make_aware(timezone.datetime(2023, 12, 31), timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2024, 1, 1, 10, 30), timezone.get_default_timezone()),
)

assert _is_expired(concession_expiry)
assert _is_expired(expiry_date)


def test_is_expired_concession_expiry_is_in_the_future(mocker):
concession_expiry = timezone.make_aware(timezone.datetime(2024, 1, 1, 17, 34), timezone.get_default_timezone())
def test_is_expired_expiry_date_is_in_the_future(mocker):
expiry_date = timezone.make_aware(timezone.datetime(2024, 1, 1, 17, 34), timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2024, 1, 1, 11, 5), timezone.get_default_timezone()),
)

assert not _is_expired(concession_expiry)
assert not _is_expired(expiry_date)


def test_is_expired_concession_expiry_equals_now(mocker):
concession_expiry = timezone.make_aware(timezone.datetime(2024, 1, 1, 13, 37), timezone.get_default_timezone())
def test_is_expired_expiry_date_equals_now(mocker):
expiry_date = timezone.make_aware(timezone.datetime(2024, 1, 1, 13, 37), timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2024, 1, 1, 13, 37), timezone.get_default_timezone()),
)

assert _is_expired(concession_expiry)
assert _is_expired(expiry_date)


@pytest.mark.django_db
Expand All @@ -405,7 +403,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_expired(
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

# mock that a funding source already exists, doesn't matter what concession_expiry is
# mock that a funding source already exists, doesn't matter what expiry_date is
mocker.patch("benefits.enrollment.views._get_group_funding_source", return_value=mocked_group_funding_source_with_expiry)

mocker.patch("benefits.enrollment.views._is_expired", return_value=True)
Expand All @@ -426,75 +424,75 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_expired(

def test_is_within_enrollment_window_True(mocker):
enrollment_reenrollment_date = timezone.make_aware(timezone.datetime(2023, 2, 1), timezone=timezone.get_default_timezone())
concession_expiry = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())
expiry_date = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2023, 2, 15, 15, 30), timezone=timezone.get_default_timezone()),
)

is_within_reenrollment_window = _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date)
is_within_reenrollment_window = _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date)

assert is_within_reenrollment_window


def test_is_within_enrollment_window_before_window(mocker):
enrollment_reenrollment_date = timezone.make_aware(timezone.datetime(2023, 2, 1), timezone=timezone.get_default_timezone())
concession_expiry = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())
expiry_date = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2023, 1, 15, 15, 30), timezone=timezone.get_default_timezone()),
)

is_within_reenrollment_window = _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date)
is_within_reenrollment_window = _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date)

assert not is_within_reenrollment_window


def test_is_within_enrollment_window_after_window(mocker):
enrollment_reenrollment_date = timezone.make_aware(timezone.datetime(2023, 2, 1), timezone=timezone.get_default_timezone())
concession_expiry = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())
expiry_date = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=timezone.make_aware(timezone.datetime(2023, 3, 15, 15, 30), timezone=timezone.get_default_timezone()),
)

is_within_reenrollment_window = _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date)
is_within_reenrollment_window = _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date)

assert not is_within_reenrollment_window


def test_is_within_enrollment_window_equal_reenrollment_date(mocker):
enrollment_reenrollment_date = timezone.make_aware(timezone.datetime(2023, 2, 1), timezone=timezone.get_default_timezone())
concession_expiry = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())
expiry_date = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=enrollment_reenrollment_date,
)

is_within_reenrollment_window = _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date)
is_within_reenrollment_window = _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date)

assert is_within_reenrollment_window


def test_is_within_enrollment_window_equal_concession_expiry(mocker):
def test_is_within_enrollment_window_equal_expiry_date(mocker):
enrollment_reenrollment_date = timezone.make_aware(timezone.datetime(2023, 2, 1), timezone=timezone.get_default_timezone())
concession_expiry = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())
expiry_date = timezone.make_aware(timezone.datetime(2023, 3, 1), timezone=timezone.get_default_timezone())

# mock datetime of "now" to be specific date for testing
mocker.patch(
"benefits.enrollment.views.timezone.now",
return_value=concession_expiry,
return_value=expiry_date,
)

is_within_reenrollment_window = _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date)
is_within_reenrollment_window = _is_within_reenrollment_window(expiry_date, enrollment_reenrollment_date)

assert not is_within_reenrollment_window

Expand All @@ -515,7 +513,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_within_re
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

# mock that a funding source already exists, doesn't matter what concession_expiry is
# mock that a funding source already exists, doesn't matter what expiry_date is
mocker.patch("benefits.enrollment.views._get_group_funding_source", return_value=mocked_group_funding_source_with_expiry)

mocker.patch("benefits.enrollment.views._is_within_reenrollment_window", return_value=True)
Expand Down Expand Up @@ -553,7 +551,7 @@ def test_index_eligible_post_valid_form_success_supports_expiration_is_not_expir
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

# mock that a funding source already exists, doesn't matter what concession_expiry is
# mock that a funding source already exists, doesn't matter what expiry_date is
mocker.patch("benefits.enrollment.views._get_group_funding_source", return_value=mocked_group_funding_source_with_expiry)

mocker.patch("benefits.enrollment.views._is_expired", return_value=False)
Expand Down Expand Up @@ -582,7 +580,7 @@ def test_index_eligible_post_valid_form_success_does_not_support_expiration_has_
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

# mock that a funding source already exists, doesn't matter what concession_expiry is
# mock that a funding source already exists, doesn't matter what expiry_date is
mocker.patch("benefits.enrollment.views._get_group_funding_source", return_value=mocked_group_funding_source_with_expiry)

path = reverse(ROUTE_INDEX)
Expand Down

0 comments on commit 04dea37

Please sign in to comment.