|
| 1 | +""" |
| 2 | +Create a multi-step api test with every type of basicAuth returns "OK - Returns the created test details." response |
| 3 | +""" |
| 4 | + |
| 5 | +from datadog_api_client import ApiClient, Configuration |
| 6 | +from datadog_api_client.v1.api.synthetics_api import SyntheticsApi |
| 7 | +from datadog_api_client.v1.model.synthetics_api_test import SyntheticsAPITest |
| 8 | +from datadog_api_client.v1.model.synthetics_api_test_config import SyntheticsAPITestConfig |
| 9 | +from datadog_api_client.v1.model.synthetics_api_test_step import SyntheticsAPITestStep |
| 10 | +from datadog_api_client.v1.model.synthetics_api_test_step_subtype import SyntheticsAPITestStepSubtype |
| 11 | +from datadog_api_client.v1.model.synthetics_api_test_type import SyntheticsAPITestType |
| 12 | +from datadog_api_client.v1.model.synthetics_assertion_operator import SyntheticsAssertionOperator |
| 13 | +from datadog_api_client.v1.model.synthetics_assertion_target import SyntheticsAssertionTarget |
| 14 | +from datadog_api_client.v1.model.synthetics_assertion_type import SyntheticsAssertionType |
| 15 | +from datadog_api_client.v1.model.synthetics_basic_auth_digest import SyntheticsBasicAuthDigest |
| 16 | +from datadog_api_client.v1.model.synthetics_basic_auth_digest_type import SyntheticsBasicAuthDigestType |
| 17 | +from datadog_api_client.v1.model.synthetics_basic_auth_ntlm import SyntheticsBasicAuthNTLM |
| 18 | +from datadog_api_client.v1.model.synthetics_basic_auth_ntlm_type import SyntheticsBasicAuthNTLMType |
| 19 | +from datadog_api_client.v1.model.synthetics_basic_auth_oauth_client import SyntheticsBasicAuthOauthClient |
| 20 | +from datadog_api_client.v1.model.synthetics_basic_auth_oauth_client_type import SyntheticsBasicAuthOauthClientType |
| 21 | +from datadog_api_client.v1.model.synthetics_basic_auth_oauth_rop import SyntheticsBasicAuthOauthROP |
| 22 | +from datadog_api_client.v1.model.synthetics_basic_auth_oauth_rop_type import SyntheticsBasicAuthOauthROPType |
| 23 | +from datadog_api_client.v1.model.synthetics_basic_auth_oauth_token_api_authentication import ( |
| 24 | + SyntheticsBasicAuthOauthTokenApiAuthentication, |
| 25 | +) |
| 26 | +from datadog_api_client.v1.model.synthetics_basic_auth_sigv4 import SyntheticsBasicAuthSigv4 |
| 27 | +from datadog_api_client.v1.model.synthetics_basic_auth_sigv4_type import SyntheticsBasicAuthSigv4Type |
| 28 | +from datadog_api_client.v1.model.synthetics_basic_auth_web import SyntheticsBasicAuthWeb |
| 29 | +from datadog_api_client.v1.model.synthetics_basic_auth_web_type import SyntheticsBasicAuthWebType |
| 30 | +from datadog_api_client.v1.model.synthetics_test_details_sub_type import SyntheticsTestDetailsSubType |
| 31 | +from datadog_api_client.v1.model.synthetics_test_options import SyntheticsTestOptions |
| 32 | +from datadog_api_client.v1.model.synthetics_test_request import SyntheticsTestRequest |
| 33 | + |
| 34 | +body = SyntheticsAPITest( |
| 35 | + config=SyntheticsAPITestConfig( |
| 36 | + steps=[ |
| 37 | + SyntheticsAPITestStep( |
| 38 | + assertions=[ |
| 39 | + SyntheticsAssertionTarget( |
| 40 | + operator=SyntheticsAssertionOperator.IS, |
| 41 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 42 | + target=200, |
| 43 | + ), |
| 44 | + ], |
| 45 | + name="request is sent", |
| 46 | + request=SyntheticsTestRequest( |
| 47 | + url="https://httpbin.org/status/200", |
| 48 | + method="GET", |
| 49 | + basic_auth=SyntheticsBasicAuthWeb( |
| 50 | + password="password", |
| 51 | + username="username", |
| 52 | + ), |
| 53 | + ), |
| 54 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 55 | + ), |
| 56 | + SyntheticsAPITestStep( |
| 57 | + assertions=[ |
| 58 | + SyntheticsAssertionTarget( |
| 59 | + operator=SyntheticsAssertionOperator.IS, |
| 60 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 61 | + target=200, |
| 62 | + ), |
| 63 | + ], |
| 64 | + name="request is sent", |
| 65 | + request=SyntheticsTestRequest( |
| 66 | + url="https://httpbin.org/status/200", |
| 67 | + method="GET", |
| 68 | + basic_auth=SyntheticsBasicAuthWeb( |
| 69 | + password="password", |
| 70 | + username="username", |
| 71 | + type=SyntheticsBasicAuthWebType.WEB, |
| 72 | + ), |
| 73 | + ), |
| 74 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 75 | + ), |
| 76 | + SyntheticsAPITestStep( |
| 77 | + assertions=[ |
| 78 | + SyntheticsAssertionTarget( |
| 79 | + operator=SyntheticsAssertionOperator.IS, |
| 80 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 81 | + target=200, |
| 82 | + ), |
| 83 | + ], |
| 84 | + name="request is sent", |
| 85 | + request=SyntheticsTestRequest( |
| 86 | + url="https://httpbin.org/status/200", |
| 87 | + method="GET", |
| 88 | + basic_auth=SyntheticsBasicAuthSigv4( |
| 89 | + access_key="accessKey", |
| 90 | + secret_key="secretKey", |
| 91 | + type=SyntheticsBasicAuthSigv4Type.SIGV4, |
| 92 | + ), |
| 93 | + ), |
| 94 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 95 | + ), |
| 96 | + SyntheticsAPITestStep( |
| 97 | + assertions=[ |
| 98 | + SyntheticsAssertionTarget( |
| 99 | + operator=SyntheticsAssertionOperator.IS, |
| 100 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 101 | + target=200, |
| 102 | + ), |
| 103 | + ], |
| 104 | + name="request is sent", |
| 105 | + request=SyntheticsTestRequest( |
| 106 | + url="https://httpbin.org/status/200", |
| 107 | + method="GET", |
| 108 | + basic_auth=SyntheticsBasicAuthNTLM( |
| 109 | + type=SyntheticsBasicAuthNTLMType.NTLM, |
| 110 | + ), |
| 111 | + ), |
| 112 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 113 | + ), |
| 114 | + SyntheticsAPITestStep( |
| 115 | + assertions=[ |
| 116 | + SyntheticsAssertionTarget( |
| 117 | + operator=SyntheticsAssertionOperator.IS, |
| 118 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 119 | + target=200, |
| 120 | + ), |
| 121 | + ], |
| 122 | + name="request is sent", |
| 123 | + request=SyntheticsTestRequest( |
| 124 | + url="https://httpbin.org/status/200", |
| 125 | + method="GET", |
| 126 | + basic_auth=SyntheticsBasicAuthDigest( |
| 127 | + password="password", |
| 128 | + username="username", |
| 129 | + type=SyntheticsBasicAuthDigestType.DIGEST, |
| 130 | + ), |
| 131 | + ), |
| 132 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 133 | + ), |
| 134 | + SyntheticsAPITestStep( |
| 135 | + assertions=[ |
| 136 | + SyntheticsAssertionTarget( |
| 137 | + operator=SyntheticsAssertionOperator.IS, |
| 138 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 139 | + target=200, |
| 140 | + ), |
| 141 | + ], |
| 142 | + name="request is sent", |
| 143 | + request=SyntheticsTestRequest( |
| 144 | + url="https://httpbin.org/status/200", |
| 145 | + method="GET", |
| 146 | + basic_auth=SyntheticsBasicAuthOauthClient( |
| 147 | + access_token_url="accessTokenUrl", |
| 148 | + token_api_authentication=SyntheticsBasicAuthOauthTokenApiAuthentication.HEADER, |
| 149 | + client_id="clientId", |
| 150 | + client_secret="clientSecret", |
| 151 | + type=SyntheticsBasicAuthOauthClientType.OAUTH_CLIENT, |
| 152 | + ), |
| 153 | + ), |
| 154 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 155 | + ), |
| 156 | + SyntheticsAPITestStep( |
| 157 | + assertions=[ |
| 158 | + SyntheticsAssertionTarget( |
| 159 | + operator=SyntheticsAssertionOperator.IS, |
| 160 | + type=SyntheticsAssertionType.STATUS_CODE, |
| 161 | + target=200, |
| 162 | + ), |
| 163 | + ], |
| 164 | + name="request is sent", |
| 165 | + request=SyntheticsTestRequest( |
| 166 | + url="https://httpbin.org/status/200", |
| 167 | + method="GET", |
| 168 | + basic_auth=SyntheticsBasicAuthOauthROP( |
| 169 | + access_token_url="accessTokenUrl", |
| 170 | + password="password", |
| 171 | + token_api_authentication=SyntheticsBasicAuthOauthTokenApiAuthentication.HEADER, |
| 172 | + username="username", |
| 173 | + type=SyntheticsBasicAuthOauthROPType.OAUTH_ROP, |
| 174 | + ), |
| 175 | + ), |
| 176 | + subtype=SyntheticsAPITestStepSubtype.HTTP, |
| 177 | + ), |
| 178 | + ], |
| 179 | + ), |
| 180 | + locations=[ |
| 181 | + "aws:us-east-2", |
| 182 | + ], |
| 183 | + message="BDD test payload: synthetics_api_test_multi_step_with_every_type_of_basic_auth.json", |
| 184 | + name="Example-Synthetic", |
| 185 | + options=SyntheticsTestOptions( |
| 186 | + tick_every=60, |
| 187 | + ), |
| 188 | + subtype=SyntheticsTestDetailsSubType.MULTI, |
| 189 | + type=SyntheticsAPITestType.API, |
| 190 | +) |
| 191 | + |
| 192 | +configuration = Configuration() |
| 193 | +with ApiClient(configuration) as api_client: |
| 194 | + api_instance = SyntheticsApi(api_client) |
| 195 | + response = api_instance.create_synthetics_api_test(body=body) |
| 196 | + |
| 197 | + print(response) |
0 commit comments