From 95d090a7fed9d8af323e4a95a76273cd3896ff4c Mon Sep 17 00:00:00 2001 From: "bozo.kopic" Date: Wed, 6 Nov 2024 21:56:32 +0100 Subject: [PATCH] py client api update --- pyproject.toml | 2 +- src_py/hat/juggler/client.py | 7 +------ test_pytest/test_juggler.py | 24 ++++++++++-------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bc61fa7..a396652 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "hat-juggler" -version = "0.6.22" +version = "0.6.23" description = "Hat Juggler protocol" readme = "README.rst" requires-python = ">=3.10" diff --git a/src_py/hat/juggler/client.py b/src_py/hat/juggler/client.py index 0a208cd..64495ff 100644 --- a/src_py/hat/juggler/client.py +++ b/src_py/hat/juggler/client.py @@ -36,8 +36,7 @@ async def connect(address: str, notify_cb: NotifyCb | None = None, *, ssl_ctx: ssl.SSLContext | None = None, - user: str | None = None, - password: str | None = None + auth: aiohttp.BasicAuth | None = None ) -> 'Client': """Connect to remote server @@ -55,10 +54,6 @@ async def connect(address: str, client._session = aiohttp.ClientSession() try: - auth = (aiohttp.BasicAuth(user, password) - if user is not None and password is not None - else None) - client._ws = await client._session.ws_connect(address, auth=auth, ssl=ssl_ctx or False, diff --git a/test_pytest/test_juggler.py b/test_pytest/test_juggler.py index a985f36..3ecd0ef 100644 --- a/test_pytest/test_juggler.py +++ b/test_pytest/test_juggler.py @@ -1,6 +1,7 @@ import asyncio import subprocess +import aiohttp import pytest from hat import aio @@ -372,6 +373,7 @@ async def test_state_sync(port, address, change_count): async def test_basic_auth(port, address, tmp_path): user = 'user' password = 'password' + auth = aiohttp.BasicAuth(user, password) htpasswd_file = tmp_path / 'htpasswd' p = subprocess.run(['openssl', 'passwd', '-apr1', password], @@ -387,25 +389,19 @@ async def test_basic_auth(port, address, tmp_path): htpasswd_file=htpasswd_file) for _ in range(2): - with pytest.raises(Exception): - client = await juggler.connect(address) - - with pytest.raises(Exception): - client = await juggler.connect(address, - user=f'not {user}', - password=password) - - with pytest.raises(Exception): - client = await juggler.connect(address, - user=user, - password=f'not {password}') + for auth in [None, + aiohttp.BasicAuth(f'not {user}', password), + aiohttp.BasicAuth(user, f'not {password}')]: + with pytest.raises(Exception): + client = await juggler.connect(address, + auth=auth) assert conn_queue.empty() for _ in range(2): + auth = aiohttp.BasicAuth(user, password) client = await juggler.connect(address, - user=user, - password=password) + auth=auth) conn = await conn_queue.get() assert conn.is_open