Complete the code to import the FastAPI testing client.
from fastapi.testclient import [1]
The TestClient is the correct class to import for testing FastAPI apps.
Complete the code to create a test client for the FastAPI app named 'app'.
client = [1](app)You create a test client by calling TestClient with the FastAPI app instance.
Fix the error in the test function to send a GET request to '/login'.
def test_login(): response = client.[1]('/login') assert response.status_code == 200
The method to send a GET request is get. Using post or others will not match the GET route.
Fill both blanks to send a POST request with JSON data to '/token'.
def test_token(): response = client.[1]('/token', json=[2]) assert response.status_code == 200
To send JSON data in a POST request, use post method and pass the correct dictionary with keys 'username' and 'password'.
Fill all three blanks to check the token response contains 'access_token' and is a string.
def test_token_response(): response = client.post('/token', json={'username': 'user', 'password': 'pass'}) data = response.json() assert '[1]' in data assert isinstance(data['[2]'], [3])
int instead of str for the token type.The response JSON should contain the key 'access_token' and its value should be a string type.