Replies: 1 comment 3 replies
-
For testing with FastAPI, I would recommend to just override the dependency. current_user = auth.current_user()
@app.get("/protected", name="protected")
async def protected(
user: FiefUserInfo = Depends(current_user),
):
return HTMLResponse(
f"<h1>You are authenticated. Your user email is {user['email']}</h1>"
) mock_user = {
"sub": "aeeb8bfa-e8f4-4724-9427-c3d5af66190e",
"email": "[email protected]",
"tenant_id": "c91ecb7f-359c-4244-8385-51ecd6c0d06b",
"fields": {
"first_name": "Anne",
"last_name": "De Bretagne"
}
}
app.dependency_overrides[current_user] = lambda: mock_user |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Would be nice to have some easy, out-of-the-box implementations that work well with how you would typically test an integration that this Fief client ships with (FastAPI, Flask, or the library behind a Python CLI). This could even completely elide Fief in the test scenario where I want to just inject fake auth data (typically, in testing I don't necessarily care about using my real auth service data, which is separate anyways). Still thinking through what would be best for this, this is my sketch (I am using it with a few FastAPI services and a SDK/CLI python package)
FastAPI testing:
For CLI testing, I'm not sure I have a well-formed need yet, but it might be good to implement something useful with how Click does testing
Beta Was this translation helpful? Give feedback.
All reactions