Skip to content
Myr

Drop cgi module from test_multipart (#2424)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Use multipart instead of cgi for multipart tests The cgi module has been deprecated as of python 3.11. Signed-off-by: Vincent Fazio <vfazio@gmail.com> * Update setup.cfg All references to the cgi module have all been removed so there's no longer a need to silence those deprecation warnings. The deprecation warning for certifi is resolved as of version 2022.09.24. Signed-off-by: Vincent Fazio <vfazio@gmail.com>

authored by Vincent Fazio · committed by GitHub · parent db00b92 · Browse files · 3 files+23 added−27 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Vincent Fazio <vfazio@gmail.com>
  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

3 files+23 added−27 removed

  • tests:+22 added−25 removed
  • other:+1 added−2 removed

3 files+23 added−27 removed

modified:tests/test_multipart.py+22 added-25 removed
1import cgi1import io2import os3import tempfile4import typing5from unittest import mock67import pytest8from multipart import MultipartParser910import httpx11from httpx._content import encode_request12from httpx._utils import format_form_param
12 unmodified lines
25 files = {"file": io.BytesIO(b"<file content>")}26 response = client.post("http://127.0.0.1:8000/", data=data, files=files)27 assert response.status_code == 2002829 # We're using the cgi module to verify the behavior here, which is a30 # bit grungy, but sufficient just for our testing purposes.29 boundary = response.request.headers["Content-Type"].split("boundary=")[-1]32 content_length = response.request.headers["Content-Length"]33 pdict: dict = {34 "boundary": boundary.encode("ascii"),35 "CONTENT-LENGTH": content_length,36 }37 multipart = cgi.parse_multipart(io.BytesIO(response.content), pdict)30 content_length = int(response.request.headers["Content-Length"])3132 multipart = {}33 for part in MultipartParser(34 io.BytesIO(response.content), boundary=boundary, content_length=content_length35 ):36 multipart[part.name] = [part.raw]3738 # Note that the expected return type for text fields39 # appears to differs from 3.6 to 3.7+40 assert multipart["text"] == [output.decode()] or multipart["text"] == [output]41 assert multipart["file"] == [b"<file content>"]
19 unmodified lines
61 headers = {"content-type": header}62 response = client.post("http://127.0.0.1:8000/", files=files, headers=headers)63 assert response.status_code == 2006466 # We're using the cgi module to verify the behavior here, which is a67 # bit grungy, but sufficient just for our testing purposes.65 assert response.request.headers["Content-Type"] == header69 content_length = response.request.headers["Content-Length"]70 pdict: dict = {71 "boundary": b"+++",72 "CONTENT-LENGTH": content_length,73 }74 multipart = cgi.parse_multipart(io.BytesIO(response.content), pdict)66 content_length = int(response.request.headers["Content-Length"])6768 multipart = {}69 for part in MultipartParser(70 io.BytesIO(response.content), boundary="+++", content_length=content_length71 ):72 multipart[part.name] = [part.raw]7374 assert multipart["file"] == [b"<file content>"]757677@pytest.mark.parametrize(
50 unmodified lines
128 files = {"file": ("name.txt", io.BytesIO(b"<file content>"))}129 response = client.post("http://127.0.0.1:8000/", data=data, files=files)130 assert response.status_code == 200131134 # We're using the cgi module to verify the behavior here, which is a135 # bit grungy, but sufficient just for our testing purposes.132 boundary = response.request.headers["Content-Type"].split("boundary=")[-1]137 content_length = response.request.headers["Content-Length"]138 pdict: dict = {139 "boundary": boundary.encode("ascii"),140 "CONTENT-LENGTH": content_length,141 }142 multipart = cgi.parse_multipart(io.BytesIO(response.content), pdict)133 content_length = int(response.request.headers["Content-Length"])134135 multipart = {}136 for part in MultipartParser(137 io.BytesIO(response.content), boundary=boundary, content_length=content_length138 ):139 multipart[part.name] = [part.raw]140141 # Note that the expected return type for text fields142 # appears to differs from 3.6 to 3.7+143 assert multipart["text"] == ["abc"] or multipart["text"] == [b"abc"]144 assert multipart["file"] == [b"<file content>"]
301 unmodified lines
modified:requirements.txt+1 added
26 unmodified lines
27flake8-bugbear==22.7.128flake8-pie==0.16.0; python_version>='3.7'29importlib-metadata==4.13.0; python_version>='3.7'30isort==5.10.131multipart==0.2.432mypy==0.98233types-certifi==2021.10.8.234pytest==7.1.235pytest-asyncio==0.19.0
5 unmodified lines
modified:setup.cfg-2 removed
18 unmodified lines
19[tool:pytest]20addopts = -rxXs21filterwarnings =22 error23 default:path is deprecated:DeprecationWarning:certifi24 default:'cgi' is deprecated:DeprecationWarning23asyncio_mode = strict24markers =25 copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accodomate e.g. our test setup26 network: marks tests which require network connection. Used in 3rd-party build environments that have network disabled.
4 unmodified lines