Complete the code to create a test client for the FastAPI app.
from fastapi.testclient import TestClient from main import app client = [1](app)
The TestClient class from fastapi.testclient is used to create a test client for the FastAPI app.
Complete the code to send a GET request to the '/items' path.
response = client.[1]('/items')
To test a GET path operation, use the get method of the test client.
Fix the error in the assertion to check the response status code is 200.
assert response.status_code == [1]The status code 200 means the request was successful.
Fill both blanks to test a POST request with JSON data and check the response status code.
response = client.[1]('/items', json=[2]) assert response.status_code == 201
Use post to send data and a dictionary for JSON payload.
Fill all three blanks to test a PUT request updating an item and verify the response JSON content.
response = client.[1]('/items/1', json=[2]) assert response.status_code == 200 assert response.json() == [3]
Use put to update an item, send updated data as JSON, and check the returned JSON matches the updated item.