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

1584 lines
61 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.users_api import UsersApi
from .integration_test_utils import IntegrationTestBase
from .test_utils import assert_constructed_model_matches_example_json
class TestUsersApiIntegration(IntegrationTestBase):
"""UsersApi integration test stubs"""
def setUp(self) -> None:
super().setUp()
self.api = UsersApi(self.api_client)
def test_create_user_happy_path(self) -> None:
"""Integration test for create_user success path"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
aid = '1234'
response_body_json = """
{
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;allAccountGroupRoles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&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;accountGroupRoles&quot; : [ {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
}, {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
} ],
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
}
"""
expected_response = json.loads(response_body_json)
response = self.api.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_create_user_error_400(self) -> None:
"""Integration test for create_user error path (HTTP 400)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_create_user_error_401(self) -> None:
"""Integration test for create_user error path (HTTP 401)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_create_user_error_403(self) -> None:
"""Integration test for create_user error path (HTTP 403)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_create_user_error_404(self) -> None:
"""Integration test for create_user error path (HTTP 404)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_create_user_error_429(self) -> None:
"""Integration test for create_user error path (HTTP 429)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_create_user_error_500(self) -> None:
"""Integration test for create_user error path (HTTP 500)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
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.create_user(
user_request=user_request,
aid=aid,
_headers=self.te_headers("create_user", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_happy_path(self) -> None:
"""Integration test for delete_user success path"""
id = '1234'
aid = '1234'
response = self.api.delete_user_with_http_info(
id=id,
aid=aid,
_headers=self.te_headers("delete_user"),
)
self.assertEqual(204, response.status_code)
self.assertIsNone(response.data)
def test_delete_user_error_400(self) -> None:
"""Integration test for delete_user error path (HTTP 400)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_error_401(self) -> None:
"""Integration test for delete_user error path (HTTP 401)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_error_403(self) -> None:
"""Integration test for delete_user error path (HTTP 403)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_error_404(self) -> None:
"""Integration test for delete_user error path (HTTP 404)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_error_429(self) -> None:
"""Integration test for delete_user error path (HTTP 429)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_delete_user_error_500(self) -> None:
"""Integration test for delete_user error path (HTTP 500)"""
id = '1234'
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.delete_user(
id=id,
aid=aid,
_headers=self.te_headers("delete_user", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_happy_path(self) -> None:
"""Integration test for get_current_user success path"""
response_body_json = """
{
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;lastLogin&quot; : &quot;2022-07-17T22:00:54Z&quot;,
&quot;allAccountGroupRoles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&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;accountGroupRoles&quot; : [ {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
}, {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
} ],
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_current_user(
_headers=self.te_headers("get_current_user"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_current_user_error_400(self) -> None:
"""Integration test for get_current_user error path (HTTP 400)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_error_401(self) -> None:
"""Integration test for get_current_user error path (HTTP 401)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_error_403(self) -> None:
"""Integration test for get_current_user error path (HTTP 403)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_error_404(self) -> None:
"""Integration test for get_current_user error path (HTTP 404)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_error_429(self) -> None:
"""Integration test for get_current_user error path (HTTP 429)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_current_user_error_500(self) -> None:
"""Integration test for get_current_user error path (HTTP 500)"""
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_current_user(
_headers=self.te_headers("get_current_user", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_happy_path(self) -> None:
"""Integration test for get_user success path"""
id = '1234'
aid = '1234'
response_body_json = """
{
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;lastLogin&quot; : &quot;2022-07-17T22:00:54Z&quot;,
&quot;allAccountGroupRoles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&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;accountGroupRoles&quot; : [ {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
}, {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
} ],
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_user_error_400(self) -> None:
"""Integration test for get_user error path (HTTP 400)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_error_401(self) -> None:
"""Integration test for get_user error path (HTTP 401)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_error_403(self) -> None:
"""Integration test for get_user error path (HTTP 403)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_error_404(self) -> None:
"""Integration test for get_user error path (HTTP 404)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_error_429(self) -> None:
"""Integration test for get_user error path (HTTP 429)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_user_error_500(self) -> None:
"""Integration test for get_user error path (HTTP 500)"""
id = '1234'
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_user(
id=id,
aid=aid,
_headers=self.te_headers("get_user", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_happy_path(self) -> None:
"""Integration test for get_users success path"""
aid = '1234'
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;users&quot; : [ {
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;lastLogin&quot; : &quot;2022-07-17T22:00:54Z&quot;,
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
}, {
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;lastLogin&quot; : &quot;2022-07-17T22:00:54Z&quot;,
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
} ]
}
"""
expected_response = json.loads(response_body_json)
response = self.api.get_users(
aid=aid,
_headers=self.te_headers("get_users"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_get_users_error_400(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_error_401(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_error_403(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_error_404(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_error_429(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_get_users_error_500(self) -> None:
"""Integration test for get_users 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_users(
aid=aid,
_headers=self.te_headers("get_users", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_happy_path(self) -> None:
"""Integration test for update_user success path"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
aid = '1234'
response_body_json = """
{
&quot;loginAccountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
},
&quot;uid&quot; : &quot;245&quot;,
&quot;lastLogin&quot; : &quot;2022-07-17T22:00:54Z&quot;,
&quot;allAccountGroupRoles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&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;accountGroupRoles&quot; : [ {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
}, {
&quot;roles&quot; : [ {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
}, {
&quot;roleId&quot; : &quot;35&quot;,
&quot;name&quot; : &quot;Organization Admin&quot;,
&quot;isBuiltin&quot; : true,
&quot;hasManagementPermissions&quot; : true
} ],
&quot;accountGroup&quot; : {
&quot;accountGroupName&quot; : &quot;Account A&quot;,
&quot;aid&quot; : &quot;1234&quot;
}
} ],
&quot;name&quot; : &quot;User X&quot;,
&quot;email&quot; : &quot;userx@thousandeyes.com&quot;,
&quot;dateRegistered&quot; : &quot;2020-07-17T22:00:54Z&quot;
}
"""
expected_response = json.loads(response_body_json)
response = self.api.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user"),
)
assert_constructed_model_matches_example_json(response, expected_response)
def test_update_user_error_400(self) -> None:
"""Integration test for update_user error path (HTTP 400)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="400"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_error_401(self) -> None:
"""Integration test for update_user error path (HTTP 401)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="401"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_error_403(self) -> None:
"""Integration test for update_user error path (HTTP 403)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="403"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_error_404(self) -> None:
"""Integration test for update_user error path (HTTP 404)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="404"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_error_429(self) -> None:
"""Integration test for update_user error path (HTTP 429)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="429"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
def test_update_user_error_500(self) -> None:
"""Integration test for update_user error path (HTTP 500)"""
request_body_json = """
{
"loginAccountGroupId" : "691",
"accountGroupRoles" : [ {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
}, {
"roleIds" : [ "57", "1140" ],
"accountGroupId" : "315"
} ],
"name" : "User X",
"allAccountGroupRoleIds" : [ "57", "1140" ],
"email" : "userx@thousandeyes.com"
}
"""
user_request = thousandeyes_sdk.administrative.models.UserRequest.from_json(request_body_json)
id = '1234'
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.update_user(
id=id,
user_request=user_request,
aid=aid,
_headers=self.te_headers("update_user", error_status="500"),
)
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
if __name__ == '__main__':
unittest.main()