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'}
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'}
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
def test_field_with_default(self): field = fields.Str(default='foo') res = swagger.field2property(field) assert res['default'] == 'foo'
def test_field_with_description(self): field = fields.Str(description='a username') res = swagger.field2property(field) assert res['description'] == 'a username'
def test_field2property_formats(self, FieldClass, expected_format): field = FieldClass() res = swagger.field2property(field) assert res['format'] == expected_format
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())
def test_field2property_type(self, FieldClass, jsontype): field = FieldClass() res = swagger.field2property(field) assert res['type'] == jsontype