def test_websocket_client(fake_home: Home, home_data): fake_home.enable_events() # preparing event data for client added client_base_id = "00000000-0000-0000-0000-000000000000" client_added = home_data["clients"][client_base_id].copy() client_added_id = "NEW_CLIENT" client_added["id"] = client_added_id send_event(fake_home, EventType.CLIENT_ADDED, "client", client_added) # preparing event data for client changed client_changed = home_data["clients"][client_base_id].copy() client_changed["label"] = "CHANGED" send_event(fake_home, EventType.CLIENT_CHANGED, "client", client_changed) # preparing event data for client remove client_delete_id = "AA000000-0000-0000-0000-000000000000" c = fake_home.search_client_by_id(client_delete_id) assert c != None assert c.label == "REMOVE_ME" send_event(fake_home, EventType.CLIENT_REMOVED, "id", client_delete_id) time.sleep(1) d = fake_home.search_client_by_id(client_added_id) assert d.label == "TEST-Client" assert isinstance(d, Client) d = fake_home.search_client_by_id(client_base_id) assert d.label == "CHANGED" assert isinstance(d, Client) assert fake_home.search_client_by_id(client_delete_id) == None fake_home.disable_events()
def test_auth_challenge_no_pin(fake_home: Home): with no_ssl_verification(): auth = Auth(fake_home) sgtin = "3014F711A000000BAD0C0DED" devicename = "auth_test" assert auth.connectionRequest(sgtin, devicename).status_code == 200 assert auth.isRequestAcknowledged() == False assert auth.isRequestAcknowledged() == False fake_home._connection._restCall("auth/simulateBlueButton") assert auth.isRequestAcknowledged() == True token = auth.requestAuthToken() assert token == hashlib.sha512( auth.uuid.encode('utf-8')).hexdigest().upper() resultId = auth.confirmAuthToken(token) assert resultId == auth.uuid fake_home.get_current_state() client = fake_home.search_client_by_id(resultId) assert client != None assert client.label == devicename
def test_websocket_error(fake_home: Home, home_data): global ws_error_called def on_error(err): global ws_error_called ws_error_called = True fake_home.onWsError += on_error fake_home.enable_events() with no_ssl_verification(): fake_home._connection._restCallRequestCounter = 1 fake_home._restCall("ws/sleep", json.dumps({"seconds": 5})) assert ws_error_called # testing automatic reconnection time.sleep(5) # give the reconnection routine time to reconnect client_base_id = "00000000-0000-0000-0000-000000000000" client_changed = home_data["clients"][client_base_id].copy() client_changed["label"] = "CHANGED" send_event(fake_home, EventType.CLIENT_CHANGED, "client", client_changed) time.sleep(1) d = fake_home.search_client_by_id(client_base_id) assert d.label == "CHANGED" assert isinstance(d, Client) fake_home.disable_events()
def test_clients(fake_home: Home): client = fake_home.search_client_by_id( "00000000-0000-0000-0000-000000000000") assert client.label == "TEST-Client" assert client.homeId == "00000000-0000-0000-0000-000000000001" assert client.id == "00000000-0000-0000-0000-000000000000" assert client.clientType == ClientType.APP assert (client._rawJSONData == fake_home_download_configuration() ["clients"]["00000000-0000-0000-0000-000000000000"]) assert str(client) == "label(TEST-Client)"
def test_clients(fake_home: Home): client = fake_home.search_client_by_id( '00000000-0000-0000-0000-000000000000') assert client.label == 'TEST-Client' assert client.homeId == '00000000-0000-0000-0000-000000000001' assert client.id == '00000000-0000-0000-0000-000000000000' assert client.clientType == ClientType.APP assert client._rawJSONData == fake_home_download_configuration( )["clients"]['00000000-0000-0000-0000-000000000000'] assert str(client) == "label(TEST-Client)"