File: test_context_processors.py

package info (click to toggle)
python-django-csp 3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: python: 935; makefile: 135; sh: 6
file content (27 lines) | stat: -rw-r--r-- 660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.http import HttpResponse
from django.test import RequestFactory

from csp.context_processors import nonce
from csp.middleware import CSPMiddleware
from csp.tests.utils import response

rf = RequestFactory()
mw = CSPMiddleware(response())


def test_nonce_context_processor():
    request = rf.get("/")
    mw.process_request(request)
    context = nonce(request)

    response = HttpResponse()
    mw.process_response(request, response)

    assert context["CSP_NONCE"] == request.csp_nonce


def test_nonce_context_processor_with_middleware_disabled():
    request = rf.get("/")
    context = nonce(request)

    assert context["CSP_NONCE"] == ""