Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: callback endpoint hook #58

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions barterdude/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def add_callback_endpoint(
hook: Callable,
mock_dependencies: Iterable[Tuple[Any, str]] = None,
):
def hook_to_callback(req):
return self._call_callback_endpoint(req, hook, mock_dependencies)
async def hook_to_callback(req: web.Request):
return await self._call_callback_endpoint(
req,
hook,
mock_dependencies
)

self.add_endpoint(
routes=routes,
Expand Down
17 changes: 17 additions & 0 deletions tests_unit/test__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
import typing
from unittest import IsolatedAsyncioTestCase
from unittest.mock import Mock, AsyncMock, patch, call

Expand Down Expand Up @@ -79,6 +81,21 @@ async def test_should_call_route_when_adding_callback_endpoint(self):
)
self.decorator.assert_called_once()

async def test_hook_to_callback_should_be_async_and_typed(self):
bd = BarterDude()
bd.add_endpoint = Mock()

hook = Mock()
bd.add_callback_endpoint(
['/my_route'],
hook,
[(Mock(), 'service')]
)

internal_hook = bd.add_endpoint.call_args_list[0][1].get('hook')
assert asyncio.iscoroutinefunction(internal_hook) is True
assert 'req' in typing.get_type_hints(internal_hook)

async def test_should_hook_call_on_callback_endpoint(self):
async def mock_hook(message, barterdude):
barterdude['service'].method_one()
Expand Down