summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-05-10 12:12:17 +0200
committerCarlton Gibson <carlton@noumenal.es>2022-05-11 14:06:31 +0200
commit34e2148fc725e7200050f74130d7523e3cd8507a (patch)
treeb4bc74515b1d4911c6c07d5cd7697c78eff91407 /tests/utils_tests
parent02dbf1667c6da61ea9346f7c9f174a158b896811 (diff)
Refs #33173 -- Removed use of deprecated cgi module.
https://peps.python.org/pep-0594/#cgi
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_http.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index 67f3361068..2ba617dfc9 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -12,6 +12,7 @@ from django.utils.http import (
int_to_base36,
is_same_domain,
parse_etags,
+ parse_header_parameters,
parse_http_date,
quote_etag,
url_has_allowed_host_and_scheme,
@@ -435,3 +436,39 @@ class EscapeLeadingSlashesTests(unittest.TestCase):
for url, expected in tests:
with self.subTest(url=url):
self.assertEqual(escape_leading_slashes(url), expected)
+
+
+class ParseHeaderParameterTests(unittest.TestCase):
+ def test_basic(self):
+ tests = [
+ ("text/plain", ("text/plain", {})),
+ ("text/vnd.just.made.this.up ; ", ("text/vnd.just.made.this.up", {})),
+ ("text/plain;charset=us-ascii", ("text/plain", {"charset": "us-ascii"})),
+ (
+ 'text/plain ; charset="us-ascii"',
+ ("text/plain", {"charset": "us-ascii"}),
+ ),
+ (
+ 'text/plain ; charset="us-ascii"; another=opt',
+ ("text/plain", {"charset": "us-ascii", "another": "opt"}),
+ ),
+ (
+ 'attachment; filename="silly.txt"',
+ ("attachment", {"filename": "silly.txt"}),
+ ),
+ (
+ 'attachment; filename="strange;name"',
+ ("attachment", {"filename": "strange;name"}),
+ ),
+ (
+ 'attachment; filename="strange;name";size=123;',
+ ("attachment", {"filename": "strange;name", "size": "123"}),
+ ),
+ (
+ 'form-data; name="files"; filename="fo\\"o;bar"',
+ ("form-data", {"name": "files", "filename": 'fo"o;bar'}),
+ ),
+ ]
+ for header, expected in tests:
+ with self.subTest(header=header):
+ self.assertEqual(parse_header_parameters(header), expected)