thousandeyes-sdk-python/thousandeyes-sdk-usage/test/test_usage_api_integration.py
Kevin 5441f44f1f CP-2453 Add generated integration tests for all SDK packages
Sync OAS-driven integration test artifacts (mock manifest, test base, conftest, and per-operation integration tests) across 21 packages for CP-2453 full rollout evaluation.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 12:07:00 +01:00

816 lines
35 KiB
Python

# coding: utf-8
"""
Usage API
These usage endpoints define the following operations: * **Usage**: Retrieve usage data for the specified time period (default is one month). * Users must have the `View organization usage` permission to access this endpoint. * This operation offers visibility across all account groups within the organization. * Users with `View organization usage` permission in multiple organizations should query the operation with the `aid` query string parameter (see optional parameters) for each organization. * The `agentId` field in enterprise agent unit responses may be omitted when not available. * **Quotas**: Obtain organization and account usage quotas. Additionally, users with the appropriate permissions can create, update, or delete these quotas. * Users must have the necessary permissions to perform quota-related actions. Refer to the Usage API operations for detailed usage instructions and optional parameters.
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import json
import unittest
import thousandeyes_sdk.usage.models
from thousandeyes_sdk.core.exceptions import ApiException
from thousandeyes_sdk.usage.api.usage_api import UsageApi
from .integration_test_utils import IntegrationTestBase
from .test_utils import assert_constructed_model_matches_example_json
class TestUsageApiIntegration(IntegrationTestBase):
"""UsageApi integration test stubs"""
def setUp(self) -> None:
super().setUp()
self.api = UsageApi(self.api_client)
def test_get_enterprise_agents_units_usage_happy_path(self) -> None:
"""Integration test for get_enterprise_agents_units_usage success path"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
response_body_json = """
{
&quot;_links&quot; : {
&quot;next&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
},
&quot;previous&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
},
&quot;self&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
}
},
&quot;breakdowns&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;agentId&quot; : &quot;123456&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;agentName&quot; : &quot;TEVA-test-agent&quot;,
&quot;enterpriseUnitsUsed&quot; : 599878,
&quot;enterpriseUnitsProjected&quot; : 597808
}, {
&quot;aid&quot; : &quot;315&quot;,
&quot;agentId&quot; : &quot;789&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;agentName&quot; : &quot;lab-physical-appliance-1&quot;,
&quot;enterpriseUnitsUsed&quot; : 597123,
&quot;enterpriseUnitsProjected&quot; : 597808
} ]
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_enterprise_agents_units_usage_error_400(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 400)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"errors" : [ {
"code" : "code",
"field" : "field",
"message" : "message"
}, {
"code" : "code",
"field" : "field",
"message" : "message"
} ],
"status" : 0
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(400)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_enterprise_agents_units_usage_error_401(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 401)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"error_description" : "Invalid access token",
"error" : "invalid_token"
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(401)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_enterprise_agents_units_usage_error_403(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 403)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(403)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_enterprise_agents_units_usage_error_404(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 404)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(404)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_enterprise_agents_units_usage_error_429(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 429)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(429)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_enterprise_agents_units_usage_error_500(self) -> None:
"""Integration test for get_enterprise_agents_units_usage error path (HTTP 500)"""
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(500)
) as context:
self.api.get_enterprise_agents_units_usage(
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_enterprise_agents_units_usage", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_happy_path(self) -> None:
"""Integration test for get_tests_units_usage success path"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
response_body_json = """
{
&quot;_links&quot; : {
&quot;next&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
},
&quot;previous&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
},
&quot;self&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
}
},
&quot;breakdowns&quot; : [ {
&quot;testId&quot; : &quot;1158&quot;,
&quot;testName&quot; : &quot;https://app.thousandeyes.com&quot;,
&quot;testType&quot; : &quot;Web-Page Load&quot;,
&quot;enterpriseUnitsUsed&quot; : 14050,
&quot;enterpriseUnitsProjected&quot; : 340674,
&quot;cloudUnitsUsed&quot; : 10000,
&quot;cloudUnitsProjected&quot; : 12000,
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;
}, {
&quot;testId&quot; : &quot;1221&quot;,
&quot;testName&quot; : &quot;https://app.thousandeyes.com&quot;,
&quot;testType&quot; : &quot;Web - HTTP Server&quot;,
&quot;enterpriseUnitsUsed&quot; : 194051,
&quot;enterpriseUnitsProjected&quot; : 30622,
&quot;cloudUnitsUsed&quot; : 12000,
&quot;cloudUnitsProjected&quot; : 13000,
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;
} ]
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_tests_units_usage_error_400(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 400)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"errors" : [ {
"code" : "code",
"field" : "field",
"message" : "message"
}, {
"code" : "code",
"field" : "field",
"message" : "message"
} ],
"status" : 0
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(400)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_error_401(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 401)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"error_description" : "Invalid access token",
"error" : "invalid_token"
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(401)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_error_403(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 403)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(403)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_error_404(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 404)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(404)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_error_429(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 429)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(429)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_tests_units_usage_error_500(self) -> None:
"""Integration test for get_tests_units_usage error path (HTTP 500)"""
aid = '1234'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(500)
) as context:
self.api.get_tests_units_usage(
aid=aid,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_tests_units_usage", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_happy_path(self) -> None:
"""Integration test for get_usage success path"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
response_body_json = """
{
&quot;_links&quot; : {
&quot;self&quot; : {
&quot;hreflang&quot; : &quot;hreflang&quot;,
&quot;templated&quot; : true,
&quot;profile&quot; : &quot;profile&quot;,
&quot;name&quot; : &quot;name&quot;,
&quot;href&quot; : &quot;https://api.thousandeyes.com/v7/link/to/resource/id&quot;,
&quot;type&quot; : &quot;type&quot;,
&quot;deprecation&quot; : &quot;deprecation&quot;,
&quot;title&quot; : &quot;title&quot;
}
},
&quot;usage&quot; : {
&quot;cloudUnitsProjected&quot; : 20993812,
&quot;connectedDevicesUnitsUsed&quot; : 79640902,
&quot;enterpriseAgentsUsed&quot; : 58,
&quot;endpointAgents&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;endpointAgentsUsed&quot; : 22
}, {
&quot;aid&quot; : &quot;12345&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;endpointAgentsUsed&quot; : 14
} ],
&quot;cloudUnitsNextBillingPeriod&quot; : 25123456,
&quot;enterpriseUnitsNextBillingPeriod&quot; : 0,
&quot;endpointAgentsUsed&quot; : 42,
&quot;enterpriseUnitsUsed&quot; : 79640902,
&quot;cloudUnitsUsed&quot; : 8500489,
&quot;connectedDevicesUnitsNextBillingPeriod&quot; : 0,
&quot;connectedDevicesUnitsProjected&quot; : 108016317,
&quot;tests&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;testId&quot; : &quot;1158&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;testName&quot; : &quot;https://app.thousandeyes.com&quot;,
&quot;testType&quot; : &quot;Web-Page Load&quot;,
&quot;cloudUnitsUsed&quot; : 14050,
&quot;cloudUnitsProjected&quot; : 340674
}, {
&quot;aid&quot; : &quot;12345&quot;,
&quot;testId&quot; : &quot;1159&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;testName&quot; : &quot;https://support.thousandeyes.com&quot;,
&quot;testType&quot; : &quot;Web - HTTP Server&quot;,
&quot;cloudUnitsUsed&quot; : 64390,
&quot;cloudUnitsProjected&quot; : 164457
} ],
&quot;endpointAgentsEmbedded&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;endpointAgentsEmbeddedUsed&quot; : 2
}, {
&quot;aid&quot; : &quot;12345&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;endpointAgentsEmbeddedUsed&quot; : 3
} ],
&quot;allocations&quot; : {
&quot;used&quot; : 1000,
&quot;projected&quot; : 1000,
&quot;allocations&quot; : [ {
&quot;productName&quot; : &quot;Some Product Name&quot;,
&quot;allocatedUnits&quot; : 600
} ]
},
&quot;endpointAgentsEssentialsUsed&quot; : 5,
&quot;quota&quot; : {
&quot;monthEnd&quot; : &quot;2020-02-05T08:00:00Z&quot;,
&quot;endpointAgentsEmbeddedIncluded&quot; : 10,
&quot;enterpriseAgentsIncluded&quot; : 25,
&quot;monthStart&quot; : &quot;2020-01-05T08:00:00Z&quot;,
&quot;cloudUnitsIncluded&quot; : 4320000000,
&quot;deviceAgentsIncluded&quot; : 100,
&quot;endpointAgentsIncluded&quot; : 200,
&quot;endpointAgentsEssentialsIncluded&quot; : 10
},
&quot;enterpriseUnitsProjected&quot; : 108016317,
&quot;endpointAgentsEmbeddedUsed&quot; : 5,
&quot;enterpriseAgents&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;enterpriseAgentsUsed&quot; : 7
}, {
&quot;aid&quot; : &quot;12345&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;enterpriseAgentsUsed&quot; : 1
} ],
&quot;enterpriseAgentUnits&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;agentId&quot; : &quot;123456&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;agentName&quot; : &quot;TEVA-test-agent&quot;,
&quot;enterpriseUnitsUsed&quot; : 599878,
&quot;enterpriseUnitsProjected&quot; : 597808
}, {
&quot;aid&quot; : &quot;315&quot;,
&quot;agentId&quot; : &quot;789&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;agentName&quot; : &quot;lab-physical-appliance-1&quot;,
&quot;enterpriseUnitsUsed&quot; : 597123,
&quot;enterpriseUnitsProjected&quot; : 597808
} ],
&quot;endpointAgentsEssentials&quot; : [ {
&quot;aid&quot; : &quot;1234&quot;,
&quot;accountGroupName&quot; : &quot;Support&quot;,
&quot;endpointAgentsEssentialsUsed&quot; : 2
}, {
&quot;aid&quot; : &quot;12345&quot;,
&quot;accountGroupName&quot; : &quot;Documentation&quot;,
&quot;endpointAgentsEssentialsUsed&quot; : 3
} ]
}
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_usage_error_400(self) -> None:
"""Integration test for get_usage error path (HTTP 400)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"errors" : [ {
"code" : "code",
"field" : "field",
"message" : "message"
}, {
"code" : "code",
"field" : "field",
"message" : "message"
} ],
"status" : 0
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(400)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_error_401(self) -> None:
"""Integration test for get_usage error path (HTTP 401)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"error_description" : "Invalid access token",
"error" : "invalid_token"
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(401)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_error_403(self) -> None:
"""Integration test for get_usage error path (HTTP 403)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(403)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_error_404(self) -> None:
"""Integration test for get_usage error path (HTTP 404)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(404)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_error_429(self) -> None:
"""Integration test for get_usage error path (HTTP 429)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(429)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_usage_error_500(self) -> None:
"""Integration test for get_usage error path (HTTP 500)"""
aid = '1234'
expand = [thousandeyes_sdk.usage.ExpandUsageOptions()]
error_body_json = """
{
"instance" : "instance",
"detail" : "detail",
"type" : "type",
"title" : "title",
"status" : 6
}
"""
expected_error = json.loads(error_body_json)
with self.assertRaises(
ApiException.exception_class_for_http_status(500)
) as context:
self.api.get_usage(
aid=aid,
expand=expand,
_headers=self.te_headers("get_usage", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
if __name__ == '__main__':
unittest.main()