-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_flowers.py
90 lines (69 loc) · 3.5 KB
/
test_flowers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# This is the tests for the flower program!!
import datetime
import json
import os
import unittest
import flowers
class FlowerFileTest(unittest.TestCase):
def test_load_or_create_flowermap_present(self):
expected = {"flowerday": 20, "current_month": 6, "email_sent": True}
with open(flowers.FLOWERDATE_FILE, 'w') as f:
f.write(json.dumps(expected))
flowermap = flowers.load_or_create_flowermap()
self.assertEquals(flowermap, expected)
os.remove(flowers.FLOWERDATE_FILE)
def test_load_or_create_flowermap_absent(self):
if os.path.isfile(flowers.FLOWERDATE_FILE):
os.remove(flowers.FLOWERDATE_FILE)
expected = {'flowerday': None, 'current_month': None, 'email_sent': False}
flowermap = flowers.load_or_create_flowermap()
self.assertEquals(flowermap, expected)
with open(flowers.FLOWERDATE_FILE, 'r') as f:
flowermap = json.loads(f.read())
self.assertEquals(flowermap, expected)
class EmailerTest(unittest.TestCase):
def assert_check_emailer(self, todays_date, flowermap, expected):
email_status = flowers.check_date_for_emailer(flowermap, todays_date)
self.assertEquals(email_status, expected)
def test_check_emailer1(self):
todays_date = datetime.date(2013, 6, 24)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": True}
self.assert_check_emailer(todays_date, flowermap, False)
def test_check_emailer2(self):
todays_date = datetime.date(2013, 6, 13)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": False}
self.assert_check_emailer(todays_date, flowermap, False)
def test_check_emailer3(self):
todays_date = datetime.date(2013, 6, 13)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": False}
self.assert_check_emailer(todays_date, flowermap, False)
def test_check_emailer4(self):
todays_date = datetime.date(2013, 6, 23)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": False}
self.assert_check_emailer(todays_date, flowermap, True)
def test_check_emailer5(self):
todays_date = datetime.date(2013, 5, 23)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": True}
self.assert_check_emailer(todays_date, flowermap, False)
def test_check_emailer6(self):
todays_date = datetime.date(2013, 5, 23)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": False}
self.assert_check_emailer(todays_date, flowermap, False)
class DateGeneratorTest(unittest.TestCase):
def assert_date(self, flowermap, expected, todays_date):
generated_flowermap = flowers.generate_date(flowermap, todays_date)[1]
self.assertEquals(generated_flowermap, expected)
def test_check_generator1(self):
todays_date = datetime.date(2013, 6, 23)
flowermap = {"flowerday": 23, "current_month": 6, "email_sent": False}
self.assert_date(flowermap, False, todays_date)
def test_check_generator2(self):
todays_date = datetime.date(2013, 6, 23)
flowermap = {"flowerday": 24, "current_month": 6, "email_sent": True}
self.assert_date(flowermap, False, todays_date)
def test_check_generator3(self):
todays_date = datetime.date(2013, 6, 23)
flowermap = {"flowerday": 23, "current_month": 5, "email_sent": False}
self.assert_date(flowermap, True, todays_date)
if __name__ == '__main__':
unittest.main()