upgrade
[wolnelektury.git] / src / messaging / tests.py
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
6 from . import states
7
8 #    Cold,
9 #    ClubTried,
10 #    ClubSingle,
11 #    ClubSingleExpired,
12 #    ClubRecurring,
13 #    ClubRecurringExpired,
14 ###  ClubRecurringCancelled
15
16
17 class MessagingTests(TestCase):
18     def test_tried(self):
19         # user1 has one unsuccessful try.
20         Schedule.objects.create(email='user1@example.com', amount=1)
21         
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)),
28         )
29
30         state = states.ClubTried()
31         self.assertEqual(
32             [c.email for c in state.get_contacts()],
33             ['user1@example.com']
34         )
35
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)),
42         )
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)),
47             monthly=True
48         )
49         self.assertEqual(
50             [c.email for c in states.ClubSingle().get_contacts()],
51             []
52         )
53         self.assertEqual(
54             [c.email for c in states.ClubRecurring().get_contacts()],
55             ['user1@example.com']
56         )
57
58     def test_recurring_expired(self):
59         # User1 has expiring
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)),
64             monthly=True
65         )
66
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)),
71             monthly=True,
72             is_cancelled=True,
73         )
74
75         self.assertEqual(
76             [c.email for c in states.ClubRecurringExpired().get_contacts()],
77             ['user1@example.com', 'user2@example.com']
78         )
79
80 # Start -> 
81
82
83         
84 # Has recurring-cancelled AND single