Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_required_optional_negative(self):
self.client.config.required_global_path = None
self.client.config.required_global_query = None
with self.assertRaises(ValidationError):
self.client.implicit.get_required_path(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_parameter(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_property(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_parameter(None)
def test_required_optional_negative(self):
self.client.config.required_global_path = None
self.client.config.required_global_query = None
with self.assertRaises(ValidationError):
self.client.implicit.get_required_path(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_parameter(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_property(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_parameter(None)
def test_required_optional_negative(self):
self.client.config.required_global_path = None
self.client.config.required_global_query = None
with self.assertRaises(ValidationError):
self.client.implicit.get_required_path(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_parameter(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_string_property(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_header(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_parameter(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_array_property(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_class_parameter(None)
with self.assertRaises(ValidationError):
self.client.explicit.post_required_class_property(None)
client = AutoRestParameterGroupingTestService(cred, base_url="http://localhost:3000")
# Valid required parameters
requiredParameters = ParameterGroupingPostRequiredParameters(body=bodyParameter, path=pathParameter, custom_header=headerParameter, query=queryParameter)
client.parameter_grouping.post_required(requiredParameters)
#Required parameters but null optional parameters
requiredParameters = ParameterGroupingPostRequiredParameters(body=bodyParameter, path=pathParameter, query=None)
client.parameter_grouping.post_required(requiredParameters)
#Required parameters object is not null, but a required property of the object is
requiredParameters = ParameterGroupingPostRequiredParameters(body = None, path = pathParameter)
with self.assertRaises(ValidationError):
client.parameter_grouping.post_required(requiredParameters)
with self.assertRaises(ValidationError):
client.parameter_grouping.post_required(None)
#Valid optional parameters
optionalParameters = ParameterGroupingPostOptionalParameters(custom_header = headerParameter, query = queryParameter)
client.parameter_grouping.post_optional(optionalParameters)
#null optional paramters
client.parameter_grouping.post_optional(None)
#Multiple grouped parameters
firstGroup = FirstParameterGroup(header_one = headerParameter, query_one = queryParameter)
secondGroup = ParameterGroupingPostMultiParamGroupsSecondParamGroup(header_two = "header2", query_two = 42)
client.parameter_grouping.post_multi_param_groups(firstGroup, secondGroup)
#Multiple grouped parameters -- some optional parameters omitted
cmd, registry_name, resource_group_name, REPLICATIONS_NOT_SUPPORTED)
normalized_location = "".join(location.split()).lower()
if registry.location == normalized_location:
raise CLIError('Replication could not be created in the same location as the registry.')
from msrest.exceptions import ValidationError
try:
return client.create(
resource_group_name=resource_group_name,
registry_name=registry_name,
replication_name=replication_name or normalized_location,
location=location,
tags=tags
)
except ValidationError as e:
raise CLIError(e)
# For error code, follow guidelines at https://docs.python.org/2/library/sys.html#sys.exit,
from jmespath.exceptions import JMESPathTypeError
from msrestazure.azure_exceptions import CloudError
from msrest.exceptions import HttpOperationError, ValidationError, ClientRequestError
from azure.cli.core.azlogging import CommandLoggerContext
with CommandLoggerContext(logger):
if isinstance(ex, JMESPathTypeError):
logger.error("\nInvalid jmespath query supplied for `--query`:\n%s", ex)
logger.error("To learn more about --query, please visit: "
"https://docs.microsoft.com/cli/azure/query-azure-cli?view=azure-cli-latest")
return 1
if isinstance(ex, (CLIError, CloudError, AzureException)):
logger.error(ex.args[0])
return ex.args[1] if len(ex.args) >= 2 else 1
if isinstance(ex, ValidationError):
logger.error('validation error: %s', ex)
return 1
if isinstance(ex, ClientRequestError):
msg = str(ex)
if 'SSLError' in msg:
logger.error("request failed: %s", SSLERROR_TEMPLATE.format(msg))
else:
logger.error("request failed: %s", ex)
return 1
if isinstance(ex, KeyboardInterrupt):
return 1
if isinstance(ex, HttpOperationError):
try:
response_dict = json.loads(ex.response.text)
error = response_dict['error']
# Otherwise handle based on return type of results
if isinstance(result, Paged):
return list(result)
return result
except BatchErrorException as ex:
try:
message = ex.error.message.value
if ex.error.values:
for detail in ex.error.values:
message += "\n{}: {}".format(detail.key, detail.value)
raise CLIError(message)
except AttributeError:
raise CLIError(ex)
except (ValidationError, ClientRequestError) as ex:
raise CLIError(ex)
def netapp_exception_handler(ex):
if isinstance(ex, (CloudError, ValidationError, ValueError)):
message = ex
raise CLIError(message)
else:
import sys
from six import reraise
reraise(*sys.exc_info())
def body(self, data, data_type, **kwargs):
"""Serialize data intended for a request body.
:param data: The data to be serialized.
:param str data_type: The type to be serialized from.
:rtype: dict
:raises: SerializationError if serialization fails.
:raises: ValueError if data is None
"""
if data is None:
raise ValidationError("required", "body", True)
# Just in case this is a dict
internal_data_type = data_type.strip('[]{}')
internal_data_type = self.dependencies.get(internal_data_type, None)
try:
is_xml_model_serialization = kwargs["is_xml"]
except KeyError:
if internal_data_type and issubclass(internal_data_type, Model):
is_xml_model_serialization = kwargs.setdefault("is_xml", internal_data_type.is_xml_model())
else:
is_xml_model_serialization = False
if internal_data_type and not isinstance(internal_data_type, Enum):
try:
deserializer = Deserializer(self.dependencies)
# Since it's on serialization, it's almost sure that format is not JSON REST
# We're not able to deal with additional properties for now.
def batch_exception_handler(ex):
from msrest.exceptions import ValidationError, ClientRequestError
from msrestazure.azure_exceptions import CloudError
from azure.batch.models import BatchErrorException
if isinstance(ex, BatchErrorException):
try:
message = ex.error.message.value
if ex.error.values:
for detail in ex.error.values:
message += "\n{}: {}".format(detail.key, detail.value)
raise CLIError(message)
except AttributeError:
raise CLIError(ex)
elif isinstance(ex, (ValidationError, ClientRequestError)):
raise CLIError(ex)
elif isinstance(ex, CloudError):
raise CLIError(ex)
else:
import sys
from six import reraise
reraise(*sys.exc_info())