def create(self, file_path): if self.file_hash: folder_create(self.metadata_folder_path()) file_copy(file_path, self.source_file_path()) self.set_original_file_size(file_path) self.set_original_file_extension(file_path) self.set_original_file_name(file_path)
def setUpClass(cls) -> None: cls.test_file = temp_file( contents='Static text so that we have a static hash') cls.file_hash = '500286533bf75d769e9180a19414d1c3502dd52093e7351a0a9b1385d8f8961c' cls.temp_dir = temp_folder() file_copy(cls.test_file, cls.temp_dir) cls.pre_processor = Pre_Processor() Setup_Testing().configure_pre_processor(cls.pre_processor)
def test_move_file(self): source_file = temp_file() target_file = temp_file() file_copy(self.test_file, source_file) self.file_service.move_file(source_file, target_file) assert os.path.exists(source_file) is False assert os.path.exists(target_file) is True
def download_screenshot_from_datastore(self): datastore_file = Datastore_File().set_file_from_path_datastore(self.ds_screenshot) local_temp_file = datastore_file.download() if (self.path_screenshot): file_copy(local_temp_file, self.path_screenshot) else: self.path_screenshot = local_temp_file if self.ds_delete_on_download: datastore_file.delete() return self.path_screenshot
def get_processing_config(self, target_file): target_file_name = file_name(target_file) config = { "target_file": target_file, "file_name": target_file_name, "local_config": self.get_processing_local_config(target_file_name), "docker_config": self.get_processing_docker_config(target_file_name) } file_copy(source=target_file, destination=config.get('local_config').get('input_file')) return config
def test_file_copy(self): text_a = random_string() text_b = random_string() file_a = temp_file(contents=text_a) file_b = temp_file(contents=text_b) assert file_exists(file_a) is True assert file_exists(file_b) is True assert file_contents(file_a) == text_a assert file_contents(file_b) == text_b assert file_delete(file_b) is True assert file_exists(file_b) is False file_copy(file_a, file_b) assert file_exists(file_b) is True assert file_contents(file_b) == text_a
def prepare_zip(self, path, zip_name): try: self.temp_folder = temp_folder() dst_path = os.path.join(self.temp_folder, ntpath.basename(path)) if os.path.isfile(path): file_copy(path, dst_path) elif os.path.isdir(path): folder_copy(path, dst_path) target_file_path = os.path.join(self.zip_folder, zip_name) zip_files(self.temp_folder, file_pattern='*.*', target_file = target_file_path) folder_delete_all(self.temp_folder) return target_file_path except Exception as error: logger.error(f"File_Distributor: prepare_zip : {error}") raise error
def setup_test_environment__Deploy_Lambda( cls): # todo: refactor into separate class STS().check_current_session_credentials() cls.lambda_name = "osbot_test_deploy_lambda" cls.lambda_code = Temp_Folder_With_Lambda_File(cls.lambda_name) cls.code_folder = cls.lambda_code.folder lambda_file = cls.lambda_code.tmp_file module_folder = path_combine(cls.code_folder, "osbot_test_deploy_lambda") lambda_in_module = path_combine(module_folder, file_name(lambda_file)) folder_create(module_folder) file_copy(lambda_file, lambda_in_module) # todo add a file_move to OSBot_Utils file_delete(lambda_file) file_create(path_combine(module_folder, '__init__.py'), "") sys.path.append(cls.code_folder) cls.lambda_module = importlib.import_module( "osbot_test_deploy_lambda.osbot_test_deploy_lambda") cls.lambda_function = cls.lambda_module.run
def setUpClass(cls) -> None: cls.file_path = temp_file(contents='some text') # test file cls.file_copy_path = cls.file_path + '_an_copy' # create a copy to test adding multiple files file_copy(cls.file_path, cls.file_copy_path)
def hd1_add_file(self, path): # todo add support for child folders if file_exists(path): return file_copy(path, self.hd1())