Skip to content
Merged
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
6 changes: 3 additions & 3 deletions datadog/api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
ApiNotInitialized
)
from datadog.api.http_client import resolve_http_client
from datadog.util.compat import is_p3k, urljoin
from datadog.util.compat import is_p3k
from datadog.util.format import construct_url


log = logging.getLogger('datadog.api')
Expand Down Expand Up @@ -120,8 +121,7 @@ def submit(cls, method, path, api_version=None, body=None, attach_host_name=Fals
headers['Content-Type'] = 'application/json'

# Construct the URL
start_url = urljoin(_api_host, 'api/{}/'.format(api_version))
url = urljoin(start_url, path)
url = construct_url(_api_host, api_version, path)

# Process requesting
start_time = time.time()
Expand Down
3 changes: 2 additions & 1 deletion datadog/api/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def status(cls, snapshot_url):
"""
snap_path = urlparse(snapshot_url).path
snap_path = snap_path.split('/snapshot/view/')[1].split('.png')[0]
snapshot_status_url = '/graph/snapshot_status/{0}'.format(snap_path)

snapshot_status_url = 'graph/snapshot_status/{0}'.format(snap_path)

return super(Graph, cls)._trigger_action('GET', snapshot_status_url)

Expand Down
4 changes: 4 additions & 0 deletions datadog/util/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

def pretty_json(obj):
return json.dumps(obj, sort_keys=True, indent=2)


def construct_url(host, api_version, path):
return "{}/api/{}/{}".format(host.strip("/"), api_version.strip("/"), path.strip("/"))
Empty file added tests/unit/util/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions tests/unit/util/test_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from datadog.util.format import construct_url


class TestConstructURL:
expected = "https://api.datadoghq.com/api/v1/graph/snapshot"
test_data = [
("https://api.datadoghq.com", "v1", "graph/snapshot", expected),
("https://api.datadoghq.com/", "v1", "graph/snapshot", expected),
("https://api.datadoghq.com", "/v1", "graph/snapshot", expected),
("https://api.datadoghq.com/", "/v1", "graph/snapshot", expected),
("https://api.datadoghq.com", "v1/", "graph/snapshot", expected),
("https://api.datadoghq.com/", "v1/", "graph/snapshot", expected),
("https://api.datadoghq.com", "/v1/", "graph/snapshot", expected),
("https://api.datadoghq.com/", "/v1/", "graph/snapshot", expected),
("https://api.datadoghq.com", "v1", "/graph/snapshot", expected),
("https://api.datadoghq.com/", "v1", "/graph/snapshot", expected),
("https://api.datadoghq.com", "/v1", "/graph/snapshot", expected),
("https://api.datadoghq.com/", "/v1", "/graph/snapshot", expected),
("https://api.datadoghq.com", "v1/", "/graph/snapshot", expected),
("https://api.datadoghq.com/", "v1/", "/graph/snapshot", expected),
("https://api.datadoghq.com", "/v1/", "/graph/snapshot", expected),
("https://api.datadoghq.com/", "/v1/", "/graph/snapshot", expected),
]

@pytest.mark.parametrize("host,api_version,path,expected", test_data)
def test_construct_url(self, host, api_version, path, expected):
assert construct_url(host, api_version, path) == expected