Skip to content

Commit

Permalink
Broken safir.testing.slack implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fireye04 committed May 25, 2023
1 parent d0f9512 commit 8830a23
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pytest-httpx
pytest-xdist[psutil]
types-python-dateutil
types-PyYAML
respx

# Documentation
documenteer
Expand Down
11 changes: 8 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ httpx==0.24.1 \
# via
# -c requirements/main.txt
# pytest-httpx
# respx
idna==3.4 \
--hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \
--hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2
Expand Down Expand Up @@ -474,6 +475,10 @@ requests==2.31.0 \
# via
# documenteer
# sphinx
respx==0.20.1 \
--hash=sha256:372f06991c03d1f7f480a420a2199d01f1815b6ed5a802f4e4628043a93bd03e \
--hash=sha256:cc47a86d7010806ab65abdcf3b634c56337a737bb5c4d74c19a0dfca83b3bc73
# via -r requirements/dev.in
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down Expand Up @@ -545,9 +550,9 @@ types-pyyaml==6.0.12.10 \
--hash=sha256:662fa444963eff9b68120d70cda1af5a5f2aa57900003c2006d7626450eaae5f \
--hash=sha256:ebab3d0700b946553724ae6ca636ea932c1b0868701d4af121630e78d695fc97
# via -r requirements/dev.in
typing-extensions==4.6.1 \
--hash=sha256:558bc0c4145f01e6405f4a5fdbd82050bd221b119f4bf72a961a1cfd471349d6 \
--hash=sha256:6bac751f4789b135c43228e72de18637e9a6c29d12777023a703fd1a6858469f
typing-extensions==4.6.2 \
--hash=sha256:06006244c70ac8ee83fa8282cb188f697b8db25bc8b4df07be1873c43897060c \
--hash=sha256:3a8b36f13dd5fdc5d1b16fe317f5668545de77fa0b8e02006381fd49d731ab98
# via
# -c requirements/main.txt
# mypy
Expand Down
6 changes: 3 additions & 3 deletions requirements/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ structlog==23.1.0 \
# via
# -r requirements/main.in
# safir
typing-extensions==4.6.1 \
--hash=sha256:558bc0c4145f01e6405f4a5fdbd82050bd221b119f4bf72a961a1cfd471349d6 \
--hash=sha256:6bac751f4789b135c43228e72de18637e9a6c29d12777023a703fd1a6858469f
typing-extensions==4.6.2 \
--hash=sha256:06006244c70ac8ee83fa8282cb188f697b8db25bc8b4df07be1873c43897060c \
--hash=sha256:3a8b36f13dd5fdc5d1b16fe317f5668545de77fa0b8e02006381fd49d731ab98
# via
# arq
# pydantic
Expand Down
1 change: 1 addition & 0 deletions src/semaphore/worker/functions/send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ async def send_message(ctx: Dict[Any, Any], message: str) -> None:

slack_message = SlackMessage(message=message)
await client.post(slack_message)
return slack_message
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import pytest
import pytest_asyncio
import respx
import structlog
from asgi_lifespan import LifespanManager
from httpx import AsyncClient
from safir.testing.slack import MockSlackWebhook, mock_slack_webhook

from semaphore import main
from semaphore import config, main

if TYPE_CHECKING:
from typing import AsyncIterator
Expand Down Expand Up @@ -53,3 +55,8 @@ def worker_context() -> dict[Any, Any]:
ctx["logger"] = logger

return ctx


@pytest.fixture
def mock_slack(respx_mock: respx.Router) -> MockSlackWebhook:
return mock_slack_webhook(config.slack_webhook, respx_mock)
20 changes: 18 additions & 2 deletions tests/worker/worker_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from typing import Any

import pytest
from httpx import AsyncClient
from safir.slack.blockkit import SlackMessage
from safir.testing.slack import MockSlackWebhook

from semaphore.worker.functions.ping import ping
from semaphore.worker.functions.send_message import send_message
Expand All @@ -18,5 +21,18 @@ async def test_ping(worker_context: dict[Any, Any]) -> None:

@pytest.mark.asyncio
async def test_message(worker_context: dict[Any, Any]) -> None:
result = await send_message(worker_context, "test 1 2 3")
assert result is None
message = "test 1 2 3"
result = await send_message(worker_context, message)
assert result is SlackMessage(message=message)


@pytest.mark.asyncio
async def test_something(
worker_context: dict[Any, Any],
client: AsyncClient,
mock_slack: MockSlackWebhook,
) -> None:
# Do something with client that generates Slack messages.
assert mock_slack.messages == await send_message(
worker_context, "test 1 2 3"
)

0 comments on commit 8830a23

Please sign in to comment.