File tree Expand file tree Collapse file tree
src/ContentProcessorAPI/app/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import pytest
2+ from fastapi import FastAPI , Depends
3+ from fastapi .testclient import TestClient
4+ from src .ContentProcessorAPI .app .dependencies import get_token_header , get_query_token
5+ # from starlette.status import HTTP_400_BAD_REQUEST
6+
7+
8+ @pytest .fixture
9+ def test_app ():
10+ app = FastAPI ()
11+
12+ @app .get ("/header-protected" )
13+ async def protected_route_header (dep = Depends (get_token_header )):
14+ return {"message" : "Success" }
15+
16+ @app .get ("/query-protected" )
17+ async def protected_route_query (dep = Depends (get_query_token )):
18+ return {"message" : "Success" }
19+
20+ return app
21+
22+
23+ def test_get_token_header_fails (test_app ):
24+ client = TestClient (test_app )
25+ # Provide the required header so FastAPI doesn't return 422
26+ response = client .get ("/header-protected" , headers = {"x-token" : "fake" })
27+ assert response .status_code == 400
28+ assert response .json () == {"detail" : "X-Token header invalid" }
29+
30+
31+ def test_get_query_token_fails (test_app ):
32+ client = TestClient (test_app )
33+ # Provide the required query param so FastAPI doesn't return 422
34+ response = client .get ("/query-protected?token=fake" )
35+ assert response .status_code == 400
36+ assert response .json () == {"detail" : "No ... token provided" }
You can’t perform that action at this time.
0 commit comments