Beispiel #1
0
 def test_convert_json(self):
     parameter_api = {
         'name': 'name1',
         'schema': {'type': 'object',
                    'required': ['a', 'b'],
                    'properties':
                        {'a': {'type': 'number'},
                         'b': {'type': 'string'},
                         'c': {'type': 'boolean'}}}}
     value = {'a': '435.6', 'b': 'aaaa', 'c': 'true'}
     converted = convert_json(parameter_api, value, self.message)
     self.assertDictEqual(converted, {'a': 435.6, 'b': 'aaaa', 'c': True})
Beispiel #2
0
 def test_convert_primitive_array(self):
     parameter_api = {
         'name': 'name1',
         'schema': {
             'type': 'array',
             'items': {
                 'type': 'number'
             }
         }
     }
     value = ['1.3', '3.4', '555.1', '-132.2']
     converted = convert_json(parameter_api, value, self.message)
     self.assertListEqual(converted, [1.3, 3.4, 555.1, -132.2])
Beispiel #3
0
 def test_convert_json_invalid(self):
     parameter_api = {
         'name': 'name1',
         'schema': {
             'type': 'object',
             'required': ['a', 'b'],
             'properties': {
                 'a': {
                     'type': 'number'
                 },
                 'b': {
                     'type': 'string'
                 },
                 'c': {
                     'type': 'boolean'
                 }
             }
         }
     }
     value = {'a': '435.6', 'b': 'aaaa', 'c': 'invalid'}
     with self.assertRaises(InvalidArgument):
         convert_json(parameter_api, value, self.message)
Beispiel #4
0
 def test_convert_json_nested(self):
     parameter_api = {
         'name': 'name1',
         'schema': {'type': 'object',
                    'required': ['a', 'b'],
                    'properties':
                        {'a': {'type': 'number'},
                         'b': {'type': 'string'},
                         'c': {'type': 'object',
                               'properties': {'A': {'type': 'string'},
                                              'B': {'type': 'integer'}}}}}}
     value = {'a': '435.6', 'b': 'aaaa', 'c': {'A': 'string in', 'B': '3'}}
     converted = convert_json(parameter_api, value, self.message)
     self.assertDictEqual(converted, {'a': 435.6, 'b': 'aaaa', 'c': {'A': 'string in', 'B': 3}})
Beispiel #5
0
 def test_convert_object_array(self):
     parameter_api = {
         'name': 'name1',
         'schema': {'type': 'array',
                    'items': {
                        'type': 'object',
                        'properties': {'A': {'type': 'string'},
                                       'B': {'type': 'integer'}}}
                    }}
     value = [{'A': 'string in', 'B': '33'}, {'A': 'string2', 'B': '7'}]
     expected = [{'A': 'string in', 'B': 33}, {'A': 'string2', 'B': 7}]
     converted = convert_json(parameter_api, value, self.message)
     self.assertEqual(len(converted), len(expected))
     for i in range(len(converted)):
         self.assertDictEqual(converted[i], expected[i])
Beispiel #6
0
 def test_convert_object_array_unspecified_type(self):
     parameter_api = {'name': 'name1', 'schema': {'type': 'array'}}
     value = ['@action1', 2, {'a': 'v', 'b': 6}]
     expected = ['@action1', 2, {'a': 'v', 'b': 6}]
     converted = convert_json(parameter_api, value, self.message)
     self.assertListEqual(converted, expected)