Skip to content

Commit 559ead2

Browse files
authored
Merge pull request #4 from taskiq-python/feature/fastapi-tests
2 parents 0757ce1 + ab3e479 commit 559ead2

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_fastapi.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Any
2+
from unittest.mock import patch
3+
4+
from taskiq_dependencies import DependencyGraph
5+
6+
7+
class MyFastapiDepends:
8+
def __init__(self, dependency: Any, use_cache: bool = False) -> None:
9+
self.dependency = dependency
10+
self.use_cache = use_cache
11+
12+
13+
def test_dependency_swap() -> None:
14+
"""
15+
Test that dependency classes are swapped.
16+
17+
This test checks that if function depends on FastAPI depends, it will
18+
be swapped and resolved.
19+
"""
20+
with patch("taskiq_dependencies.graph.FastapiDepends", MyFastapiDepends):
21+
22+
def func_a() -> int:
23+
return 1
24+
25+
def func_b(dep_a: int = MyFastapiDepends(func_a)) -> int: # type: ignore
26+
return dep_a
27+
28+
with DependencyGraph(func_b).sync_ctx() as ctx:
29+
kwargs = ctx.resolve_kwargs()
30+
31+
assert kwargs == {"dep_a": 1}

0 commit comments

Comments
 (0)