Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mygeotab/altitude/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .daas_definition import DaasGetQueryResult, DaasGetJobStatusResult, NOT_FULL_API_CALL_EXCEPTION
from ..api import API, DEFAULT_TIMEOUT

ALTITUDE_PROXY_SERVER = "https://altitudeapis.geotab.com/api/v1"


class AltitudeAPI(API):
def __init__(
Expand All @@ -12,7 +14,7 @@ def __init__(
password=None,
database=None,
session_id=None,
server="altitudeserver.geotab.com",
server=ALTITUDE_PROXY_SERVER,
timeout=DEFAULT_TIMEOUT,
proxies=None,
cert=None,
Expand All @@ -28,7 +30,8 @@ def __init__(
:type database: str
:param session_id: A session ID, assigned by the server.
:type session_id: str
:param server: The server ie. my23.geotab.com. Optional as this usually gets resolved upon authentication.
:param server: Ignored for routing. All Altitude traffic is hardcoded to the proxy
at ``https://altitudeapis.geotab.com/api/v1``, which forwards requests to MyGeotab.
:type server: str or None
:param timeout: The timeout to make the call, in seconds. By default, this is 300 seconds (or 5 minutes).
:type timeout: float or None
Expand All @@ -38,7 +41,8 @@ def __init__(
:type cert: str or Tuple or None
:raise Exception: Raises an Exception if a username, or one of the session_id or password is not provided.
"""

# Overwriting to our new proxy server - backwards compatible for our customers
server = ALTITUDE_PROXY_SERVER
super().__init__(
username=username,
password=password,
Expand Down
2 changes: 2 additions & 0 deletions mygeotab/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ def get_api_url(server):
:rtype: str
"""
parsed = urlparse(server)
if parsed.scheme in ("http", "https") and parsed.path not in ("", "/"):
return server
base_url = parsed.netloc if parsed.netloc else parsed.path
base_url.replace("/", "")
return "https://" + base_url + "/apiv1"
Expand Down
24 changes: 24 additions & 0 deletions tests/test_altitude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

from mygeotab import api
from mygeotab.altitude.wrapper import AltitudeAPI, ALTITUDE_PROXY_SERVER

USERNAME = "test@example.com"
SESSION_ID = "abc123sessionid"
DATABASE = "testdatabase"


class TestAltitudeServer:
def test_default_server_is_proxy(self):
altitude_api = AltitudeAPI(USERNAME, session_id=SESSION_ID, database=DATABASE)
assert altitude_api._server == ALTITUDE_PROXY_SERVER

def test_passed_server_is_overridden(self):
altitude_api = AltitudeAPI(
USERNAME, session_id=SESSION_ID, database=DATABASE, server="my3.geotab.com"
)
assert altitude_api._server == ALTITUDE_PROXY_SERVER

def test_resolved_url_is_proxy_verbatim(self):
altitude_api = AltitudeAPI(USERNAME, session_id=SESSION_ID, database=DATABASE)
assert api.get_api_url(altitude_api._server) == ALTITUDE_PROXY_SERVER
16 changes: 16 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ def test_should_verify_ssl(self):
assert my_api._is_verify_ssl is False


class TestGetApiUrl:
def test_bare_host(self):
assert api.get_api_url("my3.geotab.com") == "https://my3.geotab.com/apiv1"

def test_scheme_empty_path(self):
assert api.get_api_url("https://example.com") == "https://example.com/apiv1"

def test_scheme_root_path(self):
assert api.get_api_url("https://example.com/") == "https://example.com/apiv1"

def test_full_url_with_path_returned_verbatim(self):
server = "https://altitudeapis.geotab.com/api/v1"
assert api.get_api_url(server) == server



class TestProcessResults:
def test_handle_server_exception(self):
exception_response = dict(
Expand Down
Loading