Skip to content

Commit

Permalink
py client api update
Browse files Browse the repository at this point in the history
  • Loading branch information
bozokopic committed Nov 6, 2024
1 parent fdb079e commit 95d090a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 1 addition & 6 deletions src_py/hat/juggler/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
24 changes: 10 additions & 14 deletions test_pytest/test_juggler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import subprocess

import aiohttp
import pytest

from hat import aio
Expand Down Expand Up @@ -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],
Expand All @@ -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
Expand Down

0 comments on commit 95d090a

Please sign in to comment.