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.
5 from datetime import date, timedelta
6 from django.test import TestCase
7 from .models import Offer, Perk
10 class PerksTest(TestCase):
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)
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')
26 set(self.offer1.get_perks(10)),
29 set(self.offer1.get_perks(70)),
33 class FundingTest(TestCase):
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))
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)
56 {self.offer_past, self.offer_current}
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))
65 self.assertTrue(offer_interrupt.is_current())
66 self.assertFalse(self.offer_current.is_current())
67 self.assertEqual(Offer.current(), offer_interrupt)
70 {self.offer_past, self.offer_current}
74 {self.offer_past, self.offer_current, offer_interrupt}