Skip to content

Commit abe5c9d

Browse files
committed
Fix typing errors
1 parent ad4b463 commit abe5c9d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/test_csp_rendering.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from xml.etree.ElementTree import Element
33

44
from django.conf import settings
5+
from django.http.response import HttpResponse
56
from django.test.utils import ContextList, override_settings
67
from html5lib.constants import E
78
from html5lib.html5parser import HTMLParser
@@ -66,6 +67,8 @@ def _fail_on_invalid_html(self, content: bytes, parser: HTMLParser):
6667
def test_exists(self):
6768
"""A `nonce` should exist when using the `CSPMiddleware`."""
6869
response = self.client.get(path="/regular/basic/")
70+
if not isinstance(response, HttpResponse):
71+
raise self.failureException(f'{response!r} is not a HttpResponse')
6972
self.assertEqual(response.status_code, 200)
7073

7174
html_root: Element = self.parser.parse(stream=response.content)
@@ -88,14 +91,17 @@ def test_exists(self):
8891
)
8992
def test_redirects_exists(self):
9093
response = self.client.get("/redirect/")
94+
if not isinstance(response, HttpResponse):
95+
raise self.failureException(f'{response!r} is not a HttpResponse')
9196
self.assertEqual(response.status_code, 200)
9297

9398
html_root: Element = self.parser.parse(stream=response.content)
9499
self._fail_on_invalid_html(content=response.content, parser=self.parser)
95100
self.assertContains(response, "djDebug")
96101

97102
namespaces = get_namespaces(element=html_root)
98-
context: ContextList = response.context
103+
context: ContextList = \
104+
response.context # pyright: ignore[reportAttributeAccessIssue]
99105
nonce = str(context["toolbar"].request.csp_nonce)
100106
self._fail_if_missing(
101107
root=html_root, path=".//link", namespaces=namespaces, nonce=nonce
@@ -109,6 +115,8 @@ def test_redirects_exists(self):
109115
)
110116
def test_panel_content_nonce_exists(self):
111117
response = self.client.get("/regular/basic/")
118+
if not isinstance(response, HttpResponse):
119+
raise self.failureException(f'{response!r} is not a HttpResponse')
112120
self.assertEqual(response.status_code, 200)
113121

114122
toolbar = list(DebugToolbar._store.values())[0]
@@ -128,6 +136,8 @@ def test_panel_content_nonce_exists(self):
128136
def test_missing(self):
129137
"""A `nonce` should not exist when not using the `CSPMiddleware`."""
130138
response = self.client.get(path="/regular/basic/")
139+
if not isinstance(response, HttpResponse):
140+
raise self.failureException(f'{response!r} is not a HttpResponse')
131141
self.assertEqual(response.status_code, 200)
132142

133143
html_root: Element = self.parser.parse(stream=response.content)

0 commit comments

Comments
 (0)