forked from move-coop/parsons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_census_geocoder.py
More file actions
71 lines (56 loc) · 2.85 KB
/
test_census_geocoder.py
File metadata and controls
71 lines (56 loc) · 2.85 KB
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
import unittest
from unittest import mock
import petl
from parsons import CensusGeocoder, Table
from test.utils import assert_matching_tables, mark_live_test
from .test_responses import batch_resp, coord_resp, geographies_resp, locations_resp
@mark_live_test
class TestCensusGeocoder(unittest.TestCase):
def setUp(self):
self.cg = CensusGeocoder()
def test_geocode_onelineaddress(self):
self.cg.cg = mock.MagicMock()
address = "1600 Pennsylvania Avenue, Washington, DC"
# Assert one line with geographies parameter returns expected
self.cg.cg.onelineaddress = mock.MagicMock(return_value=geographies_resp)
geo = self.cg.geocode_onelineaddress(address, return_type="geographies")
self.cg.cg.onelineaddress.assert_called_with(address, returntype="geographies")
assert geo == geographies_resp
# Assert one line with locations parameter returns expected
self.cg.cg.onelineaddress = mock.MagicMock(return_value=locations_resp)
geo = self.cg.geocode_onelineaddress(address, return_type="locations")
self.cg.cg.onelineaddress.assert_called_with(address, returntype="locations")
assert geo == locations_resp
def test_geocode_address(self):
self.cg.cg = mock.MagicMock()
passed_address = {
"address_line": "1600 Pennsylvania Avenue",
"city": "Washington",
"state": "DC",
}
# Assert one line with geographies parameter returns expected
self.cg.cg.address = mock.MagicMock(return_value=geographies_resp)
geo = self.cg.geocode_address(**passed_address, return_type="geographies")
assert geo == geographies_resp
# Assert one line with locations parameter returns expected
self.cg.cg.address = mock.MagicMock(return_value=locations_resp)
geo = self.cg.geocode_address(**passed_address, return_type="locations")
assert geo == locations_resp
def test_geocode_address_batch(self):
batch = [
["id", "street", "city", "state", "zip"],
["1", "908 N Washtenaw", "Chicago", "IL", "60622"],
["2", "1405 Wilshire Blvd", "Austin", "TX", "78722"],
["3", "908 N Washtenaw", "Chicago", "IL", "60622"],
["4", "1405 Wilshire Blvd", "Austin", "TX", "78722"],
["5", "908 N Washtenaw", "Chicago", "IL", "60622"],
]
tbl = Table(batch)
self.cg.cg.addressbatch = mock.MagicMock(return_value=batch_resp)
geo = self.cg.geocode_address_batch(tbl)
assert_matching_tables(geo, Table(petl.fromdicts(batch_resp)))
def test_coordinates(self):
# Assert coordinates data returns expected response.
self.cg.cg.address = mock.MagicMock(return_value=coord_resp)
geo = self.cg.get_coordinates_data("38.8884212", "-77.0441907")
assert geo == coord_resp