FastAPI - Path Parameters - str - test
Keyboard shortcuts
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
FastAPI - Path Parameters - str - test
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_foobar():
response = client.get("/user/foobar")
assert response.status_code == 200
assert response.json() == {'msg': "user 'foobar'"}
def test_foo_bar():
response = client.get("/user/foo bar")
assert response.status_code == 200
assert response.json() == {'msg': "user 'foo bar'"}
def test_user():
response = client.get("/user/")
assert response.status_code == 404
assert response.json() == {'detail': 'Not Found'}