def test_dict(self): data = { 'sid': 3, 'account_sid': 4, } field = fields.FormattedString('/foo/{account_sid}/{sid}/') assert field.output('foo', data) == '/foo/4/3/'
def test_dict(self): data = { "sid": 3, "account_sid": 4, } field = fields.FormattedString("/foo/{account_sid}/{sid}/") assert field.output("foo", data) == "/foo/4/3/"
def test_tuple(self): field = fields.FormattedString("/foo/{0[account_sid]}/{0[sid]}/") self.assert_field_raises(field, (3, 4))
def test_invalid_object(self): field = fields.FormattedString("/foo/{0[account_sid]}/{0[sid]}/") self.assert_field_raises(field, {})
def test_none(self): field = fields.FormattedString("{foo}") # self.assert_field_raises(field, None) with pytest.raises(fields.MarshallingError): field.output("foo", None)
def test_object(self, mocker): obj = mocker.Mock() obj.sid = 3 obj.account_sid = 4 field = fields.FormattedString("/foo/{account_sid}/{sid}/") assert field.output("foo", obj) == "/foo/4/3/"
def test_defaults(self): field = fields.FormattedString("Hello {name}") assert not field.required assert field.__schema__ == {"type": "string"}
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 * 300 #Around 300 MBs max size app.config['UPLOAD_EXTENSIONS'] = ['.mp3', '.wav'] rabbitmq_host = os.environ.get("RABBITMQ_HOST") rabbitmq_user = os.environ.get("RABBITMQ_USER") rabbitmq_password = os.environ.get("RABBITMQ_PASSWORD") CONFIG = { 'AMQP_URI': f"amqp://{rabbitmq_user}:{rabbitmq_password}@{rabbitmq_host}", 'serializer': 'pickle' } upload_parser = api.parser() upload_parser.add_argument('file', location='files', type=FileStorage, required=True) requestResult = api.model('RequestResult', { 'uuid' : fields.FormattedString(uuid.uuid4(),description='An uuid or token that is required to retrieve file after processing' ,example=str(uuid.uuid4())), 'model' : fields.String(description='Selected model: demucs, tasnet, etc',example='Demucs'), 'status' : fields.String(description='A status of the current request',example="Queued") }) errorResponse = api.model('ErrorResponse',{ 'message' : fields.String(description='Message describing error') } ) @api.route('/upload', methods=['POST']) @api.expect(upload_parser) class Upload(Resource): '''Upload a file and receive a token or uuid for further file retrieving after processing''' @api.doc('upload') @api.response(200, 'Success', requestResult) @api.response(400, 'Validation Error', errorResponse) @api.response(500, 'Internal Server Error', errorResponse) def post(self):
from flask_restx import fields from flask_restx.fields import MarshallingError from flask_restx.marshalling import marshal from .common import ns playlist_identifier = ns.model( "playlist_identifier", { # Use `FormattedString`s in these models to act as a constant via the source string arg ("playlist" here) "type": fields.FormattedString("playlist"), "playlist_id": fields.Integer(required=True), }, ) explore_playlist_identifier = ns.model( "explore_playlist_identifier", { "type": fields.FormattedString("explore_playlist"), "playlist_id": fields.String(required=True), }, ) class PlaylistLibraryIdentifier(fields.Raw): def format(self, value): try: if value.get("type") == "playlist": return marshal(value, playlist_identifier) if value.get("type") == "explore_playlist": return marshal(value, explore_playlist_identifier)
def test_object(self, mocker): obj = mocker.Mock() obj.sid = 3 obj.account_sid = 4 field = fields.FormattedString('/foo/{account_sid}/{sid}/') assert field.output('foo', obj) == '/foo/4/3/'
def test_defaults(self): field = fields.FormattedString('Hello {name}') assert not field.required assert field.__schema__ == {'type': 'string'}