Skip to content

Commit

Permalink
Serialiaze body in async client
Browse files Browse the repository at this point in the history
Closes #951
  • Loading branch information
therve committed Apr 11, 2022
1 parent 8547dfc commit bbe95f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/datadog_api_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ async def request(
(connection, read) timeouts.
"""
assert not post_params, "not supported for now"
if body is not None:
body = json.dumps(body)
response = await self._client.request(url, method, headers, query_params, body, timeouts=_request_timeout)

if not 200 <= response.status_code <= 299:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time

import pytest

Expand Down Expand Up @@ -41,3 +42,31 @@ async def test_basic():
_, code, headers = await api_instance.list_dashboards(_return_http_data_only=False)
assert code == 200
assert headers["Content-Type"] == "application/json"


@pytest.mark.asyncio
async def test_body():
if os.getenv("RECORD", "false").lower() != "none":
pytest.skip("Integration test")
configuration = Configuration()
configuration.api_key["apiKeyAuth"] = os.getenv("DD_TEST_CLIENT_API_KEY", "fake")
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "fake")
configuration.debug = os.getenv("DEBUG") in {"true", "1", "yes", "on"}
if "DD_TEST_SITE" in os.environ:
configuration.server_index = 2
configuration.server_variables["site"] = os.environ["DD_TEST_SITE"]

body = {
"series": [
{
"metric": "system.load.1",
"points": [[time.time(), 0.7]],
"tags": ["test:async_test"],
},
]
}

async with AsyncApiClient(configuration) as api_client:
api_instance = metrics_api.MetricsApi(api_client)
_, code, headers = await api_instance.submit_metrics(body=body, _return_http_data_only=False)
assert code == 202

0 comments on commit bbe95f7

Please sign in to comment.