Skip to content

Commit

Permalink
Merge pull request #431 from openedx/pwnage101/ENT-8518-2
Browse files Browse the repository at this point in the history
fix: add missing serializer field `is_late_redemption_allowed`
  • Loading branch information
pwnage101 authored Mar 29, 2024
2 parents b43c313 + 3bb8cb9 commit 1946d7b
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ class SubsidyAccessPolicyRedeemableResponseSerializer(serializers.ModelSerialize
"""

policy_redemption_url = serializers.SerializerMethodField()
is_late_redemption_allowed = serializers.BooleanField(
help_text="True if late redemption is currently allowed (i.e. late_redemption_allowed_until is in the future)."
)

class Meta:
model = SubsidyAccessPolicy
Expand Down
44 changes: 34 additions & 10 deletions enterprise_access/apps/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Tests for the serializers in the API.
"""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from unittest import mock
from uuid import uuid4

import ddt
from django.conf import settings
from django.test import TestCase
from django.urls import reverse
from freezegun import freeze_time

from enterprise_access.apps.api.serializers.subsidy_access_policy import (
SubsidyAccessPolicyAggregatesSerializer,
Expand Down Expand Up @@ -121,31 +121,55 @@ def test_aggregates(
assert data["spend_available_usd_cents"] == available


@ddt.ddt
class TestSubsidyAccessPolicyRedeemableResponseSerializer(TestCase):
"""
Tests for the SubsidyAccessPolicyRedeemableResponseSerializer.
"""
NOW = datetime(2017, 1, 1, 0, 0, 0, tzinfo=timezone.utc)

def setUp(self):
self.non_redeemable_policy = PerLearnerEnrollmentCapLearnerCreditAccessPolicyFactory()
self.subsidy_access_policy_redeem_endpoint = reverse(
'api:v1:policy-redemption-redeem',
kwargs={'policy_uuid': self.non_redeemable_policy.uuid}
)
self.redeemable_policy = PerLearnerEnrollmentCapLearnerCreditAccessPolicyFactory()

def test_get_policy_redemption_url(self):
"""
Test that the get_policy_redemption_url method returns the correct
URL for the policy redemption.
"""

serializer = SubsidyAccessPolicyRedeemableResponseSerializer(self.non_redeemable_policy)
serializer = SubsidyAccessPolicyRedeemableResponseSerializer(self.redeemable_policy)

data = serializer.data
self.assertIn("policy_redemption_url", data)
expected_url = f"{settings.ENTERPRISE_ACCESS_URL}/api/v1/policy-redemption/" \
f"{self.non_redeemable_policy.uuid}/redeem/"
f"{self.redeemable_policy.uuid}/redeem/"
self.assertEqual(data["policy_redemption_url"], expected_url)

@ddt.data(
{
'late_redemption_allowed_until': None,
'expected_is_late_redemption_allowed': False,
},
{
'late_redemption_allowed_until': NOW - timedelta(days=1),
'expected_is_late_redemption_allowed': False,
},
{
'late_redemption_allowed_until': NOW + timedelta(days=1),
'expected_is_late_redemption_allowed': True,
},
)
@ddt.unpack
@freeze_time(NOW)
def test_is_late_enrollment_allowed(self, late_redemption_allowed_until, expected_is_late_redemption_allowed):
"""
Test that the `is_late_enrollment_allowed` computed field is present and correct.
"""
policy = PerLearnerEnrollmentCapLearnerCreditAccessPolicyFactory(
late_redemption_allowed_until=late_redemption_allowed_until
)
serializer = SubsidyAccessPolicyRedeemableResponseSerializer(policy)
assert serializer.data["is_late_redemption_allowed"] == expected_is_late_redemption_allowed


class TestSubsidyAccessPolicyCreditsAvailableResponseSerializer(TestCase):
"""
Expand Down
6 changes: 3 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ django-crum==0.7.9
# edx-rbac
django-extensions==3.2.3
# via -r requirements/base.in
django-filter==24.1
django-filter==24.2
# via -r requirements/base.in
django-log-request-id==2.1.0
# via -r requirements/base.in
Expand Down Expand Up @@ -204,15 +204,15 @@ jsonschema==4.21.1
# via drf-spectacular
jsonschema-specifications==2023.12.1
# via jsonschema
kombu==5.3.5
kombu==5.3.6
# via celery
markupsafe==2.1.5
# via jinja2
monotonic==1.6
# via analytics-python
mysqlclient==2.2.4
# via -r requirements/base.in
newrelic==9.7.1
newrelic==9.8.0
# via edx-django-utils
oauthlib==3.2.2
# via
Expand Down
11 changes: 7 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ billiard==4.2.0
# via
# -r requirements/validation.txt
# celery
build==1.1.1
build==1.2.1
# via
# -r requirements/pip-tools.txt
# pip-tools
Expand Down Expand Up @@ -193,7 +193,7 @@ django-dynamic-fixture==4.0.1
# via -r requirements/validation.txt
django-extensions==3.2.3
# via -r requirements/validation.txt
django-filter==24.1
django-filter==24.2
# via -r requirements/validation.txt
django-log-request-id==2.1.0
# via -r requirements/validation.txt
Expand Down Expand Up @@ -294,6 +294,8 @@ filelock==3.13.3
# -r requirements/validation.txt
# tox
# virtualenv
freezegun==1.4.0
# via -r requirements/validation.txt
idna==3.6
# via
# -r requirements/validation.txt
Expand Down Expand Up @@ -364,7 +366,7 @@ keyring==25.0.0
# via
# -r requirements/validation.txt
# twine
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/validation.txt
# celery
Expand Down Expand Up @@ -397,7 +399,7 @@ more-itertools==10.2.0
# jaraco-functools
mysqlclient==2.2.4
# via -r requirements/validation.txt
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/validation.txt
# edx-django-utils
Expand Down Expand Up @@ -543,6 +545,7 @@ python-dateutil==2.9.0.post0
# analytics-python
# celery
# faker
# freezegun
python-slugify==8.0.4
# via
# -r requirements/validation.txt
Expand Down
9 changes: 6 additions & 3 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ django-dynamic-fixture==4.0.1
# via -r requirements/test.txt
django-extensions==3.2.3
# via -r requirements/test.txt
django-filter==24.1
django-filter==24.2
# via -r requirements/test.txt
django-log-request-id==2.1.0
# via -r requirements/test.txt
Expand Down Expand Up @@ -296,6 +296,8 @@ filelock==3.13.3
# -r requirements/test.txt
# tox
# virtualenv
freezegun==1.4.0
# via -r requirements/test.txt
idna==3.6
# via
# -r requirements/test.txt
Expand Down Expand Up @@ -348,7 +350,7 @@ jsonschema-specifications==2023.12.1
# via
# -r requirements/test.txt
# jsonschema
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/test.txt
# celery
Expand All @@ -366,7 +368,7 @@ monotonic==1.6
# analytics-python
mysqlclient==2.2.4
# via -r requirements/test.txt
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/test.txt
# edx-django-utils
Expand Down Expand Up @@ -494,6 +496,7 @@ python-dateutil==2.9.0.post0
# analytics-python
# celery
# faker
# freezegun
python-slugify==8.0.4
# via
# -r requirements/test.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
build==1.1.1
build==1.2.1
# via pip-tools
click==8.1.7
# via pip-tools
Expand Down
6 changes: 3 additions & 3 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ django-crum==0.7.9
# edx-rbac
django-extensions==3.2.3
# via -r requirements/base.txt
django-filter==24.1
django-filter==24.2
# via -r requirements/base.txt
django-log-request-id==2.1.0
# via -r requirements/base.txt
Expand Down Expand Up @@ -256,7 +256,7 @@ jsonschema-specifications==2023.12.1
# via
# -r requirements/base.txt
# jsonschema
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/base.txt
# celery
Expand All @@ -272,7 +272,7 @@ mysqlclient==2.2.4
# via
# -r requirements/base.txt
# -r requirements/production.in
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/base.txt
# edx-django-utils
Expand Down
9 changes: 6 additions & 3 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ django-dynamic-fixture==4.0.1
# via -r requirements/test.txt
django-extensions==3.2.3
# via -r requirements/test.txt
django-filter==24.1
django-filter==24.2
# via -r requirements/test.txt
django-log-request-id==2.1.0
# via -r requirements/test.txt
Expand Down Expand Up @@ -281,6 +281,8 @@ filelock==3.13.3
# -r requirements/test.txt
# tox
# virtualenv
freezegun==1.4.0
# via -r requirements/test.txt
idna==3.6
# via
# -r requirements/test.txt
Expand Down Expand Up @@ -341,7 +343,7 @@ jsonschema-specifications==2023.12.1
# jsonschema
keyring==25.0.0
# via twine
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/test.txt
# celery
Expand All @@ -367,7 +369,7 @@ more-itertools==10.2.0
# jaraco-functools
mysqlclient==2.2.4
# via -r requirements/test.txt
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/test.txt
# edx-django-utils
Expand Down Expand Up @@ -494,6 +496,7 @@ python-dateutil==2.9.0.post0
# analytics-python
# celery
# faker
# freezegun
python-slugify==8.0.4
# via
# -r requirements/test.txt
Expand Down
1 change: 1 addition & 0 deletions requirements/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ddt
django-dynamic-fixture # library to create dynamic model instances for testing purposes
edx-lint
factory-boy
freezegun
pytest-cov
pytest-django
tox
9 changes: 6 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ django-dynamic-fixture==4.0.1
# via -r requirements/test.in
django-extensions==3.2.3
# via -r requirements/base.txt
django-filter==24.1
django-filter==24.2
# via -r requirements/base.txt
django-log-request-id==2.1.0
# via -r requirements/base.txt
Expand Down Expand Up @@ -258,6 +258,8 @@ filelock==3.13.3
# via
# tox
# virtualenv
freezegun==1.4.0
# via -r requirements/test.in
idna==3.6
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -299,7 +301,7 @@ jsonschema-specifications==2023.12.1
# via
# -r requirements/base.txt
# jsonschema
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/base.txt
# celery
Expand All @@ -315,7 +317,7 @@ monotonic==1.6
# analytics-python
mysqlclient==2.2.4
# via -r requirements/base.txt
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/base.txt
# edx-django-utils
Expand Down Expand Up @@ -420,6 +422,7 @@ python-dateutil==2.9.0.post0
# analytics-python
# celery
# faker
# freezegun
python-slugify==8.0.4
# via code-annotations
python3-openid==3.2.0
Expand Down
11 changes: 8 additions & 3 deletions requirements/validation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ django-extensions==3.2.3
# via
# -r requirements/quality.txt
# -r requirements/test.txt
django-filter==24.1
django-filter==24.2
# via
# -r requirements/quality.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -368,6 +368,10 @@ filelock==3.13.3
# -r requirements/test.txt
# tox
# virtualenv
freezegun==1.4.0
# via
# -r requirements/quality.txt
# -r requirements/test.txt
idna==3.6
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -447,7 +451,7 @@ keyring==25.0.0
# via
# -r requirements/quality.txt
# twine
kombu==5.3.5
kombu==5.3.6
# via
# -r requirements/quality.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -484,7 +488,7 @@ mysqlclient==2.2.4
# via
# -r requirements/quality.txt
# -r requirements/test.txt
newrelic==9.7.1
newrelic==9.8.0
# via
# -r requirements/quality.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -646,6 +650,7 @@ python-dateutil==2.9.0.post0
# analytics-python
# celery
# faker
# freezegun
python-slugify==8.0.4
# via
# -r requirements/quality.txt
Expand Down

0 comments on commit 1946d7b

Please sign in to comment.