-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Run validation on the arguments using the `inspect.Signature.bind` built-in utility * If invalid, raise error. Otherwise, proceed to sending task to queue * This aims to help user identity bug early on * We might consider turning this feature on only when AIOTASKQ_DEBUG=1 or something like that in the future Bump version to 0.0.12 Signed-off-by: Imran Ariffin <ariffin.imran@gmail.com>
- Loading branch information
1 parent
10f264e
commit f02f6ce
Showing
5 changed files
with
76 additions
and
5 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
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,55 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from aiotaskq.exceptions import InvalidArgument | ||
from tests.apps import simple_app | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from aiotaskq.task import Task | ||
from tests.conftest import WorkerFixture | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"task,invalid_args,invalid_kwargs", | ||
[ | ||
pytest.param( | ||
*(simple_app.add, tuple(), {"invalid_kwarg_1": 1, "invalid_kwarg_2": 2}), | ||
id="Provide invalid keyword arguments", | ||
), | ||
pytest.param( | ||
*(simple_app.power, (1, 2, 3), {}), | ||
id="Provide more positional arguments than allowed", | ||
), | ||
pytest.param( | ||
*(simple_app.echo, tuple(), {"y": 1}), | ||
id="Provide positional arguments as keyword, but missing one", | ||
), | ||
pytest.param( | ||
*(simple_app.add, (1,), {}), | ||
id="Provide positional argument, but missing one", | ||
), | ||
], | ||
) | ||
async def test_invalid_argument_provided_to_apply_async( | ||
worker: "WorkerFixture", | ||
task: "Task", | ||
invalid_args: tuple, | ||
invalid_kwargs: dict, | ||
): | ||
# Given a worker running in the background | ||
await worker.start(simple_app.__name__) | ||
|
||
# When a task has been applied with invalid arguments | ||
# Then an error should raised | ||
error = None | ||
try: | ||
_ = await task.apply_async(*invalid_args, **invalid_kwargs) | ||
except InvalidArgument as exc: | ||
error = exc | ||
finally: | ||
assert str(error) == ( | ||
f"These arguments are invalid: args={invalid_args}," | ||
f" kwargs={invalid_kwargs}" | ||
) |