def test_response(tmpdir): config_file = tmpdir.join('resize4me_settings.json') config_file.write(json.dumps(CONFIG)) r4m = Resize4Me(config_file) response = { 'resize4me': 'https://s3.amazonaws.com/resize4me/file.jpg', 'resized-300px': 'https://s3.amazonaws.com/resize4me-300px/file.jpg', 'resized-600px': 'https://s3.amazonaws.com/resize4me-600px/file.jpg', } actual_response = r4m.response('file.jpg') assert response == actual_response
def test_upload(tmpdir): config_file = tmpdir.join('resize4me_settings.json') config_file.write(json.dumps(CONFIG)) conn = boto3.resource('s3', region_name='us-east-1') conn.create_bucket(Bucket='resize4me') r4m = Resize4Me(config_file) r4m.upload('resize4me', 'key', 'body') body = conn.Object('resize4me', 'key').get()['Body'].read().decode('utf-8') assert body == 'body'
def upload_file(): """ Uplodas a file to a S3 bucket and returns a list of dicts with the generated resized files. """ if 'file' not in request.files: return 'No file uploaded' file = request.files['file'] resize4me = Resize4Me() resize4me.check_extension(file.filename) resize4me.upload(resize4me.source_bucket, file.filename, file.stream.read()) response = resize4me.response(file.filename) return jsonify(response)