Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce membership code on instructor training application #2544

11 changes: 5 additions & 6 deletions amy/extforms/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import date, timedelta
from typing import Iterable, cast

from captcha.fields import ReCaptchaField
Expand Down Expand Up @@ -215,11 +215,10 @@ def validate_member_code(self, request: HttpRequest) -> dict:
# find relevant membership - may raise Membership.DoesNotExist
membership = Membership.objects.get(registration_code=member_code)
# confirm that membership is currently active
if (
not membership.agreement_start
<= date.today()
<= membership.agreement_end
):
# grace period: 90 days before and after
valid_start = membership.agreement_start - timedelta(days=90)
valid_end = membership.agreement_end + timedelta(days=90)
if not valid_start <= date.today() <= valid_end:
elichad marked this conversation as resolved.
Show resolved Hide resolved
errors["member_code"] = ValidationError(error_msg)
except Membership.DoesNotExist:
errors["member_code"] = ValidationError(error_msg)
Expand Down
8 changes: 4 additions & 4 deletions amy/extforms/tests/test_training_request_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def test_member_code_validation__code_invalid(self):

@override_settings(FLAGS={"ENFORCE_MEMBER_CODES": [("boolean", True)]})
def test_member_code_validation__code_inactive_early(self):
# 3: code before membership start date - error on code
# 3: code used >90 days before membership start date - error on code
# Arrange
self.setUpMembership()
self.membership.agreement_start = date.today() + timedelta(days=1)
self.membership.agreement_start = date.today() + timedelta(days=91)
self.membership.save()
data = {
"review_process": "preapproved",
Expand All @@ -206,10 +206,10 @@ def test_member_code_validation__code_inactive_early(self):

@override_settings(FLAGS={"ENFORCE_MEMBER_CODES": [("boolean", True)]})
def test_member_code_validation__code_inactive_late(self):
# 4: code after membership end date - error on code
# 4: code used >90 days after membership end date - error on code
# Arrange
self.setUpMembership()
self.membership.agreement_end = date.today() - timedelta(days=1)
self.membership.agreement_end = date.today() - timedelta(days=91)
self.membership.save()
data = {
"review_process": "preapproved",
Expand Down