mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-07 01:48:53 +00:00
test(whatsapp): reuse media send client mock
This commit is contained in:
parent
353dfed502
commit
10ce839e3d
@ -79,6 +79,16 @@ def _make_channel(config: dict | None = None) -> WhatsAppChannel:
|
|||||||
return ch
|
return ch
|
||||||
|
|
||||||
|
|
||||||
|
def _make_send_client() -> SimpleNamespace:
|
||||||
|
return SimpleNamespace(
|
||||||
|
send_message=AsyncMock(),
|
||||||
|
send_image=AsyncMock(),
|
||||||
|
send_video=AsyncMock(),
|
||||||
|
send_audio=AsyncMock(),
|
||||||
|
send_document=AsyncMock(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _patch_neonize_api(monkeypatch, detect_mime=None) -> None:
|
def _patch_neonize_api(monkeypatch, detect_mime=None) -> None:
|
||||||
detect_mime = detect_mime or (
|
detect_mime = detect_mime or (
|
||||||
lambda path, *, mime: mimetypes.guess_type(path)[0] or "application/octet-stream"
|
lambda path, *, mime: mimetypes.guess_type(path)[0] or "application/octet-stream"
|
||||||
@ -183,13 +193,7 @@ async def test_login_fails_when_connect_task_fails(monkeypatch) -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_text_uses_neonize_send_message(monkeypatch) -> None:
|
async def test_send_text_uses_neonize_send_message(monkeypatch) -> None:
|
||||||
_patch_neonize_api(monkeypatch)
|
_patch_neonize_api(monkeypatch)
|
||||||
client = SimpleNamespace(
|
client = _make_send_client()
|
||||||
send_message=AsyncMock(),
|
|
||||||
send_image=AsyncMock(),
|
|
||||||
send_video=AsyncMock(),
|
|
||||||
send_audio=AsyncMock(),
|
|
||||||
send_document=AsyncMock(),
|
|
||||||
)
|
|
||||||
ch = _make_channel()
|
ch = _make_channel()
|
||||||
ch._client = client
|
ch._client = client
|
||||||
ch._connected = True
|
ch._connected = True
|
||||||
@ -202,13 +206,7 @@ async def test_send_text_uses_neonize_send_message(monkeypatch) -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_media_dispatches_by_mimetype(monkeypatch) -> None:
|
async def test_send_media_dispatches_by_mimetype(monkeypatch) -> None:
|
||||||
_patch_neonize_api(monkeypatch)
|
_patch_neonize_api(monkeypatch)
|
||||||
client = SimpleNamespace(
|
client = _make_send_client()
|
||||||
send_message=AsyncMock(),
|
|
||||||
send_image=AsyncMock(),
|
|
||||||
send_video=AsyncMock(),
|
|
||||||
send_audio=AsyncMock(),
|
|
||||||
send_document=AsyncMock(),
|
|
||||||
)
|
|
||||||
ch = _make_channel()
|
ch = _make_channel()
|
||||||
ch._client = client
|
ch._client = client
|
||||||
ch._connected = True
|
ch._connected = True
|
||||||
@ -237,13 +235,7 @@ async def test_send_media_dispatches_by_mimetype(monkeypatch) -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_mislabeled_audio_as_document(monkeypatch) -> None:
|
async def test_send_mislabeled_audio_as_document(monkeypatch) -> None:
|
||||||
_patch_neonize_api(monkeypatch, detect_mime=lambda path, *, mime: "audio/x-wav")
|
_patch_neonize_api(monkeypatch, detect_mime=lambda path, *, mime: "audio/x-wav")
|
||||||
client = SimpleNamespace(
|
client = _make_send_client()
|
||||||
send_message=AsyncMock(),
|
|
||||||
send_image=AsyncMock(),
|
|
||||||
send_video=AsyncMock(),
|
|
||||||
send_audio=AsyncMock(),
|
|
||||||
send_document=AsyncMock(),
|
|
||||||
)
|
|
||||||
ch = _make_channel()
|
ch = _make_channel()
|
||||||
ch._client = client
|
ch._client = client
|
||||||
ch._connected = True
|
ch._connected = True
|
||||||
@ -270,13 +262,7 @@ async def test_send_mislabeled_audio_as_document(monkeypatch) -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_unsupported_ogg_audio_as_document(monkeypatch) -> None:
|
async def test_send_unsupported_ogg_audio_as_document(monkeypatch) -> None:
|
||||||
_patch_neonize_api(monkeypatch, detect_mime=lambda path, *, mime: "audio/ogg")
|
_patch_neonize_api(monkeypatch, detect_mime=lambda path, *, mime: "audio/ogg")
|
||||||
client = SimpleNamespace(
|
client = _make_send_client()
|
||||||
send_message=AsyncMock(),
|
|
||||||
send_image=AsyncMock(),
|
|
||||||
send_video=AsyncMock(),
|
|
||||||
send_audio=AsyncMock(),
|
|
||||||
send_document=AsyncMock(),
|
|
||||||
)
|
|
||||||
ch = _make_channel()
|
ch = _make_channel()
|
||||||
ch._client = client
|
ch._client = client
|
||||||
ch._connected = True
|
ch._connected = True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user