Fixed tests for the heremaps geocoder

This commit is contained in:
Mario de Frutos
2016-02-10 15:24:25 +01:00
parent 3b0f92d5e7
commit 13cfee2d4c
@@ -23,68 +23,81 @@ class HereMapsGeocoderTestCase(unittest.TestCase):
} }
}""" }"""
GOOD_RESPONSE = """{ GOOD_RESPONSE = unicode("""{
"Response": { "Response": {
"MetaInfo": { "MetaInfo": {
"Timestamp": "2015-11-04T16:30:32.187+0000" "Timestamp": "2016-02-10T14:17:33.792+0000",
"NextPageInformation": "2"
}, },
"View": [{ "View": [
{
"_type": "SearchResultsViewType", "_type": "SearchResultsViewType",
"ViewId": 0, "ViewId": 0,
"Result": { "Result": [
"Relevance": 0.89, {
"MatchLevel": "street", "Relevance": 1,
"MatchLevel": "houseNumber",
"MatchQuality": { "MatchQuality": {
"City": 1.0, "Street": [
"Street": [1.0] 1
],
"HouseNumber": 1
}, },
"MatchType": "pointAddress",
"Location": { "Location": {
"LocationId": "NT_yyKB4r3mCWAX4voWgxPcuA", "LocationId": "NT_CKopMSB9JnBYAO11CMOrxB_zUD",
"LocationType": "address", "LocationType": "address",
"DisplayPosition": { "DisplayPosition": {
"Latitude": 40.43433, "Latitude": 37.70246,
"Longitude": -3.70126 "Longitude": -5.2794
}, },
"NavigationPosition": [{ "NavigationPosition": [
"Latitude": 40.43433, {
"Longitude": -3.70126 "Latitude": 37.7024199,
}], "Longitude": -5.27939
}
],
"MapView": { "MapView": {
"TopLeft": { "TopLeft": {
"Latitude": 40.43493, "Latitude": 37.7035842,
"Longitude": -3.70404 "Longitude": -5.2808208
}, },
"BottomRight": { "BottomRight": {
"Latitude": 40.43373, "Latitude": 37.7013358,
"Longitude": -3.69873 "Longitude": -5.2779792
} }
}, },
"Address": { "Address": {
"Label": "Calle de Eloy Gonzalo, Madrid, Espana", "Label": "Calle Amor de Dios, 35, 14700 Palma del Río (Córdoba), España",
"Country": "ESP", "Country": "ESP",
"State": "Comunidad de Madrid", "State": "Andalucía",
"County": "Madrid", "County": "Córdoba",
"City": "Madrid", "City": "Palma del Río",
"District": "Trafalgar", "Street": "Calle Amor de Dios",
"Street": "Calle de Eloy Gonzalo", "HouseNumber": "35",
"AdditionalData": [{ "PostalCode": "14700",
"value": "Espana", "AdditionalData": [
{
"value": "España",
"key": "CountryName" "key": "CountryName"
}, },
{ {
"value": "Comunidad de Madrid", "value": "Andalucía",
"key": "StateName" "key": "StateName"
}, },
{ {
"value": "Madrid", "value": "Córdoba",
"key": "CountyName" "key": "CountyName"
}] }
]
} }
} }
} }
}] ]
} }
}""" ]
}
}""", 'utf-8')
MALFORMED_RESPONSE = """{"manolo": "escobar"}""" MALFORMED_RESPONSE = """{"manolo": "escobar"}"""
@@ -95,12 +108,12 @@ class HereMapsGeocoderTestCase(unittest.TestCase):
req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL, req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL,
text=self.GOOD_RESPONSE) text=self.GOOD_RESPONSE)
response = self.geocoder.geocode( response = self.geocoder.geocode(
searchtext='Calle Eloy Gonzalo 27', searchtext='Calle amor de dios',
city='Madrid', city='Cordoba',
country='España') country='España')
self.assertEqual(response[0], -3.70126) self.assertEqual(response[0], -5.2794)
self.assertEqual(response[1], 40.43433) self.assertEqual(response[1], 37.70246)
def test_geocode_address_with_invalid_params(self, req_mock): def test_geocode_address_with_invalid_params(self, req_mock):
req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL, req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL,
@@ -127,6 +140,6 @@ class HereMapsGeocoderTestCase(unittest.TestCase):
text=self.MALFORMED_RESPONSE) text=self.MALFORMED_RESPONSE)
with self.assertRaises(MalformedResult): with self.assertRaises(MalformedResult):
self.geocoder.geocode( self.geocoder.geocode(
searchtext='Calle Eloy Gonzalo 27', searchtext='Calle amor de dios',
city='Madrid', city='Cordoba',
country='España') country='España')