from rest_framework.test import APIClient client = APIClient() response = client.get('/api/items/') assert response.status_code == 200
from rest_framework.test import APIClient client = APIClient() data = {'name': 'New Item'} response = client.post('/api/items/', data, format='json') assert response.status_code == 201
from rest_framework.test import APIClient client = APIClient() client.credentials(HTTP_AUTHORIZATION='Bearer abc123') response = client.get('/api/items/') assert response.status_code == 200In this example, we create an `APIClient`, set the `HTTP_AUTHORIZATION` header with a token, then send a GET request to `/api/items/`. We verify that the response code is 200, indicating that the authentication worked. The `rest_framework.test` package is part of the Django REST framework library.