Challenge - 5 Problems
API Endpoint Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the response status code for a successful GET request in Django REST Framework test?
Consider a Django REST Framework API endpoint tested with APIClient's get method. What status code should you expect for a successful GET request?
Django
from rest_framework.test import APIClient client = APIClient() response = client.get('/api/items/')
Attempts:
2 left
💡 Hint
A successful GET request usually returns a status code indicating success without creating new resources.
✗ Incorrect
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.
❓ state_output
intermediate2:00remaining
What is the value of response.data after posting valid data?
Given a Django REST Framework API test that posts valid data to create a new item, what will response.data contain?
Django
from rest_framework.test import APIClient client = APIClient() data = {'name': 'Test Item', 'price': 10.5} response = client.post('/api/items/', data, format='json')
Attempts:
2 left
💡 Hint
When a new item is created, the response usually includes the new item's ID along with the data sent.
✗ Incorrect
After a successful POST, the response data includes the created item's fields plus its generated ID.
📝 Syntax
advanced2:00remaining
Which option correctly imports and uses APIClient in Django REST Framework tests?
Select the option that correctly imports APIClient and uses it to make a GET request in a Django test.
Attempts:
2 left
💡 Hint
Check the correct import path and usage syntax for APIClient.
✗ Incorrect
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.
🔧 Debug
advanced2:00remaining
Why does this test raise an AssertionError when checking response status?
This test expects status code 201 but fails. Why?
from rest_framework.test import APIClient
client = APIClient()
data = {'title': 'New Post'}
response = client.post('/api/posts/', data)
assert response.status_code == 201
Django
from rest_framework.test import APIClient client = APIClient() data = {'title': 'New Post'} response = client.post('/api/posts/', data) assert response.status_code == 201
Attempts:
2 left
💡 Hint
Check how data is sent in POST requests with APIClient.
✗ Incorrect
Without specifying format='json', APIClient sends data as form-encoded, which the API may reject, returning 400 instead of 201.
🧠 Conceptual
expert2:00remaining
Which option best describes the purpose of force_authenticate in DRF APIClient tests?
In Django REST Framework tests, what does the method force_authenticate do when used with APIClient?
Attempts:
2 left
💡 Hint
Think about how tests simulate logged-in users without real login.
✗ Incorrect
force_authenticate sets the user directly on the client to simulate authentication, bypassing login and token checks.