1 from datetime import datetime
2 from django.test import TestCase
3 from django.utils.timezone import make_aware
4 from club.models import Schedule
5 from .models import Contact
13 # ClubRecurringExpired,
14 ### ClubRecurringCancelled
17 class MessagingTests(TestCase):
19 # user1 has one unsuccessful try.
20 Schedule.objects.create(email='user1@example.com', amount=1)
22 # user2 has one unsuccessful and one successful try
23 Schedule.objects.create(email='user2@example.com', amount=1)
24 Schedule.objects.create(
25 email='user2@example.com', amount=1,
26 payed_at=make_aware(datetime(2020, 1, 1)),
27 expires_at=make_aware(datetime(2030, 2, 1)),
30 state = states.ClubTried()
32 [c.email for c in state.get_contacts()],
36 def test_single_and_recurring(self):
37 # This user has both single and recurring payments.
38 Schedule.objects.create(
39 email='user1@example.com', amount=1,
40 payed_at=make_aware(datetime(2020, 1, 1)),
41 expires_at=make_aware(datetime(2030, 2, 1)),
43 Schedule.objects.create(
44 email='user1@example.com', amount=1,
45 payed_at=make_aware(datetime(2020, 1, 1)),
46 expires_at=make_aware(datetime(2030, 2, 1)),
50 [c.email for c in states.ClubSingle().get_contacts()],
54 [c.email for c in states.ClubRecurring().get_contacts()],
58 def test_recurring_expired(self):
60 Schedule.objects.create(
61 email='user1@example.com', amount=1,
62 payed_at=make_aware(datetime(2020, 1, 1)),
63 expires_at=make_aware(datetime(2020, 2, 1)),
67 Schedule.objects.create(
68 email='user2@example.com', amount=1,
69 payed_at=make_aware(datetime(2020, 1, 1)),
70 expires_at=make_aware(datetime(2020, 2, 1)),
76 [c.email for c in states.ClubRecurringExpired().get_contacts()],
77 ['user1@example.com', 'user2@example.com']
84 # Has recurring-cancelled AND single