Skip to content

test: drive middleware via django.test.Client#3

Open
marcin-prerender wants to merge 1 commit into
add-prerender-djangofrom
full-django-test-client
Open

test: drive middleware via django.test.Client#3
marcin-prerender wants to merge 1 commit into
add-prerender-djangofrom
full-django-test-client

Conversation

@marcin-prerender
Copy link
Copy Markdown

Stacked on top of #1 (add-prerender-django). Will auto-retarget to main once #1 merges.

What

Replace RequestFactory (which bypasses MIDDLEWARE ordering and URL resolution) with the full django.test.Client. Register PrerenderMiddleware in tests/settings.MIDDLEWARE, add a catch-all tests/urls.py, and switch each test to client.get/post.

Why

RequestFactory constructs request objects and hands them straight to the middleware callable. That lets tests pass even if:

  • The middleware was missing from settings.MIDDLEWARE
  • It was registered after SecurityMiddleware or SessionMiddleware in a way that breaks ordering
  • ROOT_URLCONF wasn't reachable

The new Client setup runs each request through the actual Django pipeline.

Coverage

Adds two scenarios the previous file was missing — X-Bufferbot header and POST pass-through — to align with the other integrations.

Local run: pytest → 13 passed (7 middleware-via-Client + 6 contract).

🤖 Generated with Claude Code

RequestFactory bypasses MIDDLEWARE ordering and URL resolution, so the
prior tests could pass even if the middleware was missing from settings
or registered in the wrong position.

Register PrerenderMiddleware in tests/settings.MIDDLEWARE, add a
tests/urls.py with a catch-all view, and switch to Client().get/post so
each request runs the full Django pipeline. Also covers the X-Bufferbot
and POST-pass-through cases the previous test suite was missing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant