funding top bar without ssi
[wolnelektury.git] / src / funding / tests.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from datetime import date, timedelta
6 from django.test import TestCase
7 from .models import Offer, Perk
8
9
10 class PerksTest(TestCase):
11     def setUp(self):
12         self.today = date.today()
13         self.offer1 = Offer.objects.create(
14             author='author1', title='title1', slug='slug1',
15             target=100, start=self.today, end=self.today)
16
17     def test_perks(self):
18         perk = Perk.objects.create(price=20, name='Perk 20')
19         perk1 = Perk.objects.create(offer=self.offer1, price=50, name='Perk 50')
20         offer2 = Offer.objects.create(
21             author='author2', title='title2', slug='slug2',
22             target=100, start=self.today-timedelta(1), end=self.today-timedelta(1))
23         perk2 = Perk.objects.create(offer=offer2, price=1, name='Perk 1')
24
25         self.assertEqual(
26             set(self.offer1.get_perks(10)),
27             set())
28         self.assertEqual(
29             set(self.offer1.get_perks(70)),
30             {perk, perk1})
31
32
33 class FundingTest(TestCase):
34     def setUp(self):
35         self.today = date.today()
36         self.offer_past = Offer.objects.create(
37             author='an-author', title='past', slug='past',
38             target=100, start=self.today-timedelta(1), end=self.today-timedelta(1))
39         self.offer_current = Offer.objects.create(
40             author='an-author', title='current', slug='current',
41             target=100, start=self.today, end=self.today)
42         self.offer_future = Offer.objects.create(
43             author='an-author', title='future', slug='future',
44             target=100, start=self.today+timedelta(1), end=self.today+timedelta(1))
45
46     def test_current(self):
47         self.assertTrue(self.offer_current.is_current())
48         self.assertFalse(self.offer_past.is_current())
49         self.assertEqual(Offer.current(), self.offer_current)
50         self.assertEqual(
51             set(Offer.past()),
52             {self.offer_past}
53         )
54         self.assertEqual(
55             set(Offer.public()),
56             {self.offer_past, self.offer_current}
57         )
58
59     def test_interrupt(self):
60         # A new offer starts, ending the previously current one.
61         offer_interrupt = Offer.objects.create(
62             author='an-author', title='interrupt', slug='interrupt',
63             target=100, start=self.today-timedelta(1), end=self.today+timedelta(1))
64
65         self.assertTrue(offer_interrupt.is_current())
66         self.assertFalse(self.offer_current.is_current())
67         self.assertEqual(Offer.current(), offer_interrupt)
68         self.assertEqual(
69             set(Offer.past()),
70             {self.offer_past, self.offer_current}
71         )
72         self.assertEqual(
73             set(Offer.public()),
74             {self.offer_past, self.offer_current, offer_interrupt}
75         )