Esempio n. 1
0
    def test_empty_values_not_added(self):
        m = model.DenormalizedStructureBuilder().with_members({
            'A': {'type': 'boolean'},
        }).build_model()
        b = shorthand.BackCompatVisitor()

        params = {}
        b.visit(params, m)
        self.assertEqual(params, {})
Esempio n. 2
0
    def test_promote_to_list_of_ints(self):
        m = model.DenormalizedStructureBuilder().with_members({
            'A': {
                'type': 'array',
                'items': {'type': 'string'}
            },
        }).build_model()
        b = shorthand.BackCompatVisitor()

        params = {'A': 'foo'}
        b.visit(params, m)
        self.assertEqual(params, {'A': ['foo']})
Esempio n. 3
0
 def test_can_convert_map_of_integers(self):
     m = model.DenormalizedStructureBuilder().with_members({
         'A': {
             'type': 'object',
             'additionalProperties': {
                 'type': 'integer'
             },
         },
     }).build_model()
     b = shorthand.BackCompatVisitor()
     params = {'A': {'key': '1'}}
     b.visit(params, m)
     # We should have converted each map value to an integer
     # because the type of the value member is integer.
     self.assertEqual(params, {'A': {'key': 1}})
Esempio n. 4
0
 def test_can_convert_list_of_integers(self):
     m = model.DenormalizedStructureBuilder().with_members({
         'A': {
             'type': 'array',
             'items': {
                 'type': 'integer',
             },
         },
     }).build_model()
     b = shorthand.BackCompatVisitor()
     params = {'A': ['1', '2']}
     b.visit(params, m)
     # We should have converted each list element to an integer
     # because the type of the list member is integer.
     self.assertEqual(params, {'A': [1, 2]})
Esempio n. 5
0
 def test_dont_promote_list_if_none_value(self):
     m = model.DenormalizedStructureBuilder().with_members({
         'A': {
             'type': 'array',
             'items': {
                 'type': 'object',
                 'properties': {
                     'Single': {'type': 'string'}
                 },
             },
         },
     }).build_model()
     b = shorthand.BackCompatVisitor()
     params = {}
     b.visit(params, m)
     self.assertEqual(params, {})
Esempio n. 6
0
    def test_can_convert_scalar_types_from_string(self):
        m = model.DenormalizedStructureBuilder().with_members({
            'A': {'type': 'integer'},
            'B': {'type': 'string'},
            'C': {'type': 'float'},
            'D': {'type': 'boolean'},
            'E': {'type': 'boolean'},
            'F': {'type': 'blob'},
        }).build_model()
        b = shorthand.BackCompatVisitor()

        params = {'A': '24', 'B': '24', 'C': '24.12345',
                  'D': 'true', 'E': 'false',
                  'F': 'SGVsbG8gV29ybGQ='}
        b.visit(params, m)
        self.assertEqual(
            params,
            {'A': 24, 'B': '24', 'C': float('24.12345'),
             'D': True, 'E': False,
             'F': 'SGVsbG8gV29ybGQ='})