Example #1
0
async def test_generational_delete(time, model: Model, dest, source,
                                   simple_config):
    time.setNow(time.local(2019, 5, 10))
    now = time.now()

    # Create 4 backups, configured to keep 3
    source.setMax(3)
    source.insert("Fri", time.local(2019, 5, 10, 1))
    source.insert("Thu", time.local(2019, 5, 9, 1))
    wed = source.insert("Wed", time.local(2019, 5, 8, 1))
    source.insert("Mon", time.local(2019, 5, 6, 1))

    # configure only one to be kept in both places
    simple_config.config.update({
        "days_between_backups": 1,
        "generational_weeks": 1,
        "generational_days": 2
    })
    model.reinitialize()
    await model.sync(now)

    # Shoud only delete wed, since it isn't kept in the generational backup config
    source.assertThat(current=3, deleted=1)
    assert source.deleted == [wed]
    assert len(model.backups) == 3
    dest.assertThat(current=3, saved=3)
Example #2
0
async def test_generational_empty(time, model: Model, dest, source,
                                  simple_config: Config):
    time.setNow(time.local(2019, 5, 10))
    now = time.now()

    simple_config.config.update({
        "days_between_backups": 1,
        "generational_weeks": 1,
        "generational_days": 2
    })

    simple_config.override(Setting.DAYS_BETWEEN_BACKUPS, 1)

    model.reinitialize()
    assert len(model.backups) == 0
    await model.sync(now)
    assert len(model.backups) == 1
async def test_alternate_timezone(coord: Coordinator, time: FakeTime, model: Model, dest, source, simple_config: Config):
    time.setTimeZone("Europe/Stockholm")
    simple_config.override(Setting.BACKUP_TIME_OF_DAY, "12:00")
    simple_config.override(Setting.DAYS_BETWEEN_BACKUPS, 1)

    source.setMax(10)
    source.insert("Fri", time.toUtc(time.local(2020, 3, 16, 18, 5)))
    time.setNow(time.local(2020, 3, 16, 18, 6))
    model.reinitialize()
    coord.reset()
    await coord.sync()
    assert not coord.check()
    assert coord.nextBackupTime() == time.local(2020, 3, 17, 12)

    time.setNow(time.local(2020, 3, 17, 11, 59))
    await coord.sync()
    assert not coord.check()
    time.setNow(time.local(2020, 3, 17, 12))
    assert coord.check()
Example #4
0
async def test_new_upload_no_delete(time, model: Model, source, dest,
                                    simple_config):
    now = time.now()

    # create a single old backup
    source.setMax(2)
    dest.setMax(2)
    backup_dest = dest.insert("older", now - timedelta(days=1), "older")
    backup_source = source.insert("older", now - timedelta(days=1), "older")

    # configure keeping two in both places
    simple_config.config.update({"days_between_backups": 1})
    model.reinitialize()
    await model.sync(now)

    # Another backup should have been created and saved
    source.assertThat(current=2, created=1)
    dest.assertThat(current=2, saved=1)
    assert len(model.backups) == 2
    assertBackup(model, [source.created[0], dest.saved[0]])
    assertBackup(model, [backup_dest, backup_source])
Example #5
0
async def test_new_upload_with_delete(time, model: Model, source, dest,
                                      simple_config):
    now = time.now()

    # create a single old backups
    source.setMax(1)
    dest.setMax(1)
    backup_dest = dest.insert("older", now - timedelta(days=1), "older")
    backup_source = source.insert("older", now - timedelta(days=1), "older")

    # configure only one to be kept in both places
    simple_config.config.update({"days_between_backups": 1})
    model.reinitialize()
    await model.sync(now)

    # Old snapshto shoudl be deleted, new one shoudl be created and uploaded.
    source.assertThat(current=1, created=1, deleted=1)
    dest.assertThat(current=1, saved=1, deleted=1)
    assert dest.deleted == [backup_dest]
    assert source.deleted == [backup_source]

    assert len(model.backups) == 1
    assertBackup(model, [source.created[0], dest.saved[0]])
Example #6
0
async def test_dont_delete_purgable(time, model: Model, source, dest,
                                    simple_config):
    now = time.now()

    # create a single old backup, retained
    source.setMax(1)
    dest.setMax(1)
    backup_dest = dest.insert("older", now - timedelta(days=1), "older")
    backup_dest.setRetained(True)
    backup_source = source.insert("older", now - timedelta(days=1), "older")
    backup_source.setRetained(True)

    # configure only one to be kept in both places
    simple_config.config.update({"days_between_backups": 1})
    model.reinitialize()
    await model.sync(now)

    # Old snapshto shoudl be kept, new one should be created and uploaded.
    source.assertThat(current=2, created=1)
    dest.assertThat(current=2, saved=1)

    assert len(model.backups) == 2
    assertBackup(model, [backup_dest, backup_source])
    assertBackup(model, [source.created[0], dest.saved[0]])
Example #7
0
async def test_multiple_deletes_allowed(time, model: Model, source, dest,
                                        simple_config):
    now = time.now()
    simple_config.config.update({"confirm_multiple_deletes": False})
    # create 4 backups in dest
    dest.setMax(1)

    current = dest.insert("current", now, "current")
    old = dest.insert("old", now - timedelta(days=1), "old")
    older = dest.insert("older", now - timedelta(days=2), "older")
    oldest = dest.insert("oldest", now - timedelta(days=3), "oldest")

    # configure keeping 1
    simple_config.config.update({
        "max_backups_in_google_drive": 1,
    })
    model.reinitialize()
    await model.sync(now)

    source.assertUnchanged()
    dest.assertThat(current=1, deleted=3)
    assert dest.deleted == [oldest, older, old]
    assert len(model.backups) == 1
    assertBackup(model, [current])
Example #8
0
def test_timeOfDay(estimator, model: Model) -> None:
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '00:00')
    model.reinitialize()
    assert model.getTimeOfDay() == (0, 0)

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '23:59')
    model.reinitialize()
    assert model.getTimeOfDay() == (23, 59)

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '24:59')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '24:60')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '-1:60')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '24:-1')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, 'boop:60')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '24:boop')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '24:10:22')
    model.reinitialize()
    assert model.getTimeOfDay() is None

    model.config.override(Setting.SNAPSHOT_TIME_OF_DAY, '10')
    model.reinitialize()
    assert model.getTimeOfDay() is None