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
def main(): fh, tmp = tempfile.mkstemp() config.setStatePath(tmp) assert cloud.authenticate() config.dump_state() print(hub.tz()) os.remove(tmp)
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()
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)
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)
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
def test_cloud_refresh_expiry_not_over(tmp_cloud): config.dump_state() assert not cloud._need_refresh(force=False, expiry=datetime.timedelta(days=2))
def test_cloud_refresh_expiry_over(tmp_cloud): config.dump_state() assert cloud._need_refresh(force=False, expiry=datetime.timedelta(hours=1))
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))
def test_cloud_refresh_force(tmp_cloud): config.dump_state() assert cloud._need_refresh(force=True, expiry=datetime.timedelta(days=365))
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)
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