예제 #1
0
def test_cloud_remote_match(live_cloud, live_hub):
    config.dump_state()
    live_hub.ping()
    local_tz = live_hub.tz()
    remote_tz = live_hub.tz(remote=True)

    assert local_tz == remote_tz
예제 #2
0
def main():
    fh, tmp = tempfile.mkstemp()
    config.setStatePath(tmp)

    assert cloud.authenticate()
    config.dump_state()
    print(hub.tz())
    os.remove(tmp)
예제 #3
0
def test_cloud_refresh_force(live_cloud):
    config.dump_state()
    timestamp_before = live_cloud._getAttr('last_refresh')
    token_before = live_cloud.token()
    time.sleep(2)  # ensure timestamp has a diff
    live_cloud.refresh(force=True)
    config.dump_state()
    assert timestamp_before < live_cloud._getAttr('last_refresh')
    assert token_before != live_cloud.token()
예제 #4
0
def live_hub():
    config.setStatePath()  # we assume the default config will be "live"
    configfile, configpath = tempfile.mkstemp(suffix='live_hub')
    config.setStatePath(configpath, copy_current=True)
    from cozify import hub
    assert hub.ping()
    print('Live hub state for testing:')
    config.dump_state()  # dump state so it's visible in failed test output
    yield hub
    config.setStatePath()
    os.remove(configpath)
예제 #5
0
def online_device():
    dev = None
    store = None
    config.dump_state()  # dump state so it's visible in failed test output
    devs = hub.devices(capabilities=hub.capability.BRIGHTNESS)
    for i, d in devs.items():
        if d['state']['reachable'] and 'test' in d['name']:
            dev = d
            # store state so it can be restored after tests
            store = d['state'].copy()
            break
    if dev is None:
        pytest.xfail(
            'Cannot run certain device tests, no COLOR_HS device online where name includes \'test\'.'
        )
    logging.info('online_device state before use ({1}): {0}'.format(
        store, _h6_dict(store)))
    yield dev
    logging.info(
        'online_device state after use, before rollback ({1}): {0}'.format(
            dev['state'], _h6_dict(dev['state'])))
    hub.device_state_replace(dev['id'], store)
예제 #6
0
def tmp_hub(tmp_cloud):
    with Tmp_hub(tmp_cloud) as hub_obj:
        print('Tmp hub state for testing:')
        config.dump_state()
        yield hub_obj
예제 #7
0
def test_cloud_refresh_expiry_not_over(tmp_cloud):
    config.dump_state()
    assert not cloud._need_refresh(force=False,
                                   expiry=datetime.timedelta(days=2))
예제 #8
0
def test_cloud_refresh_expiry_over(tmp_cloud):
    config.dump_state()
    assert cloud._need_refresh(force=False, expiry=datetime.timedelta(hours=1))
예제 #9
0
def test_cloud_refresh_invalid(tmp_cloud):
    config.state['Cloud']['last_refresh'] = 'intentionally bad'
    config.dump_state()
    assert cloud._need_refresh(force=False,
                               expiry=datetime.timedelta(days=365))
예제 #10
0
def test_cloud_refresh_force(tmp_cloud):
    config.dump_state()
    assert cloud._need_refresh(force=True, expiry=datetime.timedelta(days=365))
예제 #11
0
def test_cloud_refresh_cold(tmp_cloud):
    config.state.remove_option('Cloud', 'last_refresh')
    config.dump_state()
    assert cloud._need_refresh(force=False, expiry=tmp_cloud.expiry)
예제 #12
0
def live_hub():
    config.setStatePath()  # default config assumed to be live
    print('Live hub state for testing:')
    config.dump_state()  # dump state so it's visible in failed test output
    from cozify import hub
    yield hub