from rest_framework.test import APIClient client = APIClient() response = client.get('/api/items/')
A successful GET request returns HTTP status code 200, meaning OK. Codes like 201 indicate resource creation, 400 is a bad request, and 404 means not found.
from rest_framework.test import APIClient client = APIClient() data = {'name': 'Test Item', 'price': 10.5} response = client.post('/api/items/', data, format='json')
After a successful POST, the response data includes the created item's fields plus its generated ID.
APIClient must be imported from rest_framework.test and instantiated with parentheses. Option C imports from wrong module, C has wrong import syntax, D forgets parentheses when instantiating.
from rest_framework.test import APIClient client = APIClient() data = {'title': 'New Post'} response = client.post('/api/posts/', data) assert response.status_code == 201
Without specifying format='json', APIClient sends data as form-encoded, which the API may reject, returning 400 instead of 201.
force_authenticate sets the user directly on the client to simulate authentication, bypassing login and token checks.
