Fixes encoding

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-04-09 19:04:24 +02:00
parent e21d3e2e70
commit 94aeceb894
2 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,6 @@
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import json import json
import requests import requests
from uritemplate import URITemplate from uritemplate import URITemplate
@ -62,6 +65,15 @@ class TomTomGeocoder(Traceable):
@qps_retry(qps=5) @qps_retry(qps=5)
def geocode(self, searchtext, city=None, state_province=None, def geocode(self, searchtext, city=None, state_province=None,
country=None): country=None):
if searchtext:
searchtext = searchtext.decode('utf-8')
if city:
city = city.decode('utf-8')
if state_province:
state_province = state_province.decode('utf-8')
if country:
country = country.decode('utf-8')
if not self._validate_input(searchtext, city, state_province, country): if not self._validate_input(searchtext, city, state_province, country):
return [] return []

View File

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
import unittest import unittest
from mock import Mock from mock import Mock
from cartodb_services.tomtom import TomTomGeocoder from cartodb_services.tomtom import TomTomGeocoder
@ -5,7 +7,7 @@ from cartodb_services.tools.exceptions import ServiceException
from credentials import tomtom_api_key from credentials import tomtom_api_key
INVALID_APIKEY = 'invalid_apikey' INVALID_APIKEY = 'invalid_apikey'
VALID_ADDRESS = 'Plaza Mayor 3, Valladolid' VALID_ADDRESS = u'Mantería 3, Valladolid'.encode('utf-8')
class TomTomGeocoderTestCase(unittest.TestCase): class TomTomGeocoderTestCase(unittest.TestCase):