mirror of
https://github.com/thousandeyes/thousandeyes-sdk-python.git
synced 2026-08-04 08:56:50 +00:00
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>
549 lines
22 KiB
Python
549 lines
22 KiB
Python
# coding: utf-8
|
|
|
|
"""
|
|
Emulation API
|
|
|
|
**Note:** All Emulation APIs are not available for ThousandEyes for Government instance. The Emulation API facilitates the retrieval of user-agent strings for HTTP, pageload, and transaction tests. It also enables the retrieval and addition of emulated devices for pageload and transaction tests. To access Emulation API operations, the following permissions are required: * `Settings Tests Read` for read operations. * `Settings Tests Update` for write operations.
|
|
|
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
|
|
Do not edit the class manually.
|
|
""" # noqa: E501
|
|
|
|
|
|
import json
|
|
import unittest
|
|
import thousandeyes_sdk.emulation.models
|
|
|
|
from thousandeyes_sdk.core.exceptions import ApiException
|
|
from thousandeyes_sdk.emulation.api.emulation_api import EmulationApi
|
|
from .integration_test_utils import IntegrationTestBase
|
|
from .test_utils import assert_constructed_model_matches_example_json
|
|
|
|
|
|
class TestEmulationApiIntegration(IntegrationTestBase):
|
|
"""EmulationApi integration test stubs"""
|
|
|
|
def setUp(self) -> None:
|
|
super().setUp()
|
|
self.api = EmulationApi(self.api_client)
|
|
|
|
|
|
def test_create_emulated_device_happy_path(self) -> None:
|
|
"""Integration test for create_emulated_device success path"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.from_json(request_body_json)
|
|
aid = '1234'
|
|
response_body_json = """
|
|
{
|
|
"availableUserAgents" : [ "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Mobile Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Safari/537.36" ],
|
|
"width" : 1024,
|
|
"name" : "iPad Pro 12.9-in",
|
|
"codeName" : "IPAD_PRO_12_9",
|
|
"id" : "11",
|
|
"category" : "desktop",
|
|
"defaultUserAgentTemplate" : "Mozilla/5.0 (Android 4.4; Tablet; rv:70.0) Gecko/70.0 Firefox/70.0",
|
|
"height" : 768
|
|
}
|
|
"""
|
|
expected_response = json.loads(response_body_json)
|
|
response = self.api.create_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device"),
|
|
)
|
|
assert_constructed_model_matches_example_json(response, expected_response)
|
|
|
|
|
|
def test_create_emulated_device_error_401(self) -> None:
|
|
"""Integration test for create_emulated_device error path (HTTP 401)"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.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_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device", error_status="401"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_create_emulated_device_error_403(self) -> None:
|
|
"""Integration test for create_emulated_device error path (HTTP 403)"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.from_json(request_body_json)
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(403)
|
|
) as context:
|
|
self.api.create_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device", error_status="403"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_create_emulated_device_error_404(self) -> None:
|
|
"""Integration test for create_emulated_device error path (HTTP 404)"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.from_json(request_body_json)
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(404)
|
|
) as context:
|
|
self.api.create_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device", error_status="404"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_create_emulated_device_error_429(self) -> None:
|
|
"""Integration test for create_emulated_device error path (HTTP 429)"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.from_json(request_body_json)
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(429)
|
|
) as context:
|
|
self.api.create_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device", error_status="429"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_create_emulated_device_error_500(self) -> None:
|
|
"""Integration test for create_emulated_device error path (HTTP 500)"""
|
|
request_body_json = """
|
|
|
|
{
|
|
"width" : 1024,
|
|
"category" : "desktop",
|
|
"height" : 768
|
|
}
|
|
|
|
"""
|
|
emulated_device = thousandeyes_sdk.emulation.models.EmulatedDevice.from_json(request_body_json)
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(500)
|
|
) as context:
|
|
self.api.create_emulated_device(
|
|
emulated_device=emulated_device,
|
|
aid=aid,
|
|
_headers=self.te_headers("create_emulated_device", error_status="500"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
|
|
|
|
def test_get_emulated_devices_happy_path(self) -> None:
|
|
"""Integration test for get_emulated_devices success path"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
response_body_json = """
|
|
{
|
|
"emulatedDevices" : [ {
|
|
"availableUserAgents" : [ "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Mobile Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Safari/537.36" ],
|
|
"width" : 1024,
|
|
"name" : "iPad Pro 12.9-in",
|
|
"codeName" : "IPAD_PRO_12_9",
|
|
"id" : "11",
|
|
"category" : "desktop",
|
|
"defaultUserAgentTemplate" : "Mozilla/5.0 (Android 4.4; Tablet; rv:70.0) Gecko/70.0 Firefox/70.0",
|
|
"height" : 768
|
|
}, {
|
|
"availableUserAgents" : [ "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Mobile Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Safari/537.36" ],
|
|
"width" : 1024,
|
|
"name" : "iPad Pro 12.9-in",
|
|
"codeName" : "IPAD_PRO_12_9",
|
|
"id" : "11",
|
|
"category" : "desktop",
|
|
"defaultUserAgentTemplate" : "Mozilla/5.0 (Android 4.4; Tablet; rv:70.0) Gecko/70.0 Firefox/70.0",
|
|
"height" : 768
|
|
} ],
|
|
"_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"
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
expected_response = json.loads(response_body_json)
|
|
response = self.api.get_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices"),
|
|
)
|
|
assert_constructed_model_matches_example_json(response, expected_response)
|
|
|
|
|
|
def test_get_emulated_devices_error_401(self) -> None:
|
|
"""Integration test for get_emulated_devices error path (HTTP 401)"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
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_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices", error_status="401"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_emulated_devices_error_403(self) -> None:
|
|
"""Integration test for get_emulated_devices error path (HTTP 403)"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(403)
|
|
) as context:
|
|
self.api.get_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices", error_status="403"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_emulated_devices_error_404(self) -> None:
|
|
"""Integration test for get_emulated_devices error path (HTTP 404)"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(404)
|
|
) as context:
|
|
self.api.get_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices", error_status="404"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_emulated_devices_error_429(self) -> None:
|
|
"""Integration test for get_emulated_devices error path (HTTP 429)"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(429)
|
|
) as context:
|
|
self.api.get_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices", error_status="429"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_emulated_devices_error_500(self) -> None:
|
|
"""Integration test for get_emulated_devices error path (HTTP 500)"""
|
|
expand = [thousandeyes_sdk.emulation.ExpandEmulatedDeviceOptions()]
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(500)
|
|
) as context:
|
|
self.api.get_emulated_devices(
|
|
expand=expand,
|
|
_headers=self.te_headers("get_emulated_devices", error_status="500"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
|
|
|
|
def test_get_user_agents_happy_path(self) -> None:
|
|
"""Integration test for get_user_agents 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"
|
|
}
|
|
},
|
|
"userAgents" : [ {
|
|
"os" : "Windows",
|
|
"browser" : "Firefox",
|
|
"value" : "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Mobile Safari/537.36"
|
|
}, {
|
|
"os" : "Windows",
|
|
"browser" : "Firefox",
|
|
"value" : "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.70 Mobile Safari/537.36"
|
|
} ]
|
|
}
|
|
"""
|
|
expected_response = json.loads(response_body_json)
|
|
response = self.api.get_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents"),
|
|
)
|
|
assert_constructed_model_matches_example_json(response, expected_response)
|
|
|
|
|
|
def test_get_user_agents_error_401(self) -> None:
|
|
"""Integration test for get_user_agents 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_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents", error_status="401"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_user_agents_error_403(self) -> None:
|
|
"""Integration test for get_user_agents error path (HTTP 403)"""
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(403)
|
|
) as context:
|
|
self.api.get_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents", error_status="403"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_user_agents_error_404(self) -> None:
|
|
"""Integration test for get_user_agents error path (HTTP 404)"""
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(404)
|
|
) as context:
|
|
self.api.get_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents", error_status="404"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_user_agents_error_429(self) -> None:
|
|
"""Integration test for get_user_agents error path (HTTP 429)"""
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(429)
|
|
) as context:
|
|
self.api.get_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents", error_status="429"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_user_agents_error_500(self) -> None:
|
|
"""Integration test for get_user_agents error path (HTTP 500)"""
|
|
aid = '1234'
|
|
error_body_json = """
|
|
{
|
|
"instance" : "instance",
|
|
"detail" : "detail",
|
|
"type" : "type",
|
|
"title" : "title",
|
|
"status" : 0
|
|
}
|
|
"""
|
|
expected_error = json.loads(error_body_json)
|
|
with self.assertRaises(
|
|
ApiException.exception_class_for_http_status(500)
|
|
) as context:
|
|
self.api.get_user_agents(
|
|
aid=aid,
|
|
_headers=self.te_headers("get_user_agents", error_status="500"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|