How to use the msrest.exceptions.DeserializationError function in msrest

To help you get started, we’ve selected a few msrest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / datetime_tests.py View on Github external
with self.assertRaises(DeserializationError):
            client.datetime_model.get_local_negative_offset_uppercase_max_date_time()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_local_positive_offset_min_date_time()

        client.datetime_model.get_local_positive_offset_lowercase_max_date_time()
        client.datetime_model.get_local_positive_offset_uppercase_max_date_time()

        client.datetime_model.get_null()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_overflow()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_invalid()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_underflow()

        client.datetime_model.put_utc_max_date_time(max_date)
        client.datetime_model.put_utc_min_date_time(min_date)

        with self.assertRaises(SerializationError):
            client.datetime_model.put_local_positive_offset_min_date_time(
                isodate.parse_datetime("0001-01-01T00:00:00+14:00"))

        client.datetime_model.put_local_negative_offset_min_date_time(
            isodate.parse_datetime("0001-01-01T00:00:00-14:00"))

        with self.assertRaises(SerializationError):
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / datetime_rfc_tests.py View on Github external
def test_datetime_rfc(self):
        client = AutoRestRFC1123DateTimeTestService(base_url="http://localhost:3000")

        self.assertIsNone(client.datetimerfc1123.get_null())

        with self.assertRaises(DeserializationError):
            client.datetimerfc1123.get_invalid()

        with self.assertRaises(DeserializationError):
            client.datetimerfc1123.get_underflow()

        with self.assertRaises(DeserializationError):
            client.datetimerfc1123.get_overflow()

        client.datetimerfc1123.get_utc_lowercase_max_date_time()
        client.datetimerfc1123.get_utc_uppercase_max_date_time()
        client.datetimerfc1123.get_utc_min_date_time()

        max_date = isodate.parse_datetime("9999-12-31T23:59:59.999999Z")
        client.datetimerfc1123.put_utc_max_date_time(max_date)

        min_date = isodate.parse_datetime("0001-01-01T00:00:00Z")
        client.datetimerfc1123.put_utc_min_date_time(min_date)
github Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / complex_tests.py View on Github external
# GET basic/empty
        basic_result = client.basic.get_empty()
        self.assertIsNone(basic_result.id)
        self.assertIsNone(basic_result.name)

        # GET basic/null
        basic_result = client.basic.get_null()
        self.assertIsNone(basic_result.id)
        self.assertIsNone(basic_result.name)

        # GET basic/notprovided
        basic_result = client.basic.get_not_provided()
        self.assertIsNone(basic_result)

        # GET basic/invalid
        with self.assertRaises(DeserializationError):
            client.basic.get_invalid()

        """
        COMPLEX TYPE WITH PRIMITIVE PROPERTIES
        """
        # GET primitive/integer
        intResult = client.primitive.get_int();
        self.assertEqual(-1, intResult.field1)
        self.assertEqual(2, intResult.field2)

        # PUT primitive/integer
        intRequest = {'field1':-1, 'field2':2}
        client.primitive.put_int(intRequest)

        # GET primitive/long
        longResult = client.primitive.get_long();
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / dictionary_tests.py View on Github external
int_null_dict = {"0":1, "1":None, "2":0}
        self.assertEqual(int_null_dict, self.client.dictionary.get_int_invalid_null())
        
        with self.assertRaises(DeserializationError):
            self.client.dictionary.get_int_invalid_string()
        
        long_valid = {"0":1, "1":-1, "2":3, "3":300}
        self.assertEqual(long_valid, self.client.dictionary.get_long_valid())

        self.client.dictionary.put_long_valid(long_valid)

        long_null_dict = {"0":1, "1":None, "2":0}
        self.assertEqual(long_null_dict, self.client.dictionary.get_long_invalid_null())

        with self.assertRaises(DeserializationError):
            self.client.dictionary.get_long_invalid_string()

        float_valid = {"0":0, "1":-0.01, "2":-1.2e20}
        self.assertEqual(float_valid, self.client.dictionary.get_float_valid())

        self.client.dictionary.put_float_valid(float_valid)

        float_null_dict = {"0":0.0, "1":None, "2":-1.2e20}
        self.assertEqual(float_null_dict, self.client.dictionary.get_float_invalid_null())

        with self.assertRaises(DeserializationError):
            self.client.dictionary.get_float_invalid_string()

        double_valid = {"0":0, "1":-0.01, "2":-1.2e20}
        self.assertEqual(double_valid, self.client.dictionary.get_double_valid())
github Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / number_tests.py View on Github external
client.number.get_null()
        self.assertEqual(client.number.get_big_float(), 3.402823e+20)
        self.assertEqual(client.number.get_small_float(), 3.402823e-20)
        self.assertEqual(client.number.get_big_double(), 2.5976931e+101)
        self.assertEqual(client.number.get_small_double(), 2.5976931e-101)
        self.assertEqual(client.number.get_big_double_negative_decimal(), -99999999.99)
        self.assertEqual(client.number.get_big_double_positive_decimal(), 99999999.99)
        self.assertEqual(client.number.get_big_decimal(), 2.5976931e+101)
        self.assertEqual(client.number.get_small_decimal(), 2.5976931e-101)
        self.assertEqual(client.number.get_big_decimal_negative_decimal(), -99999999.99)
        self.assertEqual(client.number.get_big_decimal_positive_decimal(), 99999999.99)

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_decimal()

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_double()

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_float()
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / datetime_tests.py View on Github external
max_date = isodate.parse_datetime("9999-12-31T23:59:59.999999Z")
        min_date = isodate.parse_datetime("0001-01-01T00:00:00Z")

        dt = client.datetime_model.get_utc_lowercase_max_date_time()
        self.assertEqual(dt, max_date)
        dt = client.datetime_model.get_utc_uppercase_max_date_time()
        self.assertEqual(dt, max_date)
        dt = client.datetime_model.get_utc_min_date_time()
        self.assertEqual(dt, min_date)

        client.datetime_model.get_local_negative_offset_min_date_time()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_local_negative_offset_lowercase_max_date_time()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_local_negative_offset_uppercase_max_date_time()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_local_positive_offset_min_date_time()

        client.datetime_model.get_local_positive_offset_lowercase_max_date_time()
        client.datetime_model.get_local_positive_offset_uppercase_max_date_time()

        client.datetime_model.get_null()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_overflow()

        with self.assertRaises(DeserializationError):
            client.datetime_model.get_invalid()
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / number_tests.py View on Github external
self.assertEqual(client.number.get_big_double(), 2.5976931e+101)
        self.assertEqual(client.number.get_small_double(), 2.5976931e-101)
        self.assertEqual(client.number.get_big_double_negative_decimal(), -99999999.99)
        self.assertEqual(client.number.get_big_double_positive_decimal(), 99999999.99)
        self.assertEqual(client.number.get_big_decimal(), 2.5976931e+101)
        self.assertEqual(client.number.get_small_decimal(), 2.5976931e-101)
        self.assertEqual(client.number.get_big_decimal_negative_decimal(), -99999999.99)
        self.assertEqual(client.number.get_big_decimal_positive_decimal(), 99999999.99)

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_decimal()

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_double()

        with self.assertRaises(DeserializationError):
            client.number.get_invalid_float()
github Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / integer_tests.py View on Github external
def test_integer(self):
        client = AutoRestIntegerTestService(base_url="http://localhost:3000")

        client.int_model.put_max32(2147483647) # sys.maxint
        client.int_model.put_min32(-2147483648)

        client.int_model.put_max64(9223372036854776000)  # sys.maxsize
        client.int_model.put_min64(-9223372036854776000)
        client.int_model.get_null()

        with self.assertRaises(DeserializationError):
            client.int_model.get_invalid()

        # These wont fail in Python
        #client.int_model.get_overflow_int32()
        #client.int_model.get_overflow_int64()
        #client.int_model.get_underflow_int32()
        #client.int_model.get_underflow_int64()

        unix_date = datetime(year=2016, month=4, day=13)
        client.int_model.put_unix_time_date(unix_date)
        self.assertEqual(unix_date.utctimetuple(), client.int_model.get_unix_time().utctimetuple())
        self.assertIsNone(client.int_model.get_null_unix_time())

        with self.assertRaises(DeserializationError):
            client.int_model.get_invalid_unix_time()
github Azure / azure-sdk-for-java / ClientRuntimes / Python / msrestazure / msrestazure / azure_operation.py View on Github external
def _is_empty(self, response):
        """Check if response body contains meaningful content.

        :rtype: bool
        :raises: DeserializationError if response body contains invalid
         json data.
        """
        if not response.content:
            return True
        try:
            body = response.json()
            return not body
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / batch / custom.py View on Github external
def create_task(client,
                job_id, json_file=None, task_id=None, command_line=None, resource_files=None,
                environment_settings=None, affinity_id=None, max_wall_clock_time=None,
                retention_time=None, max_task_retry_count=None,
                application_package_references=None):
    task = None
    tasks = []
    if json_file:
        json_obj = get_file_json(json_file)
        try:
            task = TaskAddParameter.from_dict(json_obj)
        except (DeserializationError, TypeError):
            try:
                task_collection = TaskAddCollectionParameter.from_dict(json_obj)
                tasks = task_collection.value
            except (DeserializationError, TypeError):
                try:
                    for json_task in json_obj:
                        tasks.append(TaskAddParameter.from_dict(json_task))
                except (DeserializationError, TypeError):
                    raise ValueError("JSON file '{}' is not formatted correctly.".format(json_file))
    else:
        if command_line is None or task_id is None:
            raise ValueError("Missing required arguments.\nEither --json-file, "
                             "or both --task-id and --command-line must be specified.")
        task = TaskAddParameter(
            id=task_id,
            command_line=command_line,