thousandeyes-sdk-python/thousandeyes-sdk-usage/test/test_usage_api_integration.py
Kevin b1faff026e Regenerate integration tests with fixed JSON escaping and enum params.
Success response bodies now use valid JSON quotes instead of HTML entities,
and optional expand enum params are omitted when OpenAPI examples are invalid.

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

879 lines
31 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 = """
{
"_links" : {
"next" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
},
"previous" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
},
"self" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
}
},
"breakdowns" : [ {
"aid" : "1234",
"agentId" : "123456",
"accountGroupName" : "Support",
"agentName" : "TEVA-test-agent",
"enterpriseUnitsUsed" : 599878,
"enterpriseUnitsProjected" : 597808
}, {
"aid" : "315",
"agentId" : "789",
"accountGroupName" : "Documentation",
"agentName" : "lab-physical-appliance-1",
"enterpriseUnitsUsed" : 597123,
"enterpriseUnitsProjected" : 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 = """
{
"_links" : {
"next" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
},
"previous" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
},
"self" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
}
},
"breakdowns" : [ {
"testId" : "1158",
"testName" : "https://app.thousandeyes.com",
"testType" : "Web-Page Load",
"enterpriseUnitsUsed" : 14050,
"enterpriseUnitsProjected" : 340674,
"cloudUnitsUsed" : 10000,
"cloudUnitsProjected" : 12000,
"aid" : "1234",
"accountGroupName" : "Support"
}, {
"testId" : "1221",
"testName" : "https://app.thousandeyes.com",
"testType" : "Web - HTTP Server",
"enterpriseUnitsUsed" : 194051,
"enterpriseUnitsProjected" : 30622,
"cloudUnitsUsed" : 12000,
"cloudUnitsProjected" : 13000,
"aid" : "1234",
"accountGroupName" : "Support"
} ]
}
"""
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'
response_body_json = """
{
"_links" : {
"self" : {
"hreflang" : "hreflang",
"templated" : true,
"profile" : "profile",
"name" : "name",
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
"type" : "type",
"deprecation" : "deprecation",
"title" : "title"
}
},
"usage" : {
"cloudUnitsProjected" : 20993812,
"connectedDevicesUnitsUsed" : 79640902,
"enterpriseAgentsUsed" : 58,
"endpointAgents" : [ {
"aid" : "1234",
"accountGroupName" : "Support",
"endpointAgentsUsed" : 22
}, {
"aid" : "12345",
"accountGroupName" : "Documentation",
"endpointAgentsUsed" : 14
} ],
"cloudUnitsNextBillingPeriod" : 25123456,
"enterpriseUnitsNextBillingPeriod" : 0,
"endpointAgentsUsed" : 42,
"enterpriseUnitsUsed" : 79640902,
"cloudUnitsUsed" : 8500489,
"connectedDevicesUnitsNextBillingPeriod" : 0,
"connectedDevicesUnitsProjected" : 108016317,
"tests" : [ {
"aid" : "1234",
"testId" : "1158",
"accountGroupName" : "Documentation",
"testName" : "https://app.thousandeyes.com",
"testType" : "Web-Page Load",
"cloudUnitsUsed" : 14050,
"cloudUnitsProjected" : 340674
}, {
"aid" : "12345",
"testId" : "1159",
"accountGroupName" : "Documentation",
"testName" : "https://support.thousandeyes.com",
"testType" : "Web - HTTP Server",
"cloudUnitsUsed" : 64390,
"cloudUnitsProjected" : 164457
} ],
"endpointAgentsEmbedded" : [ {
"aid" : "1234",
"accountGroupName" : "Support",
"endpointAgentsEmbeddedUsed" : 2
}, {
"aid" : "12345",
"accountGroupName" : "Documentation",
"endpointAgentsEmbeddedUsed" : 3
} ],
"allocations" : {
"used" : 1000,
"projected" : 1000,
"allocations" : [ {
"productName" : "Some Product Name",
"allocatedUnits" : 600
} ]
},
"endpointAgentsEssentialsUsed" : 5,
"quota" : {
"monthEnd" : "2020-02-05T08:00:00Z",
"endpointAgentsEmbeddedIncluded" : 10,
"enterpriseAgentsIncluded" : 25,
"monthStart" : "2020-01-05T08:00:00Z",
"cloudUnitsIncluded" : 4320000000,
"deviceAgentsIncluded" : 100,
"endpointAgentsIncluded" : 200,
"endpointAgentsEssentialsIncluded" : 10
},
"enterpriseUnitsProjected" : 108016317,
"endpointAgentsEmbeddedUsed" : 5,
"enterpriseAgents" : [ {
"aid" : "1234",
"accountGroupName" : "Support",
"enterpriseAgentsUsed" : 7
}, {
"aid" : "12345",
"accountGroupName" : "Documentation",
"enterpriseAgentsUsed" : 1
} ],
"enterpriseAgentUnits" : [ {
"aid" : "1234",
"agentId" : "123456",
"accountGroupName" : "Support",
"agentName" : "TEVA-test-agent",
"enterpriseUnitsUsed" : 599878,
"enterpriseUnitsProjected" : 597808
}, {
"aid" : "315",
"agentId" : "789",
"accountGroupName" : "Documentation",
"agentName" : "lab-physical-appliance-1",
"enterpriseUnitsUsed" : 597123,
"enterpriseUnitsProjected" : 597808
} ],
"endpointAgentsEssentials" : [ {
"aid" : "1234",
"accountGroupName" : "Support",
"endpointAgentsEssentialsUsed" : 2
}, {
"aid" : "12345",
"accountGroupName" : "Documentation",
"endpointAgentsEssentialsUsed" : 3
} ]
}
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_usage(
aid=aid,
_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'
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,
_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'
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,
_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'
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,
_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'
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,
_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'
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,
_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'
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,
_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()