mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-11 16:54:08 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
81 lines
2.0 KiB
Python
81 lines
2.0 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""Shared fixtures and envelope builders."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import datetime as dt
|
|
import json
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
from signal_bot.config import Config
|
|
from signal_bot.store import Store
|
|
from signal_bot.transport_fake import FakeTransport
|
|
|
|
WATCHED_GROUP = "group-watched=="
|
|
SECOND_GROUP = "group-second=="
|
|
OTHER_GROUP = "group-other=="
|
|
|
|
|
|
@pytest.fixture
|
|
def config() -> Config:
|
|
return Config(
|
|
phone_number="+15550000000",
|
|
group_ids=(WATCHED_GROUP, SECOND_GROUP),
|
|
api_base_url="http://localhost:9922",
|
|
database_path=":memory:",
|
|
cooldown_seconds=10,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def store() -> Store:
|
|
with Store(":memory:") as opened:
|
|
yield opened
|
|
|
|
|
|
@pytest.fixture
|
|
def transport() -> FakeTransport:
|
|
return FakeTransport()
|
|
|
|
|
|
@pytest.fixture
|
|
def clock() -> dt.datetime:
|
|
return dt.datetime(2026, 8, 29, 12, 0, tzinfo=dt.UTC)
|
|
|
|
|
|
def envelope(
|
|
*,
|
|
text: str | None = "hello",
|
|
group_id: str | None = WATCHED_GROUP,
|
|
uuid: str = "uuid-alice",
|
|
name: str = "Alice",
|
|
sticker: bool = False,
|
|
reaction: bool = False,
|
|
sync: bool = False,
|
|
) -> str:
|
|
"""Build one raw websocket frame in either envelope shape."""
|
|
payload: dict[str, Any] = {"timestamp": 1719177917717}
|
|
if text is not None:
|
|
payload["message"] = text
|
|
if group_id is not None:
|
|
payload["groupInfo"] = {"groupId": group_id, "type": "DELIVER"}
|
|
if sticker:
|
|
payload["sticker"] = {"packId": "abc", "stickerId": 6}
|
|
if reaction:
|
|
payload["reaction"] = {"emoji": "👍", "targetAuthor": "x"}
|
|
|
|
body: dict[str, Any] = {
|
|
"source": name,
|
|
"sourceUuid": uuid,
|
|
"sourceName": name,
|
|
"sourceDevice": 69,
|
|
"timestamp": 1719177917717,
|
|
}
|
|
if sync:
|
|
body["syncMessage"] = {"sentMessage": payload}
|
|
else:
|
|
body["dataMessage"] = payload
|
|
return json.dumps({"envelope": body, "account": "+15550000000"})
|