1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from datetime import date, timedelta
5 from django.test import TestCase
6 from .models import Offer, Perk
9 class PerksTest(TestCase):
11 self.today = date.today()
12 self.offer1 = Offer.objects.create(
13 author='author1', title='title1', slug='slug1',
14 target=100, start=self.today, end=self.today)
17 perk = Perk.objects.create(price=20, name='Perk 20')
18 perk1 = Perk.objects.create(offer=self.offer1, price=50, name='Perk 50')
19 offer2 = Offer.objects.create(
20 author='author2', title='title2', slug='slug2',
21 target=100, start=self.today-timedelta(1), end=self.today-timedelta(1))
22 perk2 = Perk.objects.create(offer=offer2, price=1, name='Perk 1')
25 set(self.offer1.get_perks(10)),
28 set(self.offer1.get_perks(70)),
32 class FundingTest(TestCase):
34 self.today = date.today()
35 self.offer_past = Offer.objects.create(
36 author='an-author', title='past', slug='past',
37 target=100, start=self.today-timedelta(1), end=self.today-timedelta(1))
38 self.offer_current = Offer.objects.create(
39 author='an-author', title='current', slug='current',
40 target=100, start=self.today, end=self.today)
41 self.offer_future = Offer.objects.create(
42 author='an-author', title='future', slug='future',
43 target=100, start=self.today+timedelta(1), end=self.today+timedelta(1))
45 def test_current(self):
46 self.assertTrue(self.offer_current.is_current())
47 self.assertFalse(self.offer_past.is_current())
48 self.assertEqual(Offer.current(), self.offer_current)
55 {self.offer_past, self.offer_current}
58 def test_interrupt(self):
59 # A new offer starts, ending the previously current one.
60 offer_interrupt = Offer.objects.create(
61 author='an-author', title='interrupt', slug='interrupt',
62 target=100, start=self.today-timedelta(1), end=self.today+timedelta(1))
64 self.assertTrue(offer_interrupt.is_current())
65 self.assertFalse(self.offer_current.is_current())
66 self.assertEqual(Offer.current(), offer_interrupt)
69 {self.offer_past, self.offer_current}
73 {self.offer_past, self.offer_current, offer_interrupt}