2017-12-27 20:43:14 +08:00
|
|
|
import unittest
|
2017-12-28 18:36:02 +08:00
|
|
|
from mock import Mock
|
2017-12-27 20:43:14 +08:00
|
|
|
from cartodb_services.mapbox import MapboxMatrixClient
|
|
|
|
from cartodb_services.mapbox.matrix_client import DEFAULT_PROFILE
|
2018-01-04 22:00:52 +08:00
|
|
|
from cartodb_services.tools.exceptions import ServiceException
|
2017-12-27 20:43:14 +08:00
|
|
|
from cartodb_services.tools import Coordinate
|
2018-02-14 01:23:36 +08:00
|
|
|
from credentials import mapbox_api_key
|
2017-12-27 20:43:14 +08:00
|
|
|
|
|
|
|
INVALID_TOKEN = 'invalid_token'
|
|
|
|
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
|
|
|
VALID_TARGET = Coordinate(-74, 40.733)
|
|
|
|
VALID_COORDINATES = [VALID_ORIGIN] + [VALID_TARGET]
|
|
|
|
NUM_COORDINATES_MAX = 25
|
|
|
|
INVALID_COORDINATES_EMPTY = []
|
|
|
|
INVALID_COORDINATES_MIN = [VALID_ORIGIN]
|
|
|
|
INVALID_COORDINATES_MAX = [VALID_ORIGIN] + \
|
|
|
|
[VALID_TARGET
|
|
|
|
for x in range(0, NUM_COORDINATES_MAX + 1)]
|
|
|
|
VALID_PROFILE = DEFAULT_PROFILE
|
|
|
|
INVALID_PROFILE = 'invalid_profile'
|
|
|
|
|
|
|
|
|
2018-08-14 15:39:42 +08:00
|
|
|
@unittest.skip("Stop using Matrix API. CartoDB/cartodb-management/issues/5199")
|
2017-12-27 20:43:14 +08:00
|
|
|
class MapboxMatrixTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2018-02-14 01:23:36 +08:00
|
|
|
self.matrix_client = MapboxMatrixClient(token=mapbox_api_key(),
|
2017-12-28 18:36:02 +08:00
|
|
|
logger=Mock())
|
2017-12-27 20:43:14 +08:00
|
|
|
|
|
|
|
def test_invalid_profile(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
self.matrix_client.matrix(VALID_COORDINATES,
|
|
|
|
INVALID_PROFILE)
|
|
|
|
|
|
|
|
def test_invalid_coordinates_empty(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
self.matrix_client.matrix(INVALID_COORDINATES_EMPTY,
|
|
|
|
VALID_PROFILE)
|
|
|
|
|
|
|
|
def test_invalid_coordinates_max(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
self.matrix_client.matrix(INVALID_COORDINATES_MAX,
|
|
|
|
VALID_PROFILE)
|
|
|
|
|
|
|
|
def test_invalid_coordinates_min(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
self.matrix_client.matrix(INVALID_COORDINATES_MIN,
|
|
|
|
VALID_PROFILE)
|
|
|
|
|
|
|
|
def test_invalid_token(self):
|
2017-12-28 18:36:02 +08:00
|
|
|
invalid_matrix = MapboxMatrixClient(token=INVALID_TOKEN, logger=Mock())
|
2017-12-27 20:43:14 +08:00
|
|
|
with self.assertRaises(ServiceException):
|
|
|
|
invalid_matrix.matrix(VALID_COORDINATES,
|
|
|
|
VALID_PROFILE)
|
|
|
|
|
|
|
|
def test_valid_request(self):
|
|
|
|
distance_matrix = self.matrix_client.matrix(VALID_COORDINATES,
|
|
|
|
VALID_PROFILE)
|
|
|
|
assert distance_matrix
|