-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2553 from carpentries/feature/2533-Member-codes-A…
…dd-further-checks-for-invalid-code-to-all-workshop-request-forms Add further checks for invalid code to workshop request forms
- Loading branch information
Showing
16 changed files
with
346 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import date | ||
|
||
from django import template | ||
|
||
from workshops.models import Membership | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.simple_tag | ||
def membership_alert_type(membership: Membership) -> str: | ||
workshops_remaining = membership.workshops_without_admin_fee_remaining | ||
active = membership.active_on_date(date.today()) | ||
if workshops_remaining <= 0 or not active: | ||
return "warning" | ||
else: | ||
return "info" | ||
|
||
|
||
@register.simple_tag | ||
def membership_active(membership: Membership) -> bool: | ||
return membership.active_on_date(date.today()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from datetime import date, timedelta | ||
|
||
from django.test import TestCase | ||
|
||
from amy.extrequests.templatetags.request_membership import ( | ||
membership_active, | ||
membership_alert_type, | ||
) | ||
from workshops.models import Membership | ||
|
||
|
||
class TestMembershipAlertType(TestCase): | ||
def setUp(self): | ||
self.membership = Membership.objects.create( | ||
name="Alpha Organization", | ||
variant="bronze", | ||
agreement_start=date.today() - timedelta(weeks=26), | ||
agreement_end=date.today() + timedelta(weeks=26), | ||
contribution_type="financial", | ||
registration_code="valid123", | ||
workshops_without_admin_fee_per_agreement=2, | ||
) | ||
|
||
def test_active_and_has_workshops(self): | ||
# Arrange | ||
expected = "info" | ||
|
||
# Act | ||
result = membership_alert_type(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) | ||
|
||
def test_active_and_no_workshops(self): | ||
# Arrange | ||
self.membership.workshops_without_admin_fee_per_agreement = 0 | ||
expected = "warning" | ||
|
||
# Act | ||
result = membership_alert_type(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) | ||
|
||
def test_inactive_and_no_workshops(self): | ||
# Arrange | ||
self.membership.workshops_without_admin_fee_per_agreement = 0 | ||
self.membership.agreement_end = date.today() - timedelta(days=1) | ||
expected = "warning" | ||
|
||
# Act | ||
result = membership_alert_type(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) | ||
|
||
def test_inactive_and_has_workshops(self): | ||
# Arrange | ||
self.membership.agreement_end = date.today() - timedelta(days=1) | ||
expected = "warning" | ||
|
||
# Act | ||
result = membership_alert_type(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) | ||
|
||
|
||
class TestMembershipActive(TestCase): | ||
def setUp(self): | ||
self.membership = Membership.objects.create( | ||
name="Alpha Organization", | ||
variant="bronze", | ||
agreement_start=date.today() - timedelta(weeks=26), | ||
agreement_end=date.today() + timedelta(weeks=26), | ||
contribution_type="financial", | ||
registration_code="valid123", | ||
workshops_without_admin_fee_per_agreement=2, | ||
) | ||
|
||
def test_active(self): | ||
# Arrange | ||
expected = True | ||
|
||
# Act | ||
result = membership_active(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) | ||
|
||
def test_inactive(self): | ||
# Arrange | ||
self.membership.agreement_end = date.today() - timedelta(days=1) | ||
expected = False | ||
|
||
# Act | ||
result = membership_active(self.membership) | ||
|
||
# Assert | ||
self.assertEqual(expected, result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.