# coding: utf-8

"""
    Endpoint Instant Scheduled Tests API

    You can create and execute a new endpoint instant scheduled test within ThousandEyes using this API. The test parameters are specified in the `POST` data.  The following applies to the Endpoint Instant Scheduled Tests API:  * To initiate the creation and execution of an instant scheduled test, the user must possess the `Edit endpoint tests` permission.  * Upon successful creation of an instant scheduled test, the API responds with an HTTP/201 CREATED status code and return the test definition. * It's important to note that the response does not include the results of the instant scheduled test. To retrieve test results, users can utilize the Endpoint Test Data endpoints. The URLs for these API test data endpoints are provided within the test definition output when an instant scheduled test is created. 

    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


import json
import unittest
import thousandeyes_sdk.endpoint_instant_tests.models

from thousandeyes_sdk.core.exceptions import ApiException
from thousandeyes_sdk.endpoint_instant_tests.api.run_endpoint_instant_scheduled_tests_api import RunEndpointInstantScheduledTestsApi
from .integration_test_utils import IntegrationTestBase
from .test_utils import assert_constructed_model_matches_example_json


class TestRunEndpointInstantScheduledTestsApiIntegration(IntegrationTestBase):
    """RunEndpointInstantScheduledTestsApi integration test stubs"""

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


    def test_run_endpoint_scheduled_instant_test_happy_path(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test success path"""
        test_id = '765231567'
        aid = '1234'
        response_body_json = """
                {
                  "message" : "Successfully reran the instant scheduled test with testId=765231567"
                }
                """
        expected_response = json.loads(response_body_json)
        response = self.api.run_endpoint_scheduled_instant_test(

            test_id=test_id,

            aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_400(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 400)"""
        test_id = '765231567'
        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.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_401(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 401)"""
        test_id = '765231567'
        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.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_403(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 403)"""
        test_id = '765231567'
        aid = '1234'
        error_body_json = """
                {
                  "instance" : "instance",
                  "detail" : "detail",
                  "type" : "type",
                  "title" : "title",
                  "status" : 6
                }
                """
        expected_error = json.loads(error_body_json)
        with self.assertRaises(
            ApiException.exception_class_for_http_status(403)
        ) as context:
            self.api.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_404(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 404)"""
        test_id = '765231567'
        aid = '1234'
        error_body_json = """
                {
                  "instance" : "instance",
                  "detail" : "detail",
                  "type" : "type",
                  "title" : "title",
                  "status" : 6
                }
                """
        expected_error = json.loads(error_body_json)
        with self.assertRaises(
            ApiException.exception_class_for_http_status(404)
        ) as context:
            self.api.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_429(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 429)"""
        test_id = '765231567'
        aid = '1234'
        error_body_json = """
                {
                  "instance" : "instance",
                  "detail" : "detail",
                  "type" : "type",
                  "title" : "title",
                  "status" : 6
                }
                """
        expected_error = json.loads(error_body_json)
        with self.assertRaises(
            ApiException.exception_class_for_http_status(429)
        ) as context:
            self.api.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_500(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 500)"""
        test_id = '765231567'
        aid = '1234'
        error_body_json = """
                {
                  "instance" : "instance",
                  "detail" : "detail",
                  "type" : "type",
                  "title" : "title",
                  "status" : 6
                }
                """
        expected_error = json.loads(error_body_json)
        with self.assertRaises(
            ApiException.exception_class_for_http_status(500)
        ) as context:
            self.api.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

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


    def test_run_endpoint_scheduled_instant_test_error_502(self) -> None:
        """Integration test for run_endpoint_scheduled_instant_test error path (HTTP 502)"""
        test_id = '765231567'
        aid = '1234'
        error_body_json = """
                {
                  "instance" : "instance",
                  "detail" : "detail",
                  "type" : "type",
                  "title" : "title",
                  "status" : 6
                }
                """
        expected_error = json.loads(error_body_json)
        with self.assertRaises(
            ApiException.exception_class_for_http_status(502)
        ) as context:
            self.api.run_endpoint_scheduled_instant_test(

                test_id=test_id,

                aid=aid,

                _headers=self.te_headers("run_endpoint_scheduled_instant_test", error_status="502"),
            )
        assert_constructed_model_matches_example_json(context.exception.data, expected_error)






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