예제 #1
0
async def test_update_backups_old_names(updater: HaUpdater, server, backup: Backup, time: FakeTime, supervisor: SimulatedSupervisor, config: Config):
    config.override(Setting.CALL_BACKUP_SNAPSHOT, True)
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "backed_up"
    verifyEntity(supervisor, "binary_sensor.snapshots_stale",
                 "off", {"friendly_name": "Snapshots Stale",
                         "device_class": "problem"})
    date = '1985-12-06T05:00:00+00:00'
    verifyEntity(supervisor, "sensor.snapshot_backup", "backed_up", {
        'friendly_name': 'Snapshot State',
        'last_snapshot': date,
        'snapshots': [{
            'date': date,
            'name': backup.name(),
            'size': backup.sizeString(),
            'state': backup.status(),
            'slug': backup.slug()
        }
        ],
        'snapshots_in_google_drive': 1,
        'snapshots_in_home_assistant': 1,
        'snapshots_in_hassio': 1,
        'size_in_home_assistant': Estimator.asSizeString(backup.size()),
        'size_in_google_drive': Estimator.asSizeString(backup.size())
    })
예제 #2
0
async def test_notification_link(updater: HaUpdater, server, time: FakeTime, global_info, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    verifyEntity(supervisor, "sensor.backup_state", "waiting", {
        'friendly_name': 'Backup State',
        'last_backup': 'Never',
        'last_uploaded': 'Never',
        'backups': [],
        'backups_in_google_drive': 0,
        'backups_in_home_assistant': 0,
        'size_in_home_assistant': "0.0 B",
        'size_in_google_drive': "0.0 B"
    })
    assert supervisor.getNotification() is None

    global_info.failed(Exception())
    global_info.url = "http://localhost/test"
    time.advanceDay()
    await updater.update()
    assert supervisor.getNotification() == {
        'message': 'The add-on is having trouble making backups and needs attention.  Please visit the add-on [status page](http://localhost/test) for details.',
        'title': 'Home Assistant Google Drive Backup is Having Trouble',
        'notification_id': 'backup_broken'
    }
async def test_update_snapshots_sync(updater: HaUpdater, server,
                                     time: FakeTime, snapshot,
                                     supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "backed_up"
    verifyEntity(supervisor, "binary_sensor.snapshots_stale", "off",
                 STALE_ATTRIBUTES)
    date = '1985-12-06T05:00:00+00:00'
    verifyEntity(
        supervisor, "sensor.snapshot_backup", "backed_up", {
            'friendly_name':
            'Snapshot State',
            'last_snapshot':
            date,
            'snapshots': [{
                'date': date,
                'name': snapshot.name(),
                'size': snapshot.sizeString(),
                'state': snapshot.status()
            }],
            'snapshots_in_google_drive':
            1,
            'snapshots_in_hassio':
            1,
            'snapshots_in_home_assistant':
            1,
            'size_in_home_assistant':
            Estimator.asSizeString(snapshot.size()),
            'size_in_google_drive':
            Estimator.asSizeString(snapshot.size())
        })
예제 #4
0
async def test_init_failure(updater: HaUpdater, global_info: GlobalInfo, time: FakeTime, server, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"

    global_info.failed(Exception())
    assert not updater._stale()
    assert updater._state() == "backed_up"
    assert supervisor.getNotification() is None

    time.advanceDay()
    assert updater._stale()
    assert updater._state() == "error"
    await updater.update()
    assert supervisor.getNotification() == {
        'message': 'The add-on is having trouble making backups and needs attention.  Please visit the add-on status page for details.',
        'title': 'Home Assistant Google Drive Backup is Having Trouble',
        'notification_id': 'backup_broken'
    }
예제 #5
0
async def test_init(updater: HaUpdater, global_info, supervisor: SimulatedSupervisor, server):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    verifyEntity(supervisor, "sensor.backup_state", "waiting", {
        'friendly_name': 'Backup State',
        'last_backup': 'Never',
        'last_uploaded': 'Never',
        'backups': [],
        'backups_in_google_drive': 0,
        'backups_in_home_assistant': 0,
        'size_in_google_drive': "0.0 B",
        'size_in_home_assistant': '0.0 B'
    })
    assert supervisor.getNotification() is None

    global_info.success()
    assert not updater._stale()
    assert updater._state() == "backed_up"
async def test_init(updater: HaUpdater, global_info, server):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(server, "binary_sensor.snapshots_stale", "off",
                 STALE_ATTRIBUTES)
    verifyEntity(
        server, "sensor.snapshot_backup", "waiting", {
            'friendly_name': 'Snapshot State',
            'last_snapshot': 'Never',
            'snapshots': [],
            'snapshots_in_google_drive': 0,
            'snapshots_in_hassio': 0,
            'snapshots_in_home_assistant': 0,
            'size_in_google_drive': "0.0 B",
            'size_in_home_assistant': '0.0 B'
        })
    assert server.getNotification() is None

    global_info.success()
    assert not updater._stale()
    assert updater._state() == "backed_up"
예제 #7
0
async def test_notification_clears(updater: HaUpdater, server, time: FakeTime, global_info, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    assert supervisor.getNotification() is None

    global_info.failed(Exception())
    time.advanceDay()
    await updater.update()
    assert supervisor.getNotification() is not None

    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None
예제 #8
0
async def test_update_backups(updater: HaUpdater, server, time: FakeTime, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    verifyEntity(supervisor, "sensor.backup_state", "waiting", {
        'friendly_name': 'Backup State',
        'last_backup': 'Never',
        'last_uploaded': 'Never',
        'backups': [],
        'backups_in_google_drive': 0,
        'backups_in_home_assistant': 0,
        'size_in_home_assistant': "0.0 B",
        'size_in_google_drive': "0.0 B"
    })
async def test_update_snapshots(updater: HaUpdater, server, time: FakeTime):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "waiting"
    verifyEntity(server, "binary_sensor.snapshots_stale", "off",
                 STALE_ATTRIBUTES)
    verifyEntity(
        server, "sensor.snapshot_backup", "waiting", {
            'friendly_name': 'Snapshot State',
            'last_snapshot': 'Never',
            'snapshots': [],
            'snapshots_in_google_drive': 0,
            'snapshots_in_hassio': 0,
            'snapshots_in_home_assistant': 0,
            'size_in_home_assistant': "0.0 B",
            'size_in_google_drive': "0.0 B"
        })
예제 #10
0
async def test_update_backups_sync(updater: HaUpdater, server, time: FakeTime, backup: Backup, supervisor: SimulatedSupervisor):
    await updater.update()
    assert not updater._stale()
    assert updater._state() == "backed_up"
    verifyEntity(supervisor, "binary_sensor.backups_stale",
                 "off", STALE_ATTRIBUTES)
    date = '1985-12-06T05:00:00+00:00'
    verifyEntity(supervisor, "sensor.backup_state", "backed_up", {
        'friendly_name': 'Backup State',
        'last_backup': date,
        'last_uploaded': date,
        'backups': [{
            'date': date,
            'name': backup.name(),
            'size': backup.sizeString(),
            'state': backup.status(),
            'slug': backup.slug()
        }
        ],
        'backups_in_google_drive': 1,
        'backups_in_home_assistant': 1,
        'size_in_home_assistant': Estimator.asSizeString(backup.size()),
        'size_in_google_drive': Estimator.asSizeString(backup.size())
    })