Skip to content

Commit

Permalink
feat: fixturize pytest (#694)
Browse files Browse the repository at this point in the history
feat: fixturize and convert to pytest
  • Loading branch information
taddes authored May 9, 2024
1 parent 69941d6 commit 20ed0da
Show file tree
Hide file tree
Showing 3 changed files with 1,027 additions and 1,020 deletions.
16 changes: 10 additions & 6 deletions tests/integration/async_push_test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ async def ws_server_send(self, message: dict) -> None:
log.debug(f"Send: {payload}")
await self.ws.send(payload)

async def hello(self, uaid: str | None = None, services: list[str] | None = None):
def get_host_client_endpoint(self) -> str:
"""Return host endpoint from client."""
parsed = urlparse(list(self.channels.values())[0])
return f"{parsed.scheme}://{parsed.netloc}"

async def hello(self, uaid: str | None = None, services: dict[str, str] | None = None):
"""Hello verification."""
if not self.ws:
raise WebSocketException("WebSocket client not available as expected.")
Expand Down Expand Up @@ -109,7 +114,7 @@ async def hello(self, uaid: str | None = None, services: list[str] | None = None
self.uaid = result["uaid"]
return result

async def broadcast_subscribe(self, services: list[str]) -> None:
async def broadcast_subscribe(self, services: dict[str, str]) -> None:
"""Broadcast WebSocket subscribe."""
if not self.ws:
raise WebSocketException("WebSocket client not available as expected.")
Expand Down Expand Up @@ -170,7 +175,7 @@ async def send_notification(
self,
channel=None,
version=None,
data: str | None = None,
data: str | bytes | None = None,
use_header: bool = True,
status: int = 201,
# 202 status reserved for yet to be implemented push w/ reciept.
Expand Down Expand Up @@ -210,9 +215,9 @@ async def send_notification(
headers.update({"Crypto-Key": f"{headers.get('Crypto-Key', '')};{ckey}"})
if topic:
headers["Topic"] = topic
body: str = data or ""
body: str | bytes = data or ""
method: str = "POST"
log.debug(f"{method} body: {body}")
log.debug(f"{method} body: {body!r}")
log.debug(f" headers: {headers}")
async with httpx.AsyncClient() as httpx_client:
resp = await httpx_client.request(
Expand Down Expand Up @@ -267,7 +272,6 @@ async def get_broadcast(self, timeout=1): # pragma: no cover
d = await asyncio.wait_for(self.ws.recv(), timeout)
log.debug(f"Recv: {d}")
result = json.loads(d)
assert result.get("messageType") == ClientMessageType.BROADCAST.value
return result
except WebSocketException as ex: # pragma: no cover
log.error(f"Error: {ex}")
Expand Down
Loading

0 comments on commit 20ed0da

Please sign in to comment.