Integration Testing
Overview
Test Structure
Basic Pattern
@pytest.mark.django_db
def test_user_workflow(client, user, other_fixtures):
"""Test description of what workflow is being tested."""
# 1. Login user if authentication is required
client.force_login(user)
# 2. Make GET request to view page
response = client.get(reverse("app:view-name", args=[obj.id]))
assert response.status_code == 200
assert "Expected content" in response.content.decode()
# 3. Make POST request to submit form
response = client.post(
reverse("app:action-name", args=[obj.id]),
{
"field1": "value1",
"field2": "value2",
}
)
assert response.status_code == 302 # Redirect after success
# 4. Verify database changes
obj.refresh_from_db()
assert obj.field1 == "value1"
# 5. Verify UI reflects changes
response = client.get(reverse("app:view-name", args=[obj.id]))
assert "value1" in response.content.decode()Available Fixtures
Common Test Scenarios
Testing Authentication
Testing Form Submissions
Testing Permissions
Testing Search and Filtering
Best Practices
Running Integration Tests
Debugging Tips
Example: Complete Integration Test
Last updated