class UserWithUUID(Schema): uuid = fields.UUID() # This is because Email is not typed on marshmallow email = fields.Email() # type: ignore name = fields.String() surname = fields.String()
def test_responses(self, faker: Faker) -> None: class MySchema(Schema): name = fields.Str() f = "myfield" assert ( ResponseMaker.get_schema_type(f, fields.Str(metadata={"password": True})) == "password" ) assert ResponseMaker.get_schema_type(f, fields.Bool()) == "boolean" assert ResponseMaker.get_schema_type(f, fields.Boolean()) == "boolean" assert ResponseMaker.get_schema_type(f, fields.Date()) == "date" assert ResponseMaker.get_schema_type(f, fields.DateTime()) == "datetime" assert ResponseMaker.get_schema_type(f, fields.AwareDateTime()) == "datetime" assert ResponseMaker.get_schema_type(f, fields.NaiveDateTime()) == "datetime" assert ResponseMaker.get_schema_type(f, fields.Decimal()) == "number" # This is because Email is not typed on marshmallow assert ResponseMaker.get_schema_type(f, fields.Email()) == "email" # type: ignore assert ResponseMaker.get_schema_type(f, fields.Float()) == "number" assert ResponseMaker.get_schema_type(f, fields.Int()) == "int" assert ResponseMaker.get_schema_type(f, fields.Integer()) == "int" assert ResponseMaker.get_schema_type(f, fields.Number()) == "number" assert ResponseMaker.get_schema_type(f, fields.Str()) == "string" assert ResponseMaker.get_schema_type(f, fields.String()) == "string" assert ResponseMaker.get_schema_type(f, fields.Dict()) == "dictionary" assert ResponseMaker.get_schema_type(f, fields.List(fields.Str())) == "string[]" assert ResponseMaker.get_schema_type(f, fields.Nested(MySchema())) == "nested" # Unsupported types, fallback to string assert ResponseMaker.get_schema_type(f, fields.URL()) == "string" assert ResponseMaker.get_schema_type(f, fields.Url()) == "string" assert ResponseMaker.get_schema_type(f, fields.UUID()) == "string" # assert ResponseMaker.get_schema_type(f, fields.Constant("x")) == "string" assert ResponseMaker.get_schema_type(f, fields.Field()) == "string" # assert ResponseMaker.get_schema_type(f, fields.Function()) == "string" # assert ResponseMaker.get_schema_type(f, fields.Mapping()) == "string" # assert ResponseMaker.get_schema_type(f, fields.Method()) == "string" # assert ResponseMaker.get_schema_type(f, fields.Raw()) == "string" # assert ResponseMaker.get_schema_type(f, fields.TimeDelta()) == "string" assert not ResponseMaker.is_binary(None) assert not ResponseMaker.is_binary("") assert not ResponseMaker.is_binary("application/json") assert ResponseMaker.is_binary("application/octet-stream") assert ResponseMaker.is_binary("application/x-bzip") assert ResponseMaker.is_binary("application/x-bzip2") assert ResponseMaker.is_binary("application/pdf") assert ResponseMaker.is_binary("application/msword") assert ResponseMaker.is_binary("application/rtf") assert ResponseMaker.is_binary("application/x-tar") assert ResponseMaker.is_binary("application/gzip") assert ResponseMaker.is_binary("application/zip") assert ResponseMaker.is_binary("application/x-7z-compressed") assert not ResponseMaker.is_binary("text/plain") assert not ResponseMaker.is_binary("text/css") assert not ResponseMaker.is_binary("text/csv") assert not ResponseMaker.is_binary("text/html") assert not ResponseMaker.is_binary("text/javascript") assert not ResponseMaker.is_binary("text/xml") assert ResponseMaker.is_binary("image/gif") assert ResponseMaker.is_binary("image/jpeg") assert ResponseMaker.is_binary("image/png") assert ResponseMaker.is_binary("image/svg+xml") assert ResponseMaker.is_binary("image/tiff") assert ResponseMaker.is_binary("image/webp") assert ResponseMaker.is_binary("image/bmp") assert ResponseMaker.is_binary("image/aac") assert ResponseMaker.is_binary("audio/midi") assert ResponseMaker.is_binary("audio/mpeg") assert ResponseMaker.is_binary("audio/wav") assert ResponseMaker.is_binary("audio/anyother") assert ResponseMaker.is_binary("video/mpeg") assert ResponseMaker.is_binary("video/ogg") assert ResponseMaker.is_binary("video/webm") assert ResponseMaker.is_binary("video/anyother") assert ResponseMaker.is_binary("video/anyother") assert not ResponseMaker.is_binary(faker.pystr()) response = EndpointResource.response("", code=200) assert response[1] == 200 # type: ignore response = EndpointResource.response(None, code=200) assert response[1] == 204 # type: ignore response = EndpointResource.response(None, code=200, head_method=True) assert response[1] == 200 # type: ignore
class TOKEN(Schema): token_type = fields.String()
class User(Schema): uuid = fields.UUID() email = fields.Email() name = fields.String() surname = fields.String()
class UUID(Schema): uuid = fields.String()