1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
"""Customize generated code here.
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import Any, IO, Optional, Union, cast, overload, List, MutableMapping, Coroutine, BinaryIO, Awaitable
from azure.core.exceptions import (
ClientAuthenticationError,
HttpResponseError,
ResourceExistsError,
ResourceNotFoundError,
map_error,
)
from azure.core.tracing.decorator import distributed_trace
from azure.core.utils import case_insensitive_dict
from ._operations import AppComponentOperations as AppComponentOperationsGenerated
from ._operations import TestOperations as TestOperationsGenerated, JSON, ClsType
from ...operations._patch import build_upload_test_file_request
class TestOperations(TestOperationsGenerated):
"""
for performing the operations on test
"""
def __init__(self, *args, **kwargs):
super(TestOperations, self).__init__(*args, **kwargs)
async def upload_test_file(self, test_id: str, file_id: str, file: BinaryIO, **kwargs) -> JSON:
"""Upload test file and link it to a test.
Upload a test file to an existing test.
:param test_id: Unique id for the test
:type test_id: str
:param file_id: Unique id for the file
:type file_id: str
:param file_content: dictionary containing file contet
:type file: BinaryIO (file opened in Binary read mode)
:return: JSON object
:rtype: JSON
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
error_map.update(kwargs.pop("error_map", {}) or {})
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}
cls = kwargs.pop("cls", None) # type: ClsType[JSON]
_content = file
request = build_upload_test_file_request(
test_id=test_id,
file_id=file_id,
file=file,
api_version=self._config.api_version,
headers=_headers,
params=_params,
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments) # type: ignore
request.method = "PUT"
pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
request, stream=False, **kwargs
)
response = pipeline_response.http_response
if response.status_code not in [201]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if response.content:
deserialized = response.json()
else:
deserialized = None
if cls:
return cls(pipeline_response, cast(JSON, deserialized), {})
return cast(JSON, deserialized)
class AppComponentOperations:
def __init__(self, *args, **kwargs):
self.__app_component_operations_generated = AppComponentOperationsGenerated(*args, **kwargs)
async def get_app_components(
self,
*,
test_run_id: Optional[str] = None,
test_id: Optional[str] = None,
name: Optional[str] = None,
**kwargs: Any,
) -> MutableMapping[str, Any]:
"""Get App Components for a test or a test run by its name.
Get App Components for a test or a test run by its name.
:keyword test_run_id: [Required, if testId is not provided] Test run Id. Default value is None.
:paramtype test_run_id: st
:keyword test_id: Unique name for load test, must be a valid URL character ^[a-z0-9_-]*$.
Default value is None.
:paramtype test_id: str
:keyword name: Unique name of the App Component, must be a valid URL character ^[a-z0-9_-]*$.
Default value is None.
:paramtype name: str
:return: JSON object
:rtype: JSON
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# response body for status code(s): 200
response == {
"name": "str", # Optional. AppComponent name.
"resourceId": "str", # Optional. Azure Load Testing resource Id.
"testId": "str", # Optional. [Required, if testRunId is not given] Load test
unique identifier.
"testRunId": "str", # Optional. [Required if testId is not given] Load test
run unique identifier.
"value": {
"str": {
"displayName": "str", # Optional. Azure resource display
name.
"kind": "str", # Optional. Kind of Azure resource type.
"resourceGroup": "str", # Optional. Resource group name of
the Azure resource.
"resourceId": "str", # Fully qualified resource Id e.g
subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}.
Required.
"resourceName": "str", # Azure resource name. Required.
"resourceType": "str", # Azure resource type. Required.
"subscriptionId": "str" # Optional. Subscription Id of the
Azure resource.
}
}
}
"""
if name is not None:
return await self.__app_component_operations_generated.get_app_component_by_name(name=name, **kwargs)
else:
return await self.__app_component_operations_generated.get_app_component(
test_run_id=test_run_id, test_id=test_id, **kwargs
)
@overload
async def create_or_update_app_components(
self, name: str, body: JSON, *, content_type: str = "application/merge-patch+json", **kwargs: Any
) -> JSON:
"""Associate an App Component (Azure resource) to a test or test run.
Associate an App Component (Azure resource) to a test or test run.
:param name: Unique name of the App Component, must be a valid URL character ^[a-z0-9_-]*$.
Required.
:type name: str
:param body: App Component model. Required.
:type body: JSON
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/merge-patch+json".
:paramtype content_type: str
:return: JSON object
:rtype: JSON
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# JSON input template you can fill out and use as your body input.
body = {
"name": "str", # Optional. AppComponent name.
"resourceId": "str", # Optional. Azure Load Testing resource Id.
"testId": "str", # Optional. [Required, if testRunId is not given] Load test
unique identifier.
"testRunId": "str", # Optional. [Required if testId is not given] Load test
run unique identifier.
"value": {
"str": {
"displayName": "str", # Optional. Azure resource display
name.
"kind": "str", # Optional. Kind of Azure resource type.
"resourceGroup": "str", # Optional. Resource group name of
the Azure resource.
"resourceId": "str", # Fully qualified resource Id e.g
subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}.
Required.
"resourceName": "str", # Azure resource name. Required.
"resourceType": "str", # Azure resource type. Required.
"subscriptionId": "str" # Optional. Subscription Id of the
Azure resource.
}
}
}
# response body for status code(s): 200, 201
response == {
"name": "str", # Optional. AppComponent name.
"resourceId": "str", # Optional. Azure Load Testing resource Id.
"testId": "str", # Optional. [Required, if testRunId is not given] Load test
unique identifier.
"testRunId": "str", # Optional. [Required if testId is not given] Load test
run unique identifier.
"value": {
"str": {
"displayName": "str", # Optional. Azure resource display
name.
"kind": "str", # Optional. Kind of Azure resource type.
"resourceGroup": "str", # Optional. Resource group name of
the Azure resource.
"resourceId": "str", # Fully qualified resource Id e.g
subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}.
Required.
"resourceName": "str", # Azure resource name. Required.
"resourceType": "str", # Azure resource type. Required.
"subscriptionId": "str" # Optional. Subscription Id of the
Azure resource.
}
}
}
"""
@overload
async def create_or_update_app_components(
self, name: str, body: IO, *, content_type: str = "application/merge-patch+json", **kwargs: Any
) -> JSON:
"""Associate an App Component (Azure resource) to a test or test run.
Associate an App Component (Azure resource) to a test or test run.
:param name: Unique name of the App Component, must be a valid URL character ^[a-z0-9_-]*$.
Required.
:type name: str
:param body: App Component model. Required.
:type body: IO
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
Default value is "application/merge-patch+json".
:paramtype content_type: str
:return: JSON object
:rtype: JSON
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# response body for status code(s): 200, 201
response == {
"name": "str", # Optional. AppComponent name.
"resourceId": "str", # Optional. Azure Load Testing resource Id.
"testId": "str", # Optional. [Required, if testRunId is not given] Load test
unique identifier.
"testRunId": "str", # Optional. [Required if testId is not given] Load test
run unique identifier.
"value": {
"str": {
"displayName": "str", # Optional. Azure resource display
name.
"kind": "str", # Optional. Kind of Azure resource type.
"resourceGroup": "str", # Optional. Resource group name of
the Azure resource.
"resourceId": "str", # Fully qualified resource Id e.g
subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}.
Required.
"resourceName": "str", # Azure resource name. Required.
"resourceType": "str", # Azure resource type. Required.
"subscriptionId": "str" # Optional. Subscription Id of the
Azure resource.
}
}
}
"""
@distributed_trace
async def create_or_update_app_components(
self, name: str, body: Union[JSON, IO], **kwargs: Any
) -> MutableMapping[str, Any]:
"""Associate an App Component (Azure resource) to a test or test run.
Associate an App Component (Azure resource) to a test or test run.
:param name: Unique name of the App Component, must be a valid URL character ^[a-z0-9_-]*$.
Required.
:type name: str
:param body: App Component model. Is either a model type or a IO type. Required.
:type body: JSON or IO
:keyword content_type: Body Parameter content-type. Known values are:
'application/merge-patch+json'. Default value is None.
:paramtype content_type: str
:return: JSON object
:rtype: JSON
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# response body for status code(s): 200, 201
response == {
"name": "str", # Optional. AppComponent name.
"resourceId": "str", # Optional. Azure Load Testing resource Id.
"testId": "str", # Optional. [Required, if testRunId is not given] Load test
unique identifier.
"testRunId": "str", # Optional. [Required if testId is not given] Load test
run unique identifier.
"value": {
"str": {
"displayName": "str", # Optional. Azure resource display
name.
"kind": "str", # Optional. Kind of Azure resource type.
"resourceGroup": "str", # Optional. Resource group name of
the Azure resource.
"resourceId": "str", # Fully qualified resource Id e.g
subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.LoadTestService/loadtests/{resName}.
Required.
"resourceName": "str", # Azure resource name. Required.
"resourceType": "str", # Azure resource type. Required.
"subscriptionId": "str" # Optional. Subscription Id of the
Azure resource.
}
}
}
"""
return await self.__app_component_operations_generated.create_or_update_app_components(name, body, **kwargs)
@distributed_trace
async def delete_app_components( # pylint: disable=inconsistent-return-statements
self, name: str, **kwargs: Any
) -> None:
"""Delete an App Component.
Delete an App Component.
:param name: Unique name of the App Component, must be a valid URL character ^[a-z0-9_-]*$.
Required.
:type name: str
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
return await self.__app_component_operations_generated.delete_app_components(name, **kwargs)
__all__: List[str] = ["TestOperations", "AppComponentOperations"]
# Add all objects you want publicly available to users at this package level
def patch_sdk():
"""Do not remove from this file.
`patch_sdk` is a last resort escape hatch that allows you to do customizations
you can't accomplish using the techniques described in
https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
|