def test_validate_files(self):
     os.chdir(self.test_directory)
     config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
     FileService.validate_files(config)
     if "*" in config.FILES:
         for file in config.FILES:
             assert file in glob.glob("*.csv")
 def test_validate_csv_file_extensions_with_valid_extensions(self):
     os.chdir(self.test_directory)
     config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
     FileService.navigate_to_working_directory(config)
     FileService.validate_csv_file_extensions(config)
     for file in config.FILES:
         assert file[-4:] == ".csv"
Example #3
0
 def test_encrypt_files(self):
     config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
     mock_keys = {
         ApiKeys.SALT_KEYS: [{
             "value": "test-salt-key"
         }],
         ApiKeys.ENCRYPTION_KEY:
         "_hSmVyMTLi-Qo_rmISp8jrH5Aob7frHp1X-28sxQZAU="
     }
     FileService.validate_files(config)
     HashService.hash_files(config, mock_keys)
     EncryptionService.encrypt_files(config, mock_keys)
     assert len(config.ENCRYPTED_FILES) > 0
     os.remove(config.ENCRYPTED_FILES[0])
     os.remove(config.HASHED_FILES[0])
     os.chdir(self.test_directory)
 def test_validate_files_exist_with_existing_file(self):
     os.chdir(self.test_directory)
     config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
     FileService.navigate_to_working_directory(config)
     FileService.validate_csv_file_extensions(config)
     FileService.validate_files_exist(config)
     file_instance = glob.glob(config.FILES[0])
     assert len(file_instance) > 0
 def test_validate_files_exist_with_nonexistant_file(self):
     with pytest.raises(FileNotFoundError):
         os.chdir(self.test_directory)
         config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
         config.WORKING_DIRECTORY = "tests"
         FileService.navigate_to_working_directory(config)
         FileService.validate_csv_file_extensions(config)
         FileService.validate_files_exist(config)
Example #6
0
def run(input_file, log_file, mode):
    """Entry point for the INOIS application."""

    log_level = logging.DEBUG if log_file else logging.CRITICAL
    log_location = log_file if log_file else "inois.log"
    logging.basicConfig(format='%(asctime)s (%(levelname)s): %(message)s',
                        filename=log_location,
                        level=log_level)

    application_mode = mode if mode == ApplicationModeKeys.SEARCH else ApplicationModeKeys.UPLOAD

    logging.info(
        Notifications.APPLICATION_STARTED.format(application_mode,
                                                 datetime.now()))
    print("\n" + Notifications.APPLICATION_STARTED.format(
        application_mode, datetime.now()))
    print(Banner.TEXT)
    config = ConfigService.initialize_config(input_file=input_file)
    session = AuthenticationService(config).get_authorization()
    FileService.validate_files(config)
    keys = KeyService.get_keys(config, session)

    if application_mode == ApplicationModeKeys.UPLOAD:
        HashService.hash_files(config, keys)
        FileService.delete_chunked_files(config)
        EncryptionService.encrypt_files(config, keys)
        FileService.delete_hashed_files(config)
        UploadService.upload_files(config, session)
        FileService.delete_encrypted_files(config)

    elif application_mode == ApplicationModeKeys.SEARCH:
        search_queries = HashService.hash_records_for_search(config, keys)
        SearchService.search_on_all_queries(search_queries, session)

    os.chdir(config.LAUNCH_DIRECTORY)
    logging.info(Notifications.APPLICATION_TERMINATED.format(datetime.now()))
    print("\n" + Notifications.APPLICATION_TERMINATED.format(datetime.now()))
 def test_validate_csv_file_extensions_with_invalid_extensions(self):
     with pytest.raises(TypeError):
         config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
         config.FILES = config.FILES.append("file.xls")
         FileService.navigate_to_working_directory(config)
         FileService.validate_csv_file_extensions(config)
 def test_navgiate_to_working_directory_with_valid_directory(self):
     config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
     previous_directory = os.path.realpath(os.getcwd())
     FileService.navigate_to_working_directory(config)
     assert config.WORKING_DIRECTORY == os.getcwd()
     os.chdir(previous_directory)
 def test_navgiate_to_working_directory_with_nonexistant_directory(self):
     with pytest.raises(OSError):
         config = ConfigService.initialize_config(TEST_CONFIG_FILE_PATH)
         config.WORKING_DIRECTORY = config.WORKING_DIRECTORY + '^&(^&(^&*('
         FileService.navigate_to_working_directory(config)