mirror of
https://github.com/thousandeyes/thousandeyes-sdk-python.git
synced 2026-08-04 00:46:52 +00:00
446 lines
15 KiB
Python
446 lines
15 KiB
Python
# coding: utf-8
|
|
|
|
"""
|
|
Tests API
|
|
|
|
**Note:** The Page Load Tests, API Tests, and Web Transaction Tests APIs are not available for ThousandEyes for Government instance. This API allows you to list, create, edit, and delete Network and Application Synthetics tests.
|
|
|
|
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
|
|
Do not edit the class manually.
|
|
""" # noqa: E501
|
|
|
|
|
|
import json
|
|
import unittest
|
|
import thousandeyes_sdk.tests.models
|
|
|
|
from thousandeyes_sdk.core.exceptions import ApiException
|
|
from thousandeyes_sdk.tests.api.tests_api import TestsApi
|
|
from .integration_test_utils import IntegrationTestBase
|
|
from .test_utils import assert_constructed_model_matches_example_json
|
|
|
|
|
|
class TestTestsApiIntegration(IntegrationTestBase):
|
|
"""TestsApi integration test stubs"""
|
|
|
|
def setUp(self) -> None:
|
|
super().setUp()
|
|
self.api = TestsApi(self.api_client)
|
|
|
|
|
|
def test_get_test_version_history_happy_path(self) -> None:
|
|
"""Integration test for get_test_version_history success path"""
|
|
test_id = '202701'
|
|
aid = '1234'
|
|
limit = 50
|
|
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"
|
|
}
|
|
},
|
|
"testVersionHistory" : [ {
|
|
"versionId" : "1234",
|
|
"versionTimestamp" : "2022-07-17T22:00:54Z",
|
|
"createdBy" : "user (user@user.com)",
|
|
"testId" : "474276"
|
|
}, {
|
|
"versionId" : "1234",
|
|
"versionTimestamp" : "2022-07-17T22:00:54Z",
|
|
"createdBy" : "user (user@user.com)",
|
|
"testId" : "474276"
|
|
} ]
|
|
}
|
|
"""
|
|
expected_response = json.loads(response_body_json)
|
|
response = self.api.get_test_version_history(
|
|
|
|
test_id=test_id,
|
|
|
|
aid=aid,
|
|
|
|
limit=limit,
|
|
|
|
_headers=self.te_headers("get_test_version_history"),
|
|
)
|
|
assert_constructed_model_matches_example_json(response, expected_response)
|
|
|
|
|
|
def test_get_test_version_history_error_401(self) -> None:
|
|
"""Integration test for get_test_version_history error path (HTTP 401)"""
|
|
test_id = '202701'
|
|
aid = '1234'
|
|
limit = 50
|
|
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_test_version_history(
|
|
|
|
test_id=test_id,
|
|
|
|
aid=aid,
|
|
|
|
limit=limit,
|
|
|
|
_headers=self.te_headers("get_test_version_history", error_status="401"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_test_version_history_error_403(self) -> None:
|
|
"""Integration test for get_test_version_history error path (HTTP 403)"""
|
|
test_id = '202701'
|
|
aid = '1234'
|
|
limit = 50
|
|
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_test_version_history(
|
|
|
|
test_id=test_id,
|
|
|
|
aid=aid,
|
|
|
|
limit=limit,
|
|
|
|
_headers=self.te_headers("get_test_version_history", error_status="403"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_test_version_history_error_404(self) -> None:
|
|
"""Integration test for get_test_version_history error path (HTTP 404)"""
|
|
test_id = '202701'
|
|
aid = '1234'
|
|
limit = 50
|
|
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_test_version_history(
|
|
|
|
test_id=test_id,
|
|
|
|
aid=aid,
|
|
|
|
limit=limit,
|
|
|
|
_headers=self.te_headers("get_test_version_history", error_status="404"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_test_version_history_error_500(self) -> None:
|
|
"""Integration test for get_test_version_history error path (HTTP 500)"""
|
|
test_id = '202701'
|
|
aid = '1234'
|
|
limit = 50
|
|
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_test_version_history(
|
|
|
|
test_id=test_id,
|
|
|
|
aid=aid,
|
|
|
|
limit=limit,
|
|
|
|
_headers=self.te_headers("get_test_version_history", error_status="500"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
|
|
|
|
def test_get_tests_happy_path(self) -> None:
|
|
"""Integration test for get_tests success path"""
|
|
aid = '1234'
|
|
response_body_json = """
|
|
{
|
|
"tests" : [ {
|
|
"_links" : {
|
|
"testResults" : [ {
|
|
"href" : "https://api.thousandeyes.com/v7/test-results/281474976710706/network"
|
|
}, {
|
|
"href" : "https://api.thousandeyes.com/v7/test-results/281474976710706/path-vis"
|
|
} ],
|
|
"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"
|
|
}
|
|
},
|
|
"liveShare" : false,
|
|
"savedEvent" : true,
|
|
"description" : "ThousandEyes Test",
|
|
"type" : "agent-to-server",
|
|
"enabled" : true,
|
|
"createdDate" : "2022-07-17T22:00:54Z",
|
|
"createdBy" : "user@user.com",
|
|
"modifiedDate" : "2022-07-17T22:00:54Z",
|
|
"interval" : 60,
|
|
"modifiedBy" : "user@user.com",
|
|
"testId" : "281474976710706",
|
|
"alertsEnabled" : true,
|
|
"testName" : "ThousandEyes Test"
|
|
}, {
|
|
"_links" : {
|
|
"testResults" : [ {
|
|
"href" : "https://api.thousandeyes.com/v7/test-results/281474976710706/network"
|
|
}, {
|
|
"href" : "https://api.thousandeyes.com/v7/test-results/281474976710706/path-vis"
|
|
} ],
|
|
"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"
|
|
}
|
|
},
|
|
"liveShare" : false,
|
|
"savedEvent" : true,
|
|
"description" : "ThousandEyes Test",
|
|
"type" : "agent-to-server",
|
|
"enabled" : true,
|
|
"createdDate" : "2022-07-17T22:00:54Z",
|
|
"createdBy" : "user@user.com",
|
|
"modifiedDate" : "2022-07-17T22:00:54Z",
|
|
"interval" : 60,
|
|
"modifiedBy" : "user@user.com",
|
|
"testId" : "281474976710706",
|
|
"alertsEnabled" : true,
|
|
"testName" : "ThousandEyes Test"
|
|
} ],
|
|
"_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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests"),
|
|
)
|
|
assert_constructed_model_matches_example_json(response, expected_response)
|
|
|
|
|
|
def test_get_tests_error_401(self) -> None:
|
|
"""Integration test for get_tests 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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="401"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_tests_error_403(self) -> None:
|
|
"""Integration test for get_tests 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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="403"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_tests_error_404(self) -> None:
|
|
"""Integration test for get_tests 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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="404"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_tests_error_429(self) -> None:
|
|
"""Integration test for get_tests 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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="429"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_tests_error_500(self) -> None:
|
|
"""Integration test for get_tests 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_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="500"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
def test_get_tests_error_502(self) -> None:
|
|
"""Integration test for get_tests error path (HTTP 502)"""
|
|
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(502)
|
|
) as context:
|
|
self.api.get_tests(
|
|
|
|
aid=aid,
|
|
|
|
_headers=self.te_headers("get_tests", error_status="502"),
|
|
)
|
|
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|