Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
"""Tests for client module."""
import responses
import requests
import time
import routingpy
from routingpy.routers import options, base
import tests as _test
class RouterMock(base.Router):
def __init__(self, *args, **kwargs):
super(RouterMock, self).__init__(*args, **kwargs)
def directions(self, *args, **kwargs):
return self._request(*args, **kwargs)
def isochrones(self):
pass
def matrix(self):
pass
class BaseTest(_test.TestCase):
def setUp(self):
self.router = RouterMock("https://httpbin.org/")
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
"""
Core client functionality, common across all API requests.
"""
from .base import Router, DEFAULT
from routingpy import convert, utils
from routingpy.direction import Direction, Directions
from routingpy.isochrone import Isochrone, Isochrones
from routingpy.matrix import Matrix
class MapboxOSRM(Router):
"""Performs requests to the OSRM API services."""
_base_url = 'https://api.mapbox.com'
def __init__(
self,
api_key,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs=None,
retry_over_query_limit=False,
skip_api_error=None
):
"""
Initializes a Mapbox OSRM client.
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
from .base import Router, DEFAULT
from routingpy import convert
from routingpy.direction import Direction, Directions
from routingpy.isochrone import Isochrones, Isochrone
from routingpy.matrix import Matrix
from operator import itemgetter
class HereMaps(Router):
"""Performs requests to the HERE Maps API services."""
_DEFAULT_BASE_URL = 'https://route.api.here.com/routing/7.2'
def __init__(
self,
app_id=None,
app_code=None,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs=None,
retry_over_query_limit=False,
skip_api_error=None
):
"""
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
from .base import Router, DEFAULT
from routingpy import convert, utils
from routingpy.direction import Directions, Direction
from routingpy.matrix import Matrix
class OSRM(Router):
"""Performs requests to the OSRM API services."""
_DEFAULT_BASE_URL = 'https://router.project-osrm.org'
def __init__(
self,
base_url=_DEFAULT_BASE_URL,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs=None,
retry_over_query_limit=False,
skip_api_error=None
):
"""
Initializes an OSRM client.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
from .base import Router, DEFAULT
from routingpy import convert
from routingpy import utils
from routingpy.direction import Direction, Directions
from routingpy.isochrone import Isochrone, Isochrones
from routingpy.matrix import Matrix
class Graphhopper(Router):
"""Performs requests to the Graphhopper API services."""
_DEFAULT_BASE_URL = "https://graphhopper.com/api/1"
def __init__(
self,
api_key=None,
base_url=_DEFAULT_BASE_URL,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs={},
retry_over_query_limit=False,
skip_api_error=None
):
"""
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
from .base import Router, DEFAULT
from routingpy import convert, utils
from routingpy.direction import Directions, Direction
from routingpy.matrix import Matrix
from operator import itemgetter
class Google(Router):
"""Performs requests to the Google API services."""
_base_url = "https://maps.googleapis.com/maps/api"
def __init__(
self,
api_key,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs={},
retry_over_query_limit=True,
skip_api_error=None
):
"""
Initializes a Google client.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
from .base import Router, DEFAULT
from routingpy import utils
from routingpy.direction import Direction
from routingpy.isochrone import Isochrone, Isochrones
from routingpy.matrix import Matrix
class ORS(Router):
"""Performs requests to the ORS API services."""
_DEFAULT_BASE_URL = 'https://api.openrouteservice.org'
def __init__(
self,
api_key=None,
base_url=_DEFAULT_BASE_URL,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs=None,
retry_over_query_limit=False,
skip_api_error=None
):
"""
# the License.
#
"""
Core client functionality, common across all API requests.
"""
from .base import Router, DEFAULT
from routingpy import utils
from routingpy.direction import Direction
from routingpy.isochrone import Isochrone, Isochrones
from routingpy.matrix import Matrix
from operator import itemgetter
class Valhalla(Router):
"""Performs requests to a Valhalla instance."""
def __init__(
self,
base_url,
api_key=None,
user_agent=None,
timeout=DEFAULT,
retry_timeout=None,
requests_kwargs=None,
retry_over_query_limit=False,
skip_api_error=None
):
"""
Initializes a Valhalla client.
:param api_key: Mapbox API key. Required if base_url='https://api.mapbox.com/valhalla/v1'.