def test_types_sftp_not_private_key_and_password():
    config = get_test_config()
    config['test']['type'] = 'sftp'
    del config['test']['private_key']
    del config['test']['password']
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS
Exemple #2
0
def create_backup(environment, path):
    """Creates a backup according to the settings of the selected environment."""
    if not os.path.isfile(path):
        logging.info('The configuration file does not exist.')
        return sys.exit(CodeError.FILE_DOES_NOT_EXIST)
    config = configparser.ConfigParser()
    config.read(path)
    error_found = check_config(config, environment)
    if error_found:
        return sys.exit(error_found)
    dump_db(config, environment)
    dump_filestore(config, environment)
    type = config[environment].get('type')
    plugin = importlib.import_module(
        'odoo_backup_db_cli.protocols.{type}'.format(type=type))
    type_handler = getattr(plugin, '_{type}_handler'.format(type=type))
    type_handler(config, environment)
    return sys.exit(CodeError.SUCCESS)
def test_types_ftp_ok():
    config = get_test_config()
    config['test']['type'] = 'ftp'
    res = check_config(config, 'test')
    assert res == CodeError.SUCCESS
def test_types_another():
    config = get_test_config()
    config['test']['type'] = 'test'
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS
def test_all_config_fields():
    config = get_test_config()
    del config['test']['db_username']
    del config['common']['db_username']
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS
def test_filestore_location():
    config = get_test_config()
    del config['test']['filestore_location']
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS
def test_with_filestore():
    config = get_test_config()
    del config['test']['with_filestore']
    res = check_config(config, 'test')
    assert res == CodeError.SUCCESS
def test_clean_backup_after_is_integer():
    config = get_test_config()
    config['test']['clean_backup_after'] = "1.1"
    res = check_config(config, 'test')
    assert res == CodeError.INVALID_SETTINGS
def test_clean_backup_after():
    config = get_test_config()
    del config['test']['clean_backup_after']
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS
def test_env():
    config = get_test_config()
    res = check_config(config, 'test2')
    assert res == CodeError.NO_SETTINGS
def test_types_sftp_full():
    config = get_test_config()
    config['test']['type'] = 'sftp'
    res = check_config(config, 'test')
    assert res == CodeError.INVALID_SETTINGS
def test_types_sftp_ok():
    config = get_test_config()
    config['test']['type'] = 'sftp'
    del config['test']['private_key']
    res = check_config(config, 'test')
    assert res == CodeError.SUCCESS
def test_types_ftp():
    config = get_test_config()
    config['test']['type'] = 'ftp'
    del config['test']['pasv']
    res = check_config(config, 'test')
    assert res == CodeError.NO_SETTINGS