Coverage for tests/test_callable_endpoint.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from functools import partial 1abcde

2from typing import Optional 1abcde

3 

4from fastapi import FastAPI 1abcde

5from fastapi.testclient import TestClient 1abcde

6 

7 

8def main(some_arg, q: Optional[str] = None): 1abcde

9 return {"some_arg": some_arg, "q": q} 1abcde

10 

11 

12endpoint = partial(main, "foo") 1abcde

13 

14app = FastAPI() 1abcde

15 

16app.get("/")(endpoint) 1abcde

17 

18 

19client = TestClient(app) 1abcde

20 

21 

22def test_partial(): 1abcde

23 response = client.get("/?q=bar") 1abcde

24 data = response.json() 1abcde

25 assert data == {"some_arg": "foo", "q": "bar"} 1abcde