Skip to content

Commit

Permalink
Merge pull request #997 from CodingPirates/revert-996-975-invite-chec…
Browse files Browse the repository at this point in the history
…k-age-todays-date

Revert "[#975] Check for alder på dags dato om person kan inviteres til aktivitet"
  • Loading branch information
lakridserne authored Jan 14, 2024
2 parents 7c0fc08 + add52aa commit 2047a7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
19 changes: 13 additions & 6 deletions members/admin/admin_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from dateutil.relativedelta import relativedelta
from django import forms
from django.contrib import admin
from django.contrib import messages
Expand Down Expand Up @@ -151,8 +152,6 @@ class MassInvitationForm(forms.Form):
with transaction.atomic():
# for current_person in queryset:
for current_person in persons:
person_age = current_person.age_years()

# check for already participant
if current_person.id in already_participant_ids:
persons_already_participant.append(
Expand All @@ -166,13 +165,21 @@ class MassInvitationForm(forms.Form):
)

# Check for age constraint: too young ?
elif person_age < activity.min_age:
elif (
current_person.birthday
> activity.start_date
- relativedelta(years=activity.min_age)
):
persons_too_young.append(current_person.name)

# Check for age constraint: too old ?
elif person_age > activity.max_age:
elif (
current_person.birthday
< activity.start_date
- relativedelta(
years=activity.max_age + 1, days=-1
)
):
persons_too_old.append(current_person.name)

# Otherwise - person can be invited
else:
invited_counter = invited_counter + 1
Expand Down
55 changes: 20 additions & 35 deletions members/tests/test_admin_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,31 @@ def setUp(self):
self.family = Family()
self.family.save()

# create test persons with specific ages
self.person_too_young = self.create_person_and_waiting_list_entry(age=5)
self.person_exactly_start_age = self.create_person_and_waiting_list_entry(age=7)
self.person_correct_age = self.create_person_and_waiting_list_entry(age=10)
self.person_exactly_end_age = self.create_person_and_waiting_list_entry(age=17)
self.person_too_old = self.create_person_and_waiting_list_entry(age=18)

self.person_too_young_at_activity_start = (
self.create_person_and_waiting_list_entry(
birthday=str(datetime.now().year - 7) + "-01-02"
)
)
self.person_too_young = self.create_person_and_waiting_list_entry(
str(datetime.now().year - 5) + "-01-01"
) # 5 years old
self.person_exactly_start_age = self.create_person_and_waiting_list_entry(
str(datetime.now().year - 7) + "-01-01"
) # 7 years old
self.person_correct_age = self.create_person_and_waiting_list_entry(
str(datetime.now().year - 10) + "-01-01"
) # 10 years old
self.person_exactly_end_age = self.create_person_and_waiting_list_entry(
str(datetime.now().year - 17) + "-01-01"
) # 17 years old
self.person_too_old = self.create_person_and_waiting_list_entry(
str(datetime.now().year - 18) + "-01-01"
) # 18 years old

# setup email template
EmailTemplate.objects.create(
idname="ACT_INVITE",
subject="test email subject",
)

def create_person_and_waiting_list_entry(self, age=None, birthday=None):
if age is not None:
person_birthday = str(datetime.now().year - age) + "-01-01"
person_name = f"Testperson {age} år, født {person_birthday}"
elif birthday is not None:
person_birthday = birthday
person_name = f"Testperson født {person_birthday} år"
else:
raise ValueError("Either age or birthday must be specified")

def create_person_and_waiting_list_entry(self, person_birthday):
person = Person.objects.create(
name=person_name,
name=person_birthday,
family=self.family,
birthday=datetime.fromisoformat(person_birthday),
)
Expand All @@ -99,7 +93,7 @@ def create_mock_request_object(self):
request.POST = {
"activity": "1",
"department": "1",
"expire": datetime.fromisoformat(f"{datetime.now().year}-12-31"),
"expire": datetime.fromisoformat("2023-12-31"),
"email_text": "Lidt ekstra tekst",
}
request.user = self.user
Expand All @@ -116,12 +110,8 @@ def test_invite_many_to_activity_action_correct_persons_are_invited(self):
# Assert that the correct persons are invited
invitations = ActivityInvite.objects.all()

self.assertEqual(invitations.count(), 4)
self.assertTrue(
invitations.filter(
person=self.person_correct_age, activity=self.activity
).exists()
)
self.assertEqual(invitations.count(), 3)
self.assertTrue(invitations.filter(person=self.person_correct_age).exists())
self.assertTrue(
invitations.filter(
person=self.person_exactly_start_age, activity=self.activity
Expand All @@ -132,8 +122,3 @@ def test_invite_many_to_activity_action_correct_persons_are_invited(self):
person=self.person_exactly_end_age, activity=self.activity
).exists()
)
self.assertTrue(
invitations.filter(
person=self.person_too_young_at_activity_start, activity=self.activity
).exists()
)

0 comments on commit 2047a7a

Please sign in to comment.