Esempio n. 1
0
 def test_hd1_add_file(self):
     test_file      = temp_file(contents=random_text())
     test_file_name = file_name(test_file)
     file_in_hd1    = self.storage.hd1_add_file(test_file)
     assert file_exists(file_in_hd1)
     assert file_contents(file_in_hd1) == file_contents(test_file)
     assert self.storage.hd1_file_path(test_file_name) == file_in_hd1
Esempio n. 2
0
 def setUpClass(cls) -> None:
     cls.test_file      = temp_file(contents='Static text so that we have a static hash')
     cls.test_file_name = file_name(cls.test_file)
     cls.test_file_hash = '500286533bf75d769e9180a19414d1c3502dd52093e7351a0a9b1385d8f8961c'
     cls.meta_data={    'file_name'            : None               ,
                        'original_hash'       : '500286533bf75d769e9180a19414d1c3502dd52093e7351a0a9b1385d8f8961c'               ,
                        'rebuild_hash'         : None   }
Esempio n. 3
0
    def test_cache_on_tmp__with_params(self):
        with Profiler() as profiler:
            assert An_Class().an_function_with_params('aaaaa') == 'aaaaa'

        cache_on_tmp_self = profiler.get_f_locals_variable('self')

        assert file_name(cache_on_tmp_self.last_cache_path
                         ) == 'An_Class_an_function_with_params_aaaaa.gz'
    def test_add_file(self):
        metadata = self.metadata
        file_paths = metadata.data.get('original_file_paths')

        assert self.metadata.exists() is False  # metadata folder doesn't exist

        # adding file first time
        assert metadata.add_file(
            self.file_path
        ) == self.file_hash  # add file and get file hash as return value
        assert metadata.exists() is True  # confirm metadata folder now exists
        assert folder_exists(metadata.metadata_folder_path()
                             )  # confirm metadata folder now exists
        assert file_exists(
            metadata.metadata_file_path())  # confirm metadata json file exists
        assert file_exists(metadata.source_file_path()
                           )  # confirm source file was correctly put in place
        assert metadata.file_hash == self.metadata_utils.file_hash(
            metadata.source_file_path()
        )  # confirm hash of source file matches hash of file_path
        assert metadata.metadata_file_path() == path_combine(
            metadata.metadata_folder_path(), DEFAULT_METADATA_FILENAME
        )  # confirm metadata file is place in correct location
        file_paths = metadata.data.get('original_file_paths')
        assert file_paths == [
            self.file_path
        ]  # confirms that in this mode the entire path is preserved

        # adding same file 2nd time (with same hash and same name)
        assert metadata.add_file(
            self.file_path) == self.file_hash  # adding the same file again
        file_paths = metadata.data.get('original_file_paths')
        assert file_paths == [self.file_path
                              ]  # should not impact this value (same as above)

        # adding same file 3nd time (with same hash but different name)
        assert metadata.add_file(
            self.file_copy_path
        ) == self.file_hash  # adding the same file again (with different name)
        file_paths = metadata.data.get('original_file_paths')
        assert file_paths == [self.file_path, self.file_copy_path
                              ]  # will make the new file path be added

        # adding same file 4th time (with self.path_hd1 set to parent folder of path)
        file_parent_folder = parent_folder(
            self.file_path)  # get parent folder of test file
        self.metadata.path_hd1 = file_parent_folder  # assign it to the metadata variable used to calculate virtual paths

        assert metadata.add_file(self.file_path) == self.file_hash
        file_paths = metadata.data.get('original_file_paths')
        assert file_paths == [
            self.file_path, self.file_copy_path,
            file_name(self.file_path)
        ]  # confirm that the virtual file path was added as the 3rd item (in this case the file name)

        #clean up
        assert self.metadata.delete() is True
        assert folder_not_exists(self.metadata.metadata_folder_path())
 def setUpClass(cls) -> None:
     super().setUpClass()
     cls.test_file       = Test_Data().create_test_pdf(text=random_text(prefix="some random text: "))
     cls.test_file_name  = file_name(cls.test_file)
     cls.config          = Config()
     #cls.temp_root       = folder_create('/tmp/temp_root') # temp_folder()
     #cls.config.set_root_folder(root_folder=cls.temp_root)
     cls.meta_service    = Metadata_Service()
     cls.metadata        = cls.meta_service.create_metadata(cls.test_file)
     cls.analysis_json = Analysis_Json()
    def test_get_from_file(self):
        metadata = self.metadata_service.create_metadata(
            file_path=self.test_file)
        metadata_data = self.metadata_service.get_from_file(
            metadata.metadata_folder_path()).data

        #assert self.metadata_service.metadata_folder == self.test_metadata_folder
        metadata_data['last_update_time'] = None
        assert metadata_data == {
            'file_name':
            file_name(self.test_file),
            'xml_report_status':
            None,
            'last_update_time':
            None,
            'rebuild_server':
            None,
            'server_version':
            None,
            'error':
            None,
            'original_file_paths': [self.test_file],
            'original_hash':
            self.file_hash,
            'original_hash_calculation_time':
            metadata_data['original_hash_calculation_time'],
            'original_file_extension':
            '.tmp',
            'original_file_size':
            41,
            'rebuild_file_path':
            None,
            'rebuild_hash':
            None,
            'rebuild_status':
            FileStatus.INITIAL,
            'rebuild_file_extension':
            None,
            'rebuild_file_size':
            None,
            'rebuild_file_duration':
            None,
            'f2f_plugin_version':
            None,
            'f2f_plugin_git_commit':
            None,
            'hd1_to_hd2_copy_time':
            None,
            'hd2_to_hd3_copy_time':
            None
        }

        metadata.delete()
Esempio n. 7
0
 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_create_metadata(self):

        metadata = self.metadata_service.create_metadata(self.test_file)
        metadata.delete()
        metadata.add_file(self.test_file)
        assert metadata.data == {
            'file_name':
            file_name(self.test_file),
            'xml_report_status':
            None,
            'last_update_time':
            metadata.get_last_update_time(),
            'rebuild_server':
            None,
            'server_version':
            None,
            'error':
            None,
            'original_file_paths': [self.test_file],
            'original_hash':
            file_sha256(self.test_file),
            'original_hash_calculation_time':
            metadata.data.get('original_hash_calculation_time'),
            'original_file_extension':
            '.jpg',
            'original_file_size':
            97610,
            'rebuild_file_path':
            None,
            'rebuild_hash':
            None,
            'rebuild_status':
            FileStatus.INITIAL,
            'rebuild_file_extension':
            None,
            'rebuild_file_size':
            None,
            'rebuild_file_duration':
            None,
            'f2f_plugin_version':
            None,
            'f2f_plugin_git_commit':
            None,
            'hd1_to_hd2_copy_time':
            None,
            'hd2_to_hd3_copy_time':
            None
        }
        assert metadata.delete() is True
Esempio n. 9
0
    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
Esempio n. 10
0
 def test_file_name(self):
     target = temp_file()
     assert path_combine(folder_name(target), file_name(target)) == target
 def setUpClass(cls) -> None:
     cls.test_file      = temp_file(contents='Static text so that we have a static hash')
     cls.test_file_name = file_name(cls.test_file)
     cls.test_file_hash = '500286533bf75d769e9180a19414d1c3502dd52093e7351a0a9b1385d8f8961c'
Esempio n. 12
0
 def set_original_file_name(self, file_path):
     original_file_name = file_name(file_path)
     self.update_field('file_name', original_file_name)