Skip to content

Commit

Permalink
fix: send geag terms acceptd at in correct format
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Aug 8, 2024
1 parent 9d7f1ef commit 838c63f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
FORCED_REDEMPTION_CURRENT_TIME_KEY = 'geag_terms_accepted_at'
FORCED_REDEMPTION_DATA_SHARE_CONSENT_KEY = 'geag_data_share_consent'
FORCED_REDEMPTION_EMAIL_KEY = 'geag_email'
GEAG_DATETIME_FMT = '%Y-%m-%dT%H:%M:%SZ'


def super_admin_enabled():
Expand Down Expand Up @@ -454,7 +455,7 @@ def save_model(self, request, obj, form, change):
}
if extra_metadata:
user_record = User.objects.get(lms_user_id=form.cleaned_data.get('lms_user_id'))
extra_metadata[FORCED_REDEMPTION_CURRENT_TIME_KEY] = str(timezone.now())
extra_metadata[FORCED_REDEMPTION_CURRENT_TIME_KEY] = timezone.now().strftime(GEAG_DATETIME_FMT)
extra_metadata[FORCED_REDEMPTION_DATA_SHARE_CONSENT_KEY] = True
extra_metadata[FORCED_REDEMPTION_EMAIL_KEY] = user_record.email
obj.force_redeem(extra_metadata=extra_metadata)
Expand Down
10 changes: 8 additions & 2 deletions enterprise_access/apps/subsidy_access_policy/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Tests for the admin module.
"""
from datetime import date
from datetime import date, datetime
from unittest import mock

from django.contrib.admin.sites import AdminSite
from django.test import TestCase

from ...core.tests.factories import UserFactory
from ..admin import ForcedPolicyRedemptionAdmin, ForcedPolicyRedemptionForm
from ..admin import GEAG_DATETIME_FMT, ForcedPolicyRedemptionAdmin, ForcedPolicyRedemptionForm
from ..models import ForcedPolicyRedemption


Expand Down Expand Up @@ -52,3 +52,9 @@ def test_force_redeem_with_extra_metadata(self):
'geag_email': '[email protected]',
}
)
terms_accepted_value =\
forced_redemption_obj.force_redeem.call_args_list[0][1]['extra_metadata']['geag_terms_accepted_at']
# we don't really care about the value, but
# we want to know that parsing the value matches the datetime
# format accepted by GEAG.
assert datetime.strptime(terms_accepted_value, GEAG_DATETIME_FMT)

0 comments on commit 838c63f

Please sign in to comment.