def test_get_properties_action_with_dir(self, test_client, dir_object): response = test_client.get( '/path/{}/subdirectory?action=properties'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) path = PathSchema().load(load_json_data(response)).data assert path == dir_object
def test_get_exists_action(self, test_client): response = test_client.get('/path/{}/empty_dir?action=exists'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) booleanResponse = BooleanResponseSchema().load( load_json_data(response)).data assert booleanResponse.exists is True
def test_put_without_content_creates_directory(self, test_client): dir_to_create = '{}/new_directory'.format(standard_user().username) response = test_client.put('/path/{}'.format(dir_to_create), headers={"apiKey": standard_user().api_key}) new_dir_path = os.path.join(app.config['DATA_DIRECTORY'], dir_to_create) assert os.path.isdir(new_dir_path)
def test_get_content_action_with_invalid_dir(self, test_client): response = test_client.get( '/path/{}/dir_that_does_not_exist?action=content'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) error = error_from_response(response) assert error == PATH_DOES_NOT_EXIST
def test_get_md5_action_with_file(self, test_client): response = test_client.get('/path/{}/file.json?action=md5'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) md5 = PathMD5Schema().load(load_json_data(response)).data assert md5 == generate_md5( os.path.join(app.config['DATA_DIRECTORY'], "{}/file.json".format(standard_user().username)))
def test_get_exists_action_with_invalid_file(self, test_client): response = test_client.get( '/path/{}/!invalid_F1l3?action=exists'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) booleanResponse = BooleanResponseSchema().load( load_json_data(response)).data assert booleanResponse.exists is False
def test_delete_empty_directory(self, test_client): directory_to_delete = "{}/empty_dir".format(standard_user().username) response = test_client.delete( '/path/{}'.format(directory_to_delete), headers={"apiKey": standard_user().api_key}) assert (not os.path.exists( os.path.join(app.config['DATA_DIRECTORY'], directory_to_delete)) and response.status_code == 204)
def test_delete_single_file(self, test_client): file_to_delete = "{}/file.json".format(standard_user().username) response = test_client.delete( '/path/{}'.format(file_to_delete), headers={"apiKey": standard_user().api_key}) assert (not os.path.exists( os.path.join(app.config['DATA_DIRECTORY'], file_to_delete)) and response.status_code == 204)
def file_object(): file_path = os.path.join(app.config['DATA_DIRECTORY'], '{}/file.json'.format(standard_user().username)) return Path(platform_path="http://localhost/path/{}/file.json".format( standard_user().username), last_modification_date=int(os.path.getmtime(file_path)), is_directory=False, size=Path.get_path_size(file_path, is_dir=False), mime_type='application/json')
def test_get_list_action_with_dir(self, test_client): response = test_client.get('/path/{}/subdirectory?action=list'.format( standard_user().username), headers={"apiKey": standard_user().api_key}) paths = PathSchema(many=True).load(load_json_data(response)).data expected_paths_list = os.listdir( os.path.join(app.config['DATA_DIRECTORY'], '{}/subdirectory'.format(standard_user().username))) assert len(expected_paths_list) == len(paths)
def test_edit_password_user_other_user(self, test_client): response = test_client.post( "/users/edit", headers={"apiKey": standard_user().api_key}, data=json.dumps({ "username": standard_user_2().username, "password": standard_user().password + "2" })) error = error_from_response(response) assert error == UNAUTHORIZED
def dir_object(): dir_path = os.path.join(app.config['DATA_DIRECTORY'], '{}/subdirectory'.format(standard_user().username)) return Path( platform_path="http://localhost/path/{}/subdirectory".format( standard_user().username), last_modification_date=int(os.path.getmtime(dir_path)), is_directory=True, size=Path.get_path_size(dir_path, is_dir=True), )
def test_put_file_raw(self, test_client): path = '{}/test_file_raw.txt'.format(standard_user().username) file_content = "This is a test raw file" response = test_client.put('/path/{}'.format(path), headers={"apiKey": standard_user().api_key}, data=file_content) assert response.status_code == 201 file_path = os.path.join(app.config['DATA_DIRECTORY'], path) with open(file_path) as f: assert f.read() == file_content
def test_put_base64_dir(self, test_client, put_dir): path = '{}/empty_dir'.format(standard_user().username) abs_path = os.path.join(app.config['DATA_DIRECTORY'], path) response = test_client.put( '/path/{}'.format(path), headers={ "apiKey": standard_user().api_key, "Content-Type": "application/carmin+json" }, data=json.dumps(UploadDataSchema().dump(put_dir).data)) assert response.status_code == 201 and os.listdir(abs_path)
def test_put_base64_file(self, test_client, put_file): file_name = '{}/put_file.txt'.format(standard_user().username) response = test_client.put( '/path/{}'.format(file_name), headers={ "apiKey": standard_user().api_key, "Content-Type": "application/carmin+json" }, data=json.dumps(UploadDataSchema().dump(put_file).data)) assert os.path.exists( os.path.join(app.config['DATA_DIRECTORY'], file_name))
def test_put_valid_execution_name(self, test_client, session, execution_id): response = test_client.put('/executions/{}'.format(execution_id), headers={"apiKey": standard_user().api_key}, data=json.dumps(PATCH_VALID_EXECUTION2)) assert response.status_code == 204 execution = session.query(ExecutionDB).filter_by( identifier=execution_id).first() execution, _ = get_execution_as_model(standard_user().username, execution) assert execution.name == PATCH_VALID_EXECUTION2["name"]
def test_put_parameter_no_change(self, test_client, session, execution_id): response = test_client.put('/executions/{}'.format(execution_id), headers={"apiKey": standard_user().api_key}, data=json.dumps(PATCH_NO_CHANGE_PARAMETER)) assert response.status_code == 204 execution = session.query(ExecutionDB).filter_by( identifier=execution_id).first() execution, _ = get_execution_as_model(standard_user().username, execution) assert (execution.pipeline_identifier != PATCH_NO_CHANGE_PARAMETER["pipelineIdentifier"])
def post_invalid_execution_array_file_not_exist(pipeline_identifier: str): return Execution( name="invalid_execution", pipeline_identifier=pipeline_identifier, input_values={ "input_file": [ "http://localhost/path/{}/does_not_exist.txt".format( standard_user().username), "http://localhost/path/{}/test.txt".format( standard_user().username) ] })
def test_post_file_doesnt_exist(self, test_client, pipeline): user_execution_dir = os.path.join(app.config['DATA_DIRECTORY'], standard_user().username, 'executions') response = test_client.post( '/executions', headers={"apiKey": standard_user().api_key}, data=json.dumps(ExecutionSchema().dump( post_invalid_execution_file_not_exist( pipeline.identifier)).data)) assert not os.listdir(user_execution_dir) assert response.status_code == 400
def test_put_with_invalid_upload_type(self, test_client): response = test_client.put( '/path/{}/new_file.txt'.format(standard_user().username), headers={ "apiKey": standard_user().api_key, "Content-Type": "application/carmin+json" }, data='{"type": "Invented", "base64Content": "ewlfkjweflk=="}') error = error_from_response(response) assert error.error_code == INVALID_MODEL_PROVIDED.error_code assert error.error_message == INVALID_MODEL_PROVIDED.error_message assert len(error.error_detail) == 1 assert "type" in error.error_detail
def test_put_base64_invalid_dir(self, test_client): path = '{}/empty_dir2'.format(standard_user().username) abs_path = os.path.join(app.config['DATA_DIRECTORY'], path) put_dir = UploadData(base64_content='bad_content', upload_type='Archive', md5='') response = test_client.put( '/path/{}'.format(path), headers={ "apiKey": standard_user().api_key, "Content-Type": "application/carmin+json" }, data=json.dumps(UploadDataSchema().dump(put_dir).data)) assert response.status_code == 400
def test_put_file_on_dir(self, test_client): path = '{}/empty_dir'.format(standard_user().username) put_dir = UploadData(base64_content='bad_content', upload_type='File', md5='') response = test_client.put( '/path/{}'.format(path), headers={ "apiKey": standard_user().api_key, "Content-Type": "application/carmin+json" }, data=json.dumps(UploadDataSchema().dump(put_dir).data)) error = error_from_response(response) assert error.error_message == "Invalid path: '{}' is a directory.".format( path)
def test_config(tmpdir_factory, session): session.add(standard_user(True)) session.commit() root_directory = tmpdir_factory.mktemp('data') subdir = root_directory.mkdir(standard_user().username) subdir.mkdir('empty_dir') subdir.mkdir('subdirectory') subdir.join('subdir_text.txt').write( "this is a text file inside data/subdir") subdir.join('test.txt').write("content") subdir.join('file.json').write('{"test": "json"}') subdir.join('directory.yml').write("-yaml file") app.config['DATA_DIRECTORY'] = str(root_directory)
def test_edit_password_user(self, test_client): response = test_client.post( "/users/edit", headers={"apiKey": standard_user().api_key}, data=json.dumps({"password": standard_user().password + "2"})) assert response.status_code == 200 response = test_client.post("/authenticate", data=json.dumps({ "username": standard_user().username, "password": standard_user().password + "2" })) assert response.status_code == 200
def test_config(tmpdir_factory, session): session.add(admin(True)) session.add(standard_user(True)) session.commit() root_directory = tmpdir_factory.mktemp('data') app.config['DATA_DIRECTORY'] = str(root_directory)
def test_get_pipeline_boutiques_descriptor_by_identifier_invalid_id( self, test_client): response = test_client.get('/pipelines/{}/boutiquesdescriptor'.format( "INVALID_{}".format(PipelineOne.identifier)), headers={"apiKey": standard_user().api_key}) error = error_from_response(response) assert error == INVALID_PIPELINE_IDENTIFIER
def test_delete_root_directory(self, test_client): directory_to_delete = "./" response = test_client.delete( '/path/{}'.format(directory_to_delete), headers={"apiKey": standard_user().api_key}) assert (os.path.exists( app.config['DATA_DIRECTORY'])) and response.status_code == 403
def test_post_invalid_model(self, test_client): response = test_client.post( '/executions', headers={"apiKey": standard_user().api_key}, data=POST_INVALID_MODEL) error = error_from_response(response) assert error == INVALID_MODEL_PROVIDED
def test_get_with_offset_greater_than_execution_count( self, test_client, number_of_executions): offset = 1000 response = test_client.get('/executions?offset={}'.format(offset), headers={"apiKey": standard_user().api_key}) json_response = load_json_data(response) assert len(json_response) == 0
def test_get_with_executions(self, test_client, number_of_executions): response = test_client.get('/executions', headers={"apiKey": standard_user().api_key}) json_response = load_json_data(response) executions, error = ExecutionSchema(many=True).load(json_response) assert not error assert len(executions) == number_of_executions