thousandeyes-sdk-python/thousandeyes-sdk-administrative/test/test_user_events_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

325 lines
13 KiB
Python

# coding: utf-8
"""
Administrative API
Manage users, accounts, and account groups in the ThousandEyes platform using the Administrative API. This API provides the following operations to manage your organization: * `/account-groups`: Account groups are used to divide an organization into different sections. These operations can be used to create, retrieve, update and delete account groups. * `/users`: Create, retrieve, update and delete users within an organization. * `/roles`: Create, retrieve and update roles for the current user. * `/permissions`: Retrieve all assignable permissions. Used in the context of modifying roles. * `/audit-user-events`: Retrieve all activity log events. For more information about the administrative models, see [Account Management](https://docs.thousandeyes.com/product-documentation/user-management).
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import json
import unittest
import thousandeyes_sdk.administrative.models
from thousandeyes_sdk.core.exceptions import ApiException
from thousandeyes_sdk.administrative.api.user_events_api import UserEventsApi
from .integration_test_utils import IntegrationTestBase
from .test_utils import assert_constructed_model_matches_example_json
class TestUserEventsApiIntegration(IntegrationTestBase):
"""UserEventsApi integration test stubs"""
def setUp(self) -> None:
super().setUp()
self.api = UserEventsApi(self.api_client)
def test_get_user_events_happy_path(self) -> None:
"""Integration test for get_user_events success path"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
start_date = '2022-07-17T22:00:54Z'
end_date = '2022-07-18T22:00:54Z'
cursor = 'cursor_example'
response_body_json = """
{
&quot;endDate&quot; : &quot;2022-07-18T22:00:54Z&quot;,
&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;auditEvents&quot; : [ {
&quot;accountGroupName&quot; : &quot;API Sandbox&quot;,
&quot;aid&quot; : &quot;1234&quot;,
&quot;date&quot; : &quot;2020-07-17T21:54:54Z&quot;,
&quot;event&quot; : &quot;Report created.&quot;,
&quot;ipAddress&quot; : &quot;99.128.0.0/11&quot;,
&quot;uid&quot; : &quot;1234&quot;,
&quot;user&quot; : &quot;API Sandbox User (noreply@thousandeyes.com)&quot;,
&quot;resources&quot; : [ {
&quot;name&quot; : &quot;My New report&quot;,
&quot;type&quot; : &quot;reportTitle&quot;
}, {
&quot;name&quot; : &quot;Other Report&quot;,
&quot;type&quot; : &quot;testName&quot;
} ]
}, {
&quot;accountGroupName&quot; : &quot;API Sandbox&quot;,
&quot;aid&quot; : &quot;1234&quot;,
&quot;date&quot; : &quot;2020-07-17T22:00:54Z&quot;,
&quot;event&quot; : &quot;Login failed.&quot;,
&quot;ipAddress&quot; : &quot;99.128.0.0/11&quot;,
&quot;uid&quot; : &quot;1234&quot;,
&quot;user&quot; : &quot;API Sandbox User (noreply@thousandeyes.com)&quot;
} ],
&quot;startDate&quot; : &quot;2022-07-17T22:00:54Z&quot;
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_user_events_error_400(self) -> None:
"""Integration test for get_user_events error path (HTTP 400)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_events_error_401(self) -> None:
"""Integration test for get_user_events error path (HTTP 401)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_events_error_403(self) -> None:
"""Integration test for get_user_events error path (HTTP 403)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_events_error_404(self) -> None:
"""Integration test for get_user_events error path (HTTP 404)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_events_error_429(self) -> None:
"""Integration test for get_user_events error path (HTTP 429)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_events_error_500(self) -> None:
"""Integration test for get_user_events error path (HTTP 500)"""
aid = '1234'
use_all_permitted_aids = False
window = '12h'
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_user_events(
aid=aid,
use_all_permitted_aids=use_all_permitted_aids,
window=window,
start_date=start_date,
end_date=end_date,
cursor=cursor,
_headers=self.te_headers("get_user_events", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
if __name__ == '__main__':
unittest.main()