|
|
@@ -13,35 +13,40 @@ START_DATE = datetime.date(2011, 01, 01)
|
|
13
|
13
|
END_DATE = datetime.date(2012, 01, 01)
|
|
14
|
14
|
|
|
15
|
15
|
|
|
16
|
|
-class TestVoucher(TestCase):
|
|
|
16
|
+class TestSavingAVoucher(TestCase):
|
|
17
|
17
|
|
|
18
|
18
|
def test_saves_code_as_uppercase(self):
|
|
19
|
|
- voucher = Voucher.objects.create(code='lower',
|
|
20
|
|
- start_date=START_DATE,
|
|
21
|
|
- end_date=END_DATE)
|
|
|
19
|
+ voucher = Voucher(code='lower', start_date=START_DATE,
|
|
|
20
|
+ end_date=END_DATE)
|
|
|
21
|
+ voucher.save()
|
|
22
|
22
|
self.assertEqual('LOWER', voucher.code)
|
|
23
|
23
|
|
|
24
|
|
- def test_checks_dates_are_sensible(self):
|
|
|
24
|
+ def test_verifies_dates_are_sensible(self):
|
|
25
|
25
|
with self.assertRaises(exceptions.ValidationError):
|
|
26
|
26
|
voucher = Voucher.objects.create(code='lower',
|
|
27
|
27
|
start_date=END_DATE,
|
|
28
|
28
|
end_date=START_DATE)
|
|
29
|
29
|
voucher.clean()
|
|
30
|
30
|
|
|
|
31
|
+
|
|
|
32
|
+class TestAVoucher(TestCase):
|
|
|
33
|
+
|
|
|
34
|
+ def setUp(self):
|
|
|
35
|
+ self.voucher = Voucher(start_date=START_DATE, end_date=END_DATE)
|
|
|
36
|
+
|
|
31
|
37
|
def test_is_active_between_start_and_end_dates(self):
|
|
32
|
|
- test = datetime.date(2011, 01, 10)
|
|
33
|
|
- voucher = Voucher(start_date=START_DATE, end_date=END_DATE)
|
|
34
|
|
- self.assertTrue(voucher.is_active(test))
|
|
|
38
|
+ test = datetime.date(2011, 06, 10)
|
|
|
39
|
+ self.assertTrue(self.voucher.is_active(test))
|
|
35
|
40
|
|
|
36
|
41
|
def test_is_active_on_end_date(self):
|
|
37
|
|
- test = END_DATE
|
|
38
|
|
- voucher = Voucher(start_date=START_DATE, end_date=END_DATE)
|
|
39
|
|
- self.assertTrue(voucher.is_active(test))
|
|
|
42
|
+ self.assertTrue(self.voucher.is_active(END_DATE))
|
|
|
43
|
+
|
|
|
44
|
+ def test_is_active_on_start_date(self):
|
|
|
45
|
+ self.assertTrue(self.voucher.is_active(START_DATE))
|
|
40
|
46
|
|
|
41
|
47
|
def test_is_inactive_outside_of_start_and_end_dates(self):
|
|
42
|
48
|
test = datetime.date(2012, 03, 10)
|
|
43
|
|
- voucher = Voucher(start_date=START_DATE, end_date=END_DATE)
|
|
44
|
|
- self.assertFalse(voucher.is_active(test))
|
|
|
49
|
+ self.assertFalse(self.voucher.is_active(test))
|
|
45
|
50
|
|
|
46
|
51
|
def test_increments_total_discount_when_recording_usage(self):
|
|
47
|
52
|
voucher = G(Voucher)
|