Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that scantree isn’t run multiple times per test suite #562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/test_django_whitenoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import tempfile
from contextlib import closing
from unittest.mock import Mock
from urllib.parse import urljoin
from urllib.parse import urlparse

Expand All @@ -12,6 +13,7 @@
from django.contrib.staticfiles import storage
from django.core.management import call_command
from django.core.wsgi import get_wsgi_application
from django.test import Client
from django.test.utils import override_settings
from django.utils.functional import empty

Expand Down Expand Up @@ -209,3 +211,17 @@ def test_relative_static_url(server, static_files, _collect_static):
url = storage.staticfiles_storage.url(static_files.js_path)
response = server.get(url)
assert response.content == static_files.js_content


def test_middleware__performance(monkeypatch):
"""The middleware should not on every request."""
scantree = Mock()
scantree.return_value = []
monkeypatch.setattr("whitenoise.base.scantree", scantree)
with override_settings(
MIDDLEWARE=["whitenoise.middleware.WhiteNoiseMiddleware", *settings.MIDDLEWARE]
):
# every Django test will set up its own client and initialize a new middleware
Client().get("/")
Client().get("/")
assert scantree.assert_called_once()