def test_upload_single_file(self): """Method to test uploading of single file""" class FileObj(BytesIO): def close(self): pass class MyRequest(Request): def _get_file_stream(*args, **kwargs): return FileObj() app.request_class = MyRequest @app.route("/test_upload", methods=['POST']) def upload(): files = request.files['file'] file_uploaded = uploaded_file(files=files) return jsonify({ 'path': file_uploaded.file_path, 'name': file_uploaded.filename }) with app.test_request_context(): client = app.test_client() resp = client.post( '/test_upload', data={'file': (BytesIO(b'1,2,3,4'), 'test_file.csv')}) data = resp.get_json() file_path = data['path'] filename = data['name'] actual_file_path = app.config.get( 'BASE_DIR') + '/static/uploads/' + filename self.assertEqual(file_path, actual_file_path) self.assertTrue(os.path.exists(file_path))
def create_app(): app.config.from_object('config.TestingConfig') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) with app.test_request_context(): db.create_all() return app.test_client()
def create_app(): app.config.from_object('config.TestingConfig') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) celery.conf.update(app.config) with app.test_request_context(): db.create_all() set_settings(secret='super secret key', app_name='Open Event', app_environment=Environment.TESTING) return app.test_client()
def create_app(): app.config.from_object('config.TestingConfig') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() set_settings(secret='super secret key', app_name='Open Event', app_environment=Environment.TESTING) return app.test_client()
def create_app(): # app.config.from_object('config.TestingConfig') app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG_TB_ENABLED'] = False app.config['CELERY_ALWAYS_EAGER'] = True app.config['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = True app.config['BROKER_BACKEND'] = 'memory' # app.config['CELERY_BROKER_URL'] = '' # app.config['CELERY_RESULT_BACKEND'] = '' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(_basedir, 'test.db') app.secret_key = 'super secret key' celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() return app.test_client()
def test_upload_multiple_file(self): """Method to test uploading of multiple files""" class FileObj(BytesIO): def close(self): pass class MyRequest(Request): def _get_file_stream(*args, **kwargs): return FileObj() app.request_class = MyRequest @app.route("/test_upload_multi", methods=['POST']) def upload_multi(): files = request.files.getlist('files[]') file_uploaded = uploaded_file(files=files, multiple=True) files_uploaded = [] for file in file_uploaded: files_uploaded.append({ 'path': file.file_path, 'name': file.filename }) return jsonify({"files": files_uploaded}) with app.test_request_context(): client = app.test_client() resp = client.post('/test_upload_multi', data={ 'files[]': [(BytesIO(b'1,2,3,4'), 'test_file.csv'), (BytesIO(b'10,20,30,40'), 'test_file2.csv') ] }) datas = resp.get_json()['files'] for data in datas: file_path = data['path'] filename = data['name'] actual_file_path = app.config.get( 'BASE_DIR') + '/static/uploads/' + filename self.assertEqual(file_path, actual_file_path) self.assertTrue(os.path.exists(file_path))
def create_app(): # app.config.from_object('config.TestingConfig') app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG_TB_ENABLED'] = False app.config['CELERY_ALWAYS_EAGER'] = True app.config['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = True app.config['BROKER_BACKEND'] = 'memory' # app.config['CELERY_BROKER_URL'] = '' # app.config['CELERY_RESULT_BACKEND'] = '' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(_basedir, 'test.db') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() set_settings(secret='super secret key', app_name='Open Event') return app.test_client()
def create_app(): app.config.from_object('config.TestingConfig') app.secret_key = 'super secret key' with app.test_request_context(): db.create_all() return app.test_client()
def client(): from backend_common.models.database import database current_app.config['TESTING'] = True with database.transaction() as txn: yield current_app.test_client() txn.rollback()
def __init__(self, *args, **kwargs): super(SendPayloadMixin, self).__init__(*args, **kwargs) self.app = current_app.test_client() self._check_urls()