def test_url_without_port_uses_default(router, client_cls): client = client_cls(url="ws://localhost") # should not raise client.start() wait_for_session(client) client.stop()
def test_ipv4_secure_websocket_connection_by_router_url( self, config_path, router): assert router.url == "wss://localhost:9443" try: ssl.PROTOCOL_TLSv1_2 except AttributeError: pytest.skip('Python Environment does not support TLS') with DateService( url="wss://localhost:9443", cert_path="./wampy/testing/keys/server_cert.pem", ) as service: wait_for_registrations(service, 1) client = Client( url="wss://localhost:9443", cert_path="./wampy/testing/keys/server_cert.pem", ) with client: wait_for_session(client) result = client.rpc.get_todays_date() today = date.today() assert result == today.isoformat()
def test_ipv4_secure_websocket_connection_by_router_url( self, config_path, router ): assert router.url == "wss://localhost:9443" try: ssl.PROTOCOL_TLSv1_2 except AttributeError: pytest.skip('Python Environment does not support TLS') with DateService( url="wss://localhost:9443", cert_path="./wampy/testing/keys/server_cert.pem", ) as service: wait_for_registrations(service, 1) client = Client( url="wss://localhost:9443", cert_path="./wampy/testing/keys/server_cert.pem", ) with client: wait_for_session(client) result = client.rpc.get_todays_date() today = date.today() assert result == today.isoformat()
def test_respond_to_ping_with_pong(config_path, router): # This test shows proper handling of ping/pong keep-alives # by connecting to a pong-demanding server (crossbar.timeout.json) # and keeping the connection open for longer than the server's timeout. # Failure would be an exception being thrown because of the server # closing the connection. class MyClient(Client): pass exceptionless = True try: client = MyClient(url=router.url) client.start() wait_for_session(client) async_adapter.sleep(5) # this is purely to demonstrate we can make calls while sending # pongs client.publish(topic="test", message="test") client.stop() except Exception as e: print(e) exceptionless = False assert exceptionless
def test_url_without_port_uses_default(router, client_cls): client = client_cls(url="ws://localhost") # should not raise client.start() wait_for_session(client) client.stop()
def test_respond_to_ping_with_pong(config_path, router): # This test shows proper handling of ping/pong keep-alives # by connecting to a pong-demanding server (crossbar.timeout.json) # and keeping the connection open for longer than the server's timeout. # Failure would be an exception being thrown because of the server # closing the connection. class MyClient(Client): pass exceptionless = True try: client = MyClient(url=router.url) client.start() wait_for_session(client) async_adapter.sleep(5) # this is purely to demonstrate we can make calls while sending # pongs client.publish(topic="test", message="test") client.stop() except Exception as e: print(e) exceptionless = False assert exceptionless
def test_client_sending_unicode_does_not_raise(router, echo_service): class MyClient(Client): pass client = MyClient(url=router.url) client.start() wait_for_session(client) response = client.rpc.echo(weird_text="100éfa") assert response is not None
def test_client_connects_to_router_by_url(router): class MyClient(Client): pass client = MyClient(url=router.url) assert client.session is None client.start() wait_for_session(client) session = client.session assert session.id is not None client.stop() assert client.session.id is None
def test_client_connects_to_router_by_instance(router): class MyClient(Client): pass client = MyClient(router=router) assert client.session is None client.start() wait_for_session(client) session = client.session assert session.id is not None assert session.client is client client.stop() assert client.session.id is None
def test_ipv4_secure_websocket_connection_by_router_instance( self, config_path, router): try: ssl.PROTOCOL_TLSv1_2 except AttributeError: pytest.skip('Python Environment does not support TLS') with DateService(router=router) as service: wait_for_registrations(service, 1) client = Client(router=router) with client: wait_for_session(client) result = client.rpc.get_todays_date() today = date.today() assert result == today.isoformat()
def test_pinging(router): with patch('wampy.transports.websocket.connection.heartbeat', 1): with patch('wampy.transports.websocket.connection.heartbeat_timeout', 2): client = Client(router.url) client.start() wait_for_session(client) assert client.is_pinging ws = client.session.connection assert ws.missed_pongs == 0 async_adapter.sleep(10) assert ws.missed_pongs == 0 client.stop()
def test_pinging(router): with patch('wampy.transports.websocket.connection.heartbeat', 1): with patch( 'wampy.transports.websocket.connection.heartbeat_timeout', 2 ): client = Client(router.url) client.start() wait_for_session(client) assert client.is_pinging ws = client.session.connection assert ws.missed_pongs == 0 async_adapter.sleep(10) assert ws.missed_pongs == 0 client.stop()
def test_pings_and_missed_pongs(router, heartbeat, heartbeat_timeout, sleep, expected_missed_pongs): with patch('wampy.transports.websocket.connection.heartbeat', heartbeat): with patch('wampy.transports.websocket.connection.heartbeat_timeout', heartbeat_timeout): with Client(url=router.url) as client: wait_for_session(client) assert client.is_pinging is True ws = client.session.connection assert ws.missed_pongs == 0 # this prevents Pongs being put into the shared queue with patch.object(ws, 'handle_pong'): async_adapter.sleep(sleep) assert client.is_pinging is False assert ws.missed_pongs == expected_missed_pongs
def test_can_start_two_clients(router): class MyClient(Client): pass app_one = MyClient(url=router.url) app_one.start() wait_for_session(app_one) assert app_one.session.id app_two = MyClient(url=router.url) app_two.start() wait_for_session(app_two) assert app_two.session.id app_one.stop() app_two.stop() assert app_one.session.id is None assert app_two.session.id is None
def test_can_start_two_clients(router): class MyClient(Client): pass app_one = MyClient(url=router.url) app_one.start() wait_for_session(app_one) assert app_one.session.id app_two = MyClient(url=router.url) app_two.start() wait_for_session(app_two) assert app_two.session.id app_one.stop() app_two.stop() assert app_one.session.id is None assert app_two.session.id is None
def test_pings_and_missed_pongs( router, heartbeat, heartbeat_timeout, sleep, expected_missed_pongs ): with patch('wampy.transports.websocket.connection.heartbeat', heartbeat): with patch( 'wampy.transports.websocket.connection.heartbeat_timeout', heartbeat_timeout ): with Client(url=router.url) as client: wait_for_session(client) assert client.is_pinging is True ws = client.session.connection assert ws.missed_pongs == 0 # this prevents Pongs being put into the shared queue with patch.object(ws, 'handle_pong'): async_adapter.sleep(sleep) assert client.is_pinging is False assert ws.missed_pongs == expected_missed_pongs