forked from freelawproject/reporters-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
56 lines (52 loc) · 2.4 KB
/
tests.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
from reporters_db import REPORTERS, VARIATIONS_ONLY, EDITIONS
from unittest import TestCase
import datetime
class ConstantsTest(TestCase):
def test_any_keys_missing_editions(self):
"""Have we added any new reporters that lack a matching edition?"""
for r_name, r_items in REPORTERS.items():
# For each reporter
for item in r_items:
# and each book in each reporter
self.assertIn(
r_name, item['editions'],
msg="Could not find edition for key: %s" % r_name
)
def test_for_variations_mapping_to_bad_keys(self):
"""Do we have a variation that maps to a key that doesn't exist in the
first place?
"""
for variations in VARIATIONS_ONLY.values():
for variation in variations:
self.assertIn(
EDITIONS[variation], REPORTERS.keys(),
msg="Could not map variation to a valid reporter: %s" %
variation
)
def test_that_all_dates_are_converted_to_dates_not_strings(self):
"""Do we properly make the ISO-8601 date strings into Python dates?"""
for reporter_name, reporter_list in REPORTERS.iteritems():
# reporter_name == "A."
# reporter_list == [
# {'name': 'Atlantic Reporter', 'editions': ...},
# {'name': 'Aldo's Reporter', 'editions': ...}
# ]
for reporter_dict in reporter_list:
# reporter_dict == {'name': 'Atlantic Reporter'}
for e_name, e_dates in reporter_dict['editions'].iteritems():
# e_name == "A. 2d"
# e_dates == {
# "end": "1938-12-31T00:00:00",
# "start": "1885-01-01T00:00:00"
# }
for key in ['start', 'end']:
is_date_or_none = (
isinstance(e_dates[key], datetime.datetime) or
e_dates[key] is None
)
self.assertTrue(
is_date_or_none,
msg=("%s dates in the reporter '%s' appear to be "
"coming through as '%s'" %
(key, e_name, type(e_dates[key])))
)