2017-12-27 20:43:14 +08:00
|
|
|
import unittest
|
2017-12-28 18:36:02 +08:00
|
|
|
from mock import Mock
|
2020-02-11 17:00:27 +08:00
|
|
|
from cartodb_services.mapbox.isolines import MapboxIsolines, DEFAULT_PROFILE
|
2017-12-27 20:43:14 +08:00
|
|
|
from cartodb_services.tools import Coordinate
|
2020-02-11 17:00:27 +08:00
|
|
|
|
2018-02-14 01:23:36 +08:00
|
|
|
from credentials import mapbox_api_key
|
2017-12-27 20:43:14 +08:00
|
|
|
|
|
|
|
VALID_ORIGIN = Coordinate(-73.989, 40.733)
|
|
|
|
|
|
|
|
|
|
|
|
class MapboxIsolinesTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-02-11 17:00:27 +08:00
|
|
|
self.mapbox_isolines = MapboxIsolines(apikey=mapbox_api_key(),
|
|
|
|
logger=Mock())
|
|
|
|
|
|
|
|
def test_invalid_time_range(self):
|
|
|
|
time_ranges = [4000]
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
solution = self.mapbox_isolines.calculate_isochrone(
|
|
|
|
origin=VALID_ORIGIN,
|
|
|
|
profile=DEFAULT_PROFILE,
|
|
|
|
time_ranges=time_ranges)
|
2017-12-27 20:43:14 +08:00
|
|
|
|
|
|
|
def test_calculate_isochrone(self):
|
2017-12-29 21:07:51 +08:00
|
|
|
time_ranges = [300, 900]
|
2017-12-27 20:43:14 +08:00
|
|
|
solution = self.mapbox_isolines.calculate_isochrone(
|
|
|
|
origin=VALID_ORIGIN,
|
|
|
|
profile=DEFAULT_PROFILE,
|
2017-12-29 21:07:51 +08:00
|
|
|
time_ranges=time_ranges)
|
2017-12-27 20:43:14 +08:00
|
|
|
|
|
|
|
assert solution
|
|
|
|
|
|
|
|
def test_calculate_isodistance(self):
|
|
|
|
distance_range = 10000
|
|
|
|
solution = self.mapbox_isolines.calculate_isodistance(
|
|
|
|
origin=VALID_ORIGIN,
|
|
|
|
profile=DEFAULT_PROFILE,
|
|
|
|
distance_range=distance_range)
|
|
|
|
|
|
|
|
assert solution
|