def __set_up_with_encryption(s3_bucket: str, password: str, repository_path) -> None: """ This is used by the tests to set up a configuration for a repository **with** encryption. This is done by mocking the user inputs and running `configuration.get_configuration`. Parameters ---------- s3_bucket The name of the S3 bucket that the repository will be configured with. The back up copies would normally be uploaded to this bucket. password The encryption password that will be configured for the repository. repository_path The path to the repository of files to be backed up. This repository **must not** yet have been initialised (i.e. it has not been previously configured). Returns ------- The `Configuration` that was created for the repository. """ with mock.patch('builtins.input') as mock_input: mock_input.side_effect = [s3_bucket, "y"] with mock.patch('getpass.getpass') as mock_getpass: mock_getpass.return_value = password return configuration.get_configuration( repository_path=repository_path)
def __read_configuration_with_encryption(password: str, repository_path) -> None: """ This is used by the tests to read back the configuration for a repository configured with encryption. It is expected that the user will be prompted for the encryption password when reading the configuration (the method will mock the user input). Parameters ---------- password The encryption password for the repository. This **must** match the password that was set during configuraton. repository_path The path to the repository of files to be backed up. This repository **must** have been already been configured. Return ------ The `Configuration` that was read back from the repository. """ with mock.patch('getpass.getpass') as mock_getpass: mock_getpass.return_value = password return configuration.get_configuration(repository_path=repository_path)
def test_read_configuration_no_encryption(tmp_path) -> None: """ This tests reading back a configuration for a repository (withoouut extra encryptio) after it has been set up. """ created_configuration = __set_up_no_encryption(s3_bucket="def", repository_path=tmp_path) read_configuration = configuration.get_configuration( repository_path=tmp_path) assert created_configuration == read_configuration
from argparse import ArgumentParser import logging from pathlib import Path import pyups.backups as backups from pyups.configuration import get_configuration logging.config.fileConfig('logging.ini') parser = ArgumentParser( prog="pyups", description="Back up a directory into an Amazon S3 bucket") parser.add_argument("directory", help="The path of the directory to backup.") arguments = parser.parse_args() path = Path(arguments.directory) if path.exists() and path.is_dir(): logging.info(f"Backing up directory {arguments.directory}") backups.backup(path, get_configuration(path)) else: print(f'Could {path} either does not exist or is not a directory.')