mirror of
https://github.com/thousandeyes/thousandeyes-sdk-python.git
synced 2026-08-04 00:46:52 +00:00
681 lines
24 KiB
Python
681 lines
24 KiB
Python
# coding: utf-8
|
||
|
||
"""
|
||
Alerts API
|
||
|
||
**Note:** API operations for the creation or retrieval of API, Page Load, or Web-Transaction alert rules are not available for ThousandEyes for Government instance. You can manage the following alert functionalities on the ThousandEyes platform using the Alerts API: * **Alerts**: Retrieve alert details. Alerts are assigned to tests through alert rules. * **Alert Rules**: Conditions that you configure in order to highlight or be notified of events of interest in your ThousandEyes tests. When an alert rule’s conditions are met, the associated alert is triggered and the alert becomes active. It remains active until the alert is cleared. Alert rules are reusable across multiple tests.. * **Alert Suppression Windows**: Suppress alerts for tests during periods such as planned maintenance. Windows can be one-time events or recurring events to handle periodic occurrences such as monthly downtime for maintenance. For more information about the alerts, see [Alerts](https://docs.thousandeyes.com/product-documentation/alerts).
|
||
|
||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||
|
||
Do not edit the class manually.
|
||
""" # noqa: E501
|
||
|
||
|
||
import json
|
||
import unittest
|
||
import thousandeyes_sdk.alerts.models
|
||
|
||
from thousandeyes_sdk.core.exceptions import ApiException
|
||
from thousandeyes_sdk.alerts.api.alerts_api import AlertsApi
|
||
from .integration_test_utils import IntegrationTestBase
|
||
from .test_utils import assert_constructed_model_matches_example_json
|
||
|
||
|
||
class TestAlertsApiIntegration(IntegrationTestBase):
|
||
"""AlertsApi integration test stubs"""
|
||
|
||
def setUp(self) -> None:
|
||
super().setUp()
|
||
self.api = AlertsApi(self.api_client)
|
||
|
||
|
||
def test_get_alert_happy_path(self) -> None:
|
||
"""Integration test for get_alert success path"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
aid = '1234'
|
||
response_body_json = """
|
||
{
|
||
"severity" : "major",
|
||
"alertType" : "http-server",
|
||
"endDate" : "2022-07-18T22:00:54Z",
|
||
"_links" : {
|
||
"appLink" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"test" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"rule" : {
|
||
"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"
|
||
}
|
||
},
|
||
"alertSeverity" : "major",
|
||
"duration" : 60,
|
||
"violationCount" : 2,
|
||
"_embedded" : {
|
||
"asn" : {
|
||
"name" : "Cisco Webex LLC",
|
||
"id" : "13445",
|
||
"type" : "asn"
|
||
}
|
||
},
|
||
"meta" : {
|
||
"version" : 1
|
||
},
|
||
"details" : [ {
|
||
"name" : "Bucharest, Romania",
|
||
"start" : {
|
||
"metrics" : "metrics"
|
||
},
|
||
"end" : {
|
||
"metrics" : "metrics"
|
||
},
|
||
"id" : "3379",
|
||
"state" : "trigger",
|
||
"type" : "cea_agent"
|
||
}, {
|
||
"name" : "Bucharest, Romania",
|
||
"start" : {
|
||
"metrics" : "metrics"
|
||
},
|
||
"end" : {
|
||
"metrics" : "metrics"
|
||
},
|
||
"id" : "3379",
|
||
"state" : "trigger",
|
||
"type" : "cea_agent"
|
||
} ],
|
||
"id" : "e9c3bf02-a48c-4aa8-9e5f-898800d6f569",
|
||
"suppressed" : false,
|
||
"state" : "trigger",
|
||
"alertState" : "trigger",
|
||
"startDate" : "2022-07-17T22:00:54Z"
|
||
}
|
||
"""
|
||
expected_response = json.loads(response_body_json)
|
||
response = self.api.get_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert"),
|
||
)
|
||
assert_constructed_model_matches_example_json(response, expected_response)
|
||
|
||
|
||
def test_get_alert_error_401(self) -> None:
|
||
"""Integration test for get_alert error path (HTTP 401)"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
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_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert", error_status="401"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alert_error_403(self) -> None:
|
||
"""Integration test for get_alert error path (HTTP 403)"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
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_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert", error_status="403"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alert_error_404(self) -> None:
|
||
"""Integration test for get_alert error path (HTTP 404)"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
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_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert", error_status="404"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alert_error_429(self) -> None:
|
||
"""Integration test for get_alert error path (HTTP 429)"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
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_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert", error_status="429"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alert_error_500(self) -> None:
|
||
"""Integration test for get_alert error path (HTTP 500)"""
|
||
alert_id = 'e9c3bf02-a48c-4aa8-9e5f-898800d6f569'
|
||
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_alert(
|
||
|
||
alert_id=alert_id,
|
||
|
||
aid=aid,
|
||
|
||
_headers=self.te_headers("get_alert", error_status="500"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
|
||
|
||
def test_get_alerts_happy_path(self) -> None:
|
||
"""Integration test for get_alerts success path"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
cursor = 'cursor_example'
|
||
response_body_json = """
|
||
{
|
||
"alerts" : [ {
|
||
"severity" : "MAJOR",
|
||
"alertType" : "http-server",
|
||
"endDate" : "2022-07-18T22:00:54Z",
|
||
"_links" : {
|
||
"appLink" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"test" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"rule" : {
|
||
"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"
|
||
}
|
||
},
|
||
"apiLinks" : [ {
|
||
"key" : ""
|
||
}, {
|
||
"key" : ""
|
||
} ],
|
||
"alertSeverity" : "major",
|
||
"dateEnd" : "2020-04-23 13:43:16",
|
||
"duration" : 60,
|
||
"violationCount" : 2,
|
||
"dateStart" : "2020-04-23 13:43:16",
|
||
"meta" : {
|
||
"version" : 1
|
||
},
|
||
"id" : "e9c3bf02-a48c-4aa8-9e5f-898800d6f569",
|
||
"suppressed" : false,
|
||
"alertId" : "e9c3bf02-a48c-4aa8-9e5f-898800d6f569",
|
||
"state" : "ACTIVE",
|
||
"ruleId" : 127094,
|
||
"permalink" : "https://app.thousandeyes.com/alerts/list?__a=75&alertId=2783&agentId=12",
|
||
"alertState" : "trigger",
|
||
"startDate" : "2022-07-17T22:00:54Z",
|
||
"alertRuleId" : "127094"
|
||
}, {
|
||
"severity" : "MAJOR",
|
||
"alertType" : "http-server",
|
||
"endDate" : "2022-07-18T22:00:54Z",
|
||
"_links" : {
|
||
"appLink" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"test" : {
|
||
"hreflang" : "hreflang",
|
||
"templated" : true,
|
||
"profile" : "profile",
|
||
"name" : "name",
|
||
"href" : "https://api.thousandeyes.com/v7/link/to/resource/id",
|
||
"type" : "type",
|
||
"deprecation" : "deprecation",
|
||
"title" : "title"
|
||
},
|
||
"rule" : {
|
||
"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"
|
||
}
|
||
},
|
||
"apiLinks" : [ {
|
||
"key" : ""
|
||
}, {
|
||
"key" : ""
|
||
} ],
|
||
"alertSeverity" : "major",
|
||
"dateEnd" : "2020-04-23 13:43:16",
|
||
"duration" : 60,
|
||
"violationCount" : 2,
|
||
"dateStart" : "2020-04-23 13:43:16",
|
||
"meta" : {
|
||
"version" : 1
|
||
},
|
||
"id" : "e9c3bf02-a48c-4aa8-9e5f-898800d6f569",
|
||
"suppressed" : false,
|
||
"alertId" : "e9c3bf02-a48c-4aa8-9e5f-898800d6f569",
|
||
"state" : "ACTIVE",
|
||
"ruleId" : 127094,
|
||
"permalink" : "https://app.thousandeyes.com/alerts/list?__a=75&alertId=2783&agentId=12",
|
||
"alertState" : "trigger",
|
||
"startDate" : "2022-07-17T22:00:54Z",
|
||
"alertRuleId" : "127094"
|
||
} ],
|
||
"_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"
|
||
}
|
||
}
|
||
}
|
||
"""
|
||
expected_response = json.loads(response_body_json)
|
||
response = self.api.get_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts"),
|
||
)
|
||
assert_constructed_model_matches_example_json(response, expected_response)
|
||
|
||
|
||
def test_get_alerts_error_401(self) -> None:
|
||
"""Integration test for get_alerts error path (HTTP 401)"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
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_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts", error_status="401"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alerts_error_403(self) -> None:
|
||
"""Integration test for get_alerts error path (HTTP 403)"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
cursor = 'cursor_example'
|
||
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_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts", error_status="403"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alerts_error_404(self) -> None:
|
||
"""Integration test for get_alerts error path (HTTP 404)"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
cursor = 'cursor_example'
|
||
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_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts", error_status="404"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alerts_error_429(self) -> None:
|
||
"""Integration test for get_alerts error path (HTTP 429)"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
cursor = 'cursor_example'
|
||
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_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts", error_status="429"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
def test_get_alerts_error_500(self) -> None:
|
||
"""Integration test for get_alerts error path (HTTP 500)"""
|
||
aid = '1234'
|
||
window = '12h'
|
||
start_date = '2022-07-17T22:00:54Z'
|
||
end_date = '2022-07-18T22:00:54Z'
|
||
max = 5
|
||
cursor = 'cursor_example'
|
||
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_alerts(
|
||
|
||
aid=aid,
|
||
|
||
window=window,
|
||
|
||
start_date=start_date,
|
||
|
||
end_date=end_date,
|
||
|
||
max=max,
|
||
|
||
cursor=cursor,
|
||
|
||
_headers=self.te_headers("get_alerts", error_status="500"),
|
||
)
|
||
assert_constructed_model_matches_example_json(context.exception.data, expected_error)
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == '__main__':
|
||
unittest.main()
|