-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_hello.py
More file actions
34 lines (27 loc) · 1.02 KB
/
test_hello.py
File metadata and controls
34 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from fastapi import Depends, FastAPI, status
from fastapi.security import HTTPBearer
from fastapi.testclient import TestClient
from http_app.routes.auth import decode_jwt
async def _fake_decode_jwt(
security_scopes=None,
config=None,
jwks_client=None,
token=Depends(HTTPBearer()),
):
return {"token": token.credentials}
async def test_hello_renders_what_returned_by_decoder(
testapp: FastAPI,
):
testapp.dependency_overrides[decode_jwt] = _fake_decode_jwt
ac = TestClient(app=testapp, base_url="http://test")
response = ac.get(
"/hello/",
headers={"Authorization": "Bearer some_token"},
)
assert response.status_code == status.HTTP_200_OK
assert '"token": "some_token"' in response.text
async def test_hello_returns_401_without_token(testapp: FastAPI):
testapp.dependency_overrides[decode_jwt] = _fake_decode_jwt
ac = TestClient(app=testapp, base_url="http://test")
response = ac.get("/hello/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED