# 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.alert_rules_api import AlertRulesApi
from .integration_test_utils import IntegrationTestBase
from .test_utils import assert_constructed_model_matches_example_json


class TestAlertRulesApiIntegration(IntegrationTestBase):
    """AlertRulesApi integration test stubs"""

    def setUp(self) -> None:
        super().setUp()
        self.api = AlertRulesApi(self.api_client)


    def test_create_alert_rule_happy_path(self) -> None:
        """Integration test for create_alert_rule success path"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        aid = '1234'
        response_body_json = """
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "_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"
                    }
                  },
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
                """
        expected_response = json.loads(response_body_json)
        response = self.api.create_alert_rule(

            rule_detail_update=rule_detail_update,

            aid=aid,

            _headers=self.te_headers("create_alert_rule"),
        )
        assert_constructed_model_matches_example_json(response, expected_response)


    def test_create_alert_rule_error_400(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 400)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="400"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_create_alert_rule_error_401(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 401)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="401"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_create_alert_rule_error_403(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 403)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="403"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_create_alert_rule_error_404(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 404)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="404"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_create_alert_rule_error_429(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 429)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="429"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_create_alert_rule_error_500(self) -> None:
        """Integration test for create_alert_rule error path (HTTP 500)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.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_alert_rule(

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("create_alert_rule", error_status="500"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)




    def test_delete_alert_rule_happy_path(self) -> None:
        """Integration test for delete_alert_rule success path"""
        rule_id = '127094'
        aid = '1234'
        response = self.api.delete_alert_rule_with_http_info(

            rule_id=rule_id,

            aid=aid,

            _headers=self.te_headers("delete_alert_rule"),
        )
        self.assertEqual(204, response.status_code)
        self.assertIsNone(response.data)


    def test_delete_alert_rule_error_400(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 400)"""
        rule_id = '127094'
        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_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="400"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_delete_alert_rule_error_401(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 401)"""
        rule_id = '127094'
        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_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="401"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_delete_alert_rule_error_403(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 403)"""
        rule_id = '127094'
        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.delete_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="403"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_delete_alert_rule_error_404(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 404)"""
        rule_id = '127094'
        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.delete_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="404"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_delete_alert_rule_error_429(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 429)"""
        rule_id = '127094'
        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.delete_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="429"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_delete_alert_rule_error_500(self) -> None:
        """Integration test for delete_alert_rule error path (HTTP 500)"""
        rule_id = '127094'
        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.delete_alert_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("delete_alert_rule", error_status="500"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)




    def test_get_alert_rule_happy_path(self) -> None:
        """Integration test for get_alert_rule success path"""
        rule_id = '127094'
        aid = '1234'
        response_body_json = """
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "_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"
                    }
                  },
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "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"
                  } ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
                """
        expected_response = json.loads(response_body_json)
        response = self.api.get_alert_rule(

            rule_id=rule_id,

            aid=aid,

            _headers=self.te_headers("get_alert_rule"),
        )
        assert_constructed_model_matches_example_json(response, expected_response)


    def test_get_alert_rule_error_401(self) -> None:
        """Integration test for get_alert_rule error path (HTTP 401)"""
        rule_id = '127094'
        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_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("get_alert_rule", error_status="401"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alert_rule_error_403(self) -> None:
        """Integration test for get_alert_rule error path (HTTP 403)"""
        rule_id = '127094'
        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_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("get_alert_rule", error_status="403"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alert_rule_error_404(self) -> None:
        """Integration test for get_alert_rule error path (HTTP 404)"""
        rule_id = '127094'
        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_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("get_alert_rule", error_status="404"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alert_rule_error_429(self) -> None:
        """Integration test for get_alert_rule error path (HTTP 429)"""
        rule_id = '127094'
        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_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("get_alert_rule", error_status="429"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alert_rule_error_500(self) -> None:
        """Integration test for get_alert_rule error path (HTTP 500)"""
        rule_id = '127094'
        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_rule(

                rule_id=rule_id,

                aid=aid,

                _headers=self.te_headers("get_alert_rule", error_status="500"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)




    def test_get_alerts_rules_happy_path(self) -> None:
        """Integration test for get_alerts_rules 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"
                    }
                  },
                  "alertRules" : [ {
                    "severity" : "major",
                    "expression" : "((hops((hopDelay >= 100 ms))))",
                    "alertType" : "http-server",
                    "includeCoveredPrefixes" : true,
                    "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                    "description" : "A rule description string",
                    "roundsViolatingMode" : "exact",
                    "sensitivityLevel" : "medium",
                    "alertGroupType" : "endpoint",
                    "notifyOnClear" : true,
                    "roundsViolatingOutOf" : 5,
                    "roundsViolatingRequired" : 2,
                    "isDefault" : true,
                    "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                    "minimumSourcesPct" : 99,
                    "ruleName" : "The End of the Internet",
                    "endpointLabelIds" : [ "123456", "123456" ],
                    "minimumSources" : 10,
                    "ruleId" : "127094",
                    "direction" : "to-target"
                  }, {
                    "severity" : "major",
                    "expression" : "((hops((hopDelay >= 100 ms))))",
                    "alertType" : "http-server",
                    "includeCoveredPrefixes" : true,
                    "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                    "description" : "A rule description string",
                    "roundsViolatingMode" : "exact",
                    "sensitivityLevel" : "medium",
                    "alertGroupType" : "endpoint",
                    "notifyOnClear" : true,
                    "roundsViolatingOutOf" : 5,
                    "roundsViolatingRequired" : 2,
                    "isDefault" : true,
                    "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                    "minimumSourcesPct" : 99,
                    "ruleName" : "The End of the Internet",
                    "endpointLabelIds" : [ "123456", "123456" ],
                    "minimumSources" : 10,
                    "ruleId" : "127094",
                    "direction" : "to-target"
                  } ]
                }
                """
        expected_response = json.loads(response_body_json)
        response = self.api.get_alerts_rules(

            aid=aid,

            _headers=self.te_headers("get_alerts_rules"),
        )
        assert_constructed_model_matches_example_json(response, expected_response)


    def test_get_alerts_rules_error_401(self) -> None:
        """Integration test for get_alerts_rules 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_alerts_rules(

                aid=aid,

                _headers=self.te_headers("get_alerts_rules", error_status="401"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alerts_rules_error_403(self) -> None:
        """Integration test for get_alerts_rules 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_alerts_rules(

                aid=aid,

                _headers=self.te_headers("get_alerts_rules", error_status="403"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alerts_rules_error_404(self) -> None:
        """Integration test for get_alerts_rules 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_alerts_rules(

                aid=aid,

                _headers=self.te_headers("get_alerts_rules", error_status="404"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alerts_rules_error_429(self) -> None:
        """Integration test for get_alerts_rules 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_alerts_rules(

                aid=aid,

                _headers=self.te_headers("get_alerts_rules", error_status="429"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_get_alerts_rules_error_500(self) -> None:
        """Integration test for get_alerts_rules 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_alerts_rules(

                aid=aid,

                _headers=self.te_headers("get_alerts_rules", error_status="500"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)




    def test_update_alert_rule_happy_path(self) -> None:
        """Integration test for update_alert_rule success path"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        aid = '1234'
        response_body_json = """
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "_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"
                    }
                  },
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
                """
        expected_response = json.loads(response_body_json)
        response = self.api.update_alert_rule(

            rule_id=rule_id,

            rule_detail_update=rule_detail_update,

            aid=aid,

            _headers=self.te_headers("update_alert_rule"),
        )
        assert_constructed_model_matches_example_json(response, expected_response)


    def test_update_alert_rule_error_400(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 400)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="400"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_update_alert_rule_error_401(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 401)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="401"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_update_alert_rule_error_403(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 403)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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.update_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="403"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_update_alert_rule_error_404(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 404)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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.update_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="404"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_update_alert_rule_error_429(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 429)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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.update_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="429"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)


    def test_update_alert_rule_error_500(self) -> None:
        """Integration test for update_alert_rule error path (HTTP 500)"""
        request_body_json = """
        
                {
                  "severity" : "major",
                  "expression" : "((hops((hopDelay >= 100 ms))))",
                  "alertType" : "http-server",
                  "includeCoveredPrefixes" : true,
                  "visitedSitesFilter" : [ "app.thousandeyes.com" ],
                  "description" : "A rule description string",
                  "roundsViolatingMode" : "exact",
                  "sensitivityLevel" : "medium",
                  "alertGroupType" : "endpoint",
                  "notifyOnClear" : true,
                  "testIds" : [ "281474976710706", "271659" ],
                  "roundsViolatingOutOf" : 5,
                  "roundsViolatingRequired" : 2,
                  "isDefault" : true,
                  "endpointAgentIds" : [ "281474976710706", "281474976710706" ],
                  "minimumSourcesPct" : 99,
                  "ruleName" : "The End of the Internet",
                  "endpointLabelIds" : [ "123456", "123456" ],
                  "minimumSources" : 10,
                  "ruleId" : "127094",
                  "notifications" : {
                    "thirdParty" : [ {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    }, {
                      "integrationType" : "slack",
                      "integrationId" : "sl-101"
                    } ],
                    "webhook" : [ {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "wb-201",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ],
                    "email" : {
                      "recipients" : [ "noreply@thousandeyes.com" ],
                      "message" : "Notification message"
                    },
                    "customWebhook" : [ {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    }, {
                      "integrationType" : "custom-webhook",
                      "integrationName" : "My webhook",
                      "integrationId" : "6e069ae9-8537-4120-b988-61bf8e0d8b87",
                      "target" : "https://example.com/test/webhooks/notifications"
                    } ]
                  },
                  "direction" : "to-target"
                }
        
                """
        rule_detail_update = thousandeyes_sdk.alerts.models.RuleDetailUpdate.from_json(request_body_json)
        rule_id = '127094'
        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.update_alert_rule(

                rule_id=rule_id,

                rule_detail_update=rule_detail_update,

                aid=aid,

                _headers=self.te_headers("update_alert_rule", error_status="500"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)






if __name__ == '__main__':
    unittest.main()
