Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not wrap async function with threaded_callback
Async callbacks are being wrapped by ThreadedCoroutine when they shouldn't be. For some context, the purpose of ThreadedCoroutine is to allow sync callbacks with aiohttp client. When the callback is an async function, this condition should skip this behavior. See #256
- Loading branch information
Showing
8 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Local imports. | ||
import uplink | ||
|
||
# Third-party imports | ||
import aiohttp | ||
import pytest | ||
from uplink.clients.aiohttp_ import AiohttpClient | ||
|
||
# Constants | ||
BASE_URL = "https://example.com/" | ||
SIMPLE_RESPONSE = "simple response" | ||
|
||
|
||
@pytest.fixture | ||
def mock_aiohttp_session(mocker): | ||
return mocker.Mock(spec=aiohttp.ClientSession) | ||
|
||
|
||
@uplink.response_handler | ||
async def simple_async_handler(response): | ||
return SIMPLE_RESPONSE | ||
|
||
|
||
class Calendar(uplink.Consumer): | ||
@simple_async_handler | ||
@uplink.get("todos/{todo_id}") | ||
def get_todo(self, todo_id): | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_simple_async_handler(mock_aiohttp_session, mock_response): | ||
mock_response.status = 200 | ||
|
||
async def request(*args, **kwargs): | ||
return mock_response | ||
|
||
mock_aiohttp_session.request = request | ||
|
||
calendar = Calendar( | ||
base_url=BASE_URL, client=AiohttpClient(mock_aiohttp_session) | ||
) | ||
|
||
# Run | ||
response = await calendar.get_todo(todo_id=1) | ||
|
||
# Verify | ||
assert response == SIMPLE_RESPONSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
|
||
abc = six.moves.collections_abc | ||
reraise = six.reraise | ||
wraps = six.wraps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters