2018-04-10 01:04:24 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-02-17 00:43:22 +08:00
|
|
|
import unittest
|
|
|
|
from mock import Mock
|
|
|
|
from cartodb_services.tomtom import TomTomGeocoder
|
|
|
|
from cartodb_services.tools.exceptions import ServiceException
|
|
|
|
from credentials import tomtom_api_key
|
|
|
|
|
|
|
|
INVALID_APIKEY = 'invalid_apikey'
|
2018-04-10 01:04:24 +08:00
|
|
|
VALID_ADDRESS = u'Mantería 3, Valladolid'.encode('utf-8')
|
2018-02-17 00:43:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TomTomGeocoderTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.geocoder = TomTomGeocoder(apikey=tomtom_api_key(), logger=Mock())
|
|
|
|
|
|
|
|
def test_invalid_token(self):
|
|
|
|
invalid_geocoder = TomTomGeocoder(apikey=INVALID_APIKEY, logger=Mock())
|
|
|
|
with self.assertRaises(ServiceException):
|
|
|
|
invalid_geocoder.geocode(VALID_ADDRESS)
|
|
|
|
|
|
|
|
def test_valid_request(self):
|
|
|
|
place = self.geocoder.geocode(VALID_ADDRESS)
|
|
|
|
|
2018-03-16 21:47:56 +08:00
|
|
|
assert place
|
2018-02-17 00:43:22 +08:00
|
|
|
|
|
|
|
def test_valid_request_namedplace(self):
|
|
|
|
place = self.geocoder.geocode(searchtext='Barcelona')
|
|
|
|
|
|
|
|
assert place
|
|
|
|
|
|
|
|
def test_valid_request_namedplace2(self):
|
|
|
|
place = self.geocoder.geocode(searchtext='New York', country='us')
|
|
|
|
|
|
|
|
assert place
|
|
|
|
|
|
|
|
def test_odd_characters(self):
|
|
|
|
place = self.geocoder.geocode(searchtext='Barcelona; "Spain"')
|
|
|
|
|
|
|
|
assert place
|
|
|
|
|
|
|
|
def test_empty_request(self):
|
|
|
|
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
|
|
|
|
|
|
|
|
assert place == []
|
|
|
|
|
|
|
|
def test_empty_search_text_request(self):
|
|
|
|
place = self.geocoder.geocode(searchtext=' ', country='us', city=None, state_province="")
|
|
|
|
|
|
|
|
assert place == []
|
|
|
|
|
|
|
|
def test_unknown_place_request(self):
|
|
|
|
place = self.geocoder.geocode(searchtext='[unknown]', country='ch', state_province=None, city=None)
|
|
|
|
|
|
|
|
assert place == []
|