Skip to content

Commit

Permalink
[ci] fix tests add_verify_file_callback due to cgi deleted from pytho…
Browse files Browse the repository at this point in the history
…n 3.13
  • Loading branch information
EvanBldy committed Nov 25, 2024
1 parent 130a9f7 commit 6b0d897
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ test =
pytest
pytest-cov
requests_mock
multipart; python_version >= '3.13'

lint =
autoflake==2.3.1; python_version >= '3.8'
Expand Down
29 changes: 23 additions & 6 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import json
import gazu.client
import io
import cgi


def fakeid(string):
Expand Down Expand Up @@ -38,12 +37,30 @@ def add_verify_file_callback(mock, dict_assert={}, url=None):
def verify_file_callback(request):
if url is None or url == request.url:
body_file = io.BytesIO(request.body)
_, pdict = cgi.parse_header(request.headers["Content-Type"])
if sys.version_info[0] == 3:
pdict["boundary"] = bytes(pdict["boundary"], "UTF-8")

if sys.version_info >= (3, 13):
import multipart

p = multipart.MultipartParser(
body_file,
boundary=bytes(
multipart.parse_options_header(
request.headers["Content-Type"]
)[1]["boundary"],
"UTF-8",
),
charset="UTF-8",
)
parsed = {part.name: [part.raw] for part in p.parts()}
else:
pdict["boundary"] = bytes(pdict["boundary"])
parsed = cgi.parse_multipart(fp=body_file, pdict=pdict)
import cgi

_, pdict = cgi.parse_header(request.headers["Content-Type"])
if sys.version_info[0] == 3:
pdict["boundary"] = bytes(pdict["boundary"], "utf-8")
else:
pdict["boundary"] = bytes(pdict["boundary"])
parsed = cgi.parse_multipart(fp=body_file, pdict=pdict)
for key in dict_assert.keys():
assert key in parsed.keys()
if isinstance(parsed[key][0], bytes):
Expand Down

0 comments on commit 6b0d897

Please sign in to comment.