Exemplo n.º 1
0
def test_view_backups(
    reset_mockTime,
    patch_datetime_now,
    populate_conf_dir,
    populate_data_dir,
    tmp_path,
    capsys,
):
    expected = "full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
    # Set the backup directory.
    backup_dir = tmp_path / BASE_BACKUP_DIR
    # Create the click context that backup_manager expects to deal with
    ctx = create_click_ctx(
        Path(populate_conf_dir), Path(populate_data_dir), Path(backup_dir)
    )
    # Create our configuration
    conf = {
        "name": "full",
        "backup_limit": 0,
    }
    # Create a backup to view.
    with capsys.disabled():
        backup_config = BackupConfig.from_dict(conf)
        backup_config.backup(ctx)

    backup_manager = BackupManager(conf)
    backup_manager.view_backups(ctx)

    captured = capsys.readouterr()
    output = captured.out

    assert expected == output
Exemplo n.º 2
0
def test_view_backups_multiple_backup_strategies(
    reset_mockTime,
    patch_datetime_now,
    populate_conf_dir,
    populate_data_dir,
    tmp_path,
    capsys,
):
    expected = (
        "logs/TEST_APP_LOGS_2020-12-25T170556.tgz\n"
        "full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
    )
    # Set the backup directory.
    backup_dir = tmp_path / BASE_BACKUP_DIR
    # Create the click context that backup_manager expects to deal with
    ctx = create_click_ctx(
        Path(populate_conf_dir), Path(populate_data_dir), Path(backup_dir)
    )
    # Create our configuration
    conf_full = {
        "name": "full",
        "backup_limit": 0,
    }
    conf_logs = {
        "name": "logs",
        "file_filter": {
            "data_dir": {"include_list": ["1.txt", "**/first.txt"]},
            "conf_dir": {"include_list": ["**/*.txt"]},
        },
    }
    # Create a backup to view.
    with capsys.disabled():
        backup_config = BackupConfig.from_dict(conf_full)
        backup_config.backup(ctx)
        mock_time.increment()

        backup_config = BackupConfig.from_dict(conf_logs)
        backup_config.backup(ctx)
        mock_time.increment()

    backup_manager = BackupManager([])
    backup_manager.view_backups(ctx)

    captured = capsys.readouterr()
    output = captured.out

    assert expected == output
Exemplo n.º 3
0
def test_view_multiple_backups_descending_order(
    reset_mockTime,
    patch_datetime_now,
    populate_conf_dir,
    populate_data_dir,
    tmp_path,
    capsys,
):
    expected = (
        "full/TEST_APP_FULL_2020-12-25T170604.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170603.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170602.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170601.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170600.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170559.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170558.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170557.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170556.tgz\n"
        + "full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
    )
    # Set the backup directory.
    backup_dir = tmp_path / BASE_BACKUP_DIR
    # Create the click context that backup_manager expects to deal with
    ctx = create_click_ctx(
        Path(populate_conf_dir), Path(populate_data_dir), Path(backup_dir)
    )
    # Create our configuration
    conf = {
        "name": "full",
        "backup_limit": 0,
    }
    # Create backups to view.
    with capsys.disabled():
        backup_config = BackupConfig.from_dict(conf)
        for x in range(10):
            backup_config.backup(ctx)
            mock_time.increment()

    backup_manager = BackupManager(conf)
    backup_manager.view_backups(ctx)

    captured = capsys.readouterr()
    output = captured.out

    assert expected == output