Esempio n. 1
0
    def test_field2property_nested(self):
        category = fields.Nested(CategorySchema)
        assert swagger.field2property(category) == swagger.schema2jsonschema(
            CategorySchema)

        cat_with_ref = fields.Nested(CategorySchema, ref='Category')
        assert swagger.field2property(cat_with_ref) == {'$ref': 'Category'}
Esempio n. 2
0
    def test_field2property_nested_many(self):
        categories = fields.Nested(CategorySchema, many=True)
        res = swagger.field2property(categories)
        assert res['type'] == 'array'
        assert res['items'] == swagger.schema2jsonschema(CategorySchema)

        cats_with_ref = fields.Nested(CategorySchema,
                                      many=True,
                                      ref='Category')
        res = swagger.field2property(cats_with_ref)
        assert res['type'] == 'array'
        assert res['items'] == {'$ref': 'Category'}
Esempio n. 3
0
 def test_field_with_additional_metadata(self):
     field = fields.Str(minLength=6, maxLength=100)
     res = swagger.field2property(field)
     assert res['maxLength'] == 100
     assert res['minLength'] == 6
Esempio n. 4
0
 def test_field_with_default(self):
     field = fields.Str(default='foo')
     res = swagger.field2property(field)
     assert res['default'] == 'foo'
Esempio n. 5
0
 def test_field_with_description(self):
     field = fields.Str(description='a username')
     res = swagger.field2property(field)
     assert res['description'] == 'a username'
Esempio n. 6
0
 def test_field2property_formats(self, FieldClass, expected_format):
     field = FieldClass()
     res = swagger.field2property(field)
     assert res['format'] == expected_format
Esempio n. 7
0
 def test_formatted_field_translates_to_array(self):
     field = fields.List(fields.String)
     res = swagger.field2property(field)
     assert res['type'] == 'array'
     assert res['items'] == swagger.field2property(fields.String())
Esempio n. 8
0
 def test_field2property_type(self, FieldClass, jsontype):
     field = FieldClass()
     res = swagger.field2property(field)
     assert res['type'] == jsontype