Skip to content
Merged
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
12 changes: 5 additions & 7 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@

from datadog_api_client.api_client import AsyncApiClient
from datadog_api_client.configuration import Configuration
from datadog_api_client.exceptions import ForbiddenException
from datadog_api_client.exceptions import UnauthorizedException
from datadog_api_client.v1.api import dashboards_api, metrics_api


@pytest.mark.asyncio
async def test_error():
configuration = Configuration()
configuration.api_key["apiKeyAuth"] = "00000000000000000000000000000000"
configuration.api_key["appKeyAuth"] = "00000000000000000000000000000000"

async with AsyncApiClient(configuration) as api_client:
api_instance = metrics_api.MetricsApi(api_client)
with pytest.raises(ForbiddenException) as e:
with pytest.raises(UnauthorizedException) as e:
await api_instance.get_metric_metadata("some_metric")
error = str(e.value)
assert "(403)" in error
assert "Reason: Forbidden" in error
assert "(401)" in error
assert "Reason: Unauthorized" in error
# cast headers to HttpHeaders to make them case insensitive
headers = HttpHeaders(e.value.headers)
assert headers["content-type"] == "application/json"
assert e.value.body["errors"] == ["Forbidden"]
assert e.value.body["errors"] == ["Unauthorized"]


@pytest.mark.asyncio
Expand Down