mirror of https://github.com/scrapy/scrapy.git
Drop list of plain cookie dicts support from request_to_curl().
This commit is contained in:
parent
19d5a106c5
commit
707ab67fe2
|
|
@ -212,9 +212,8 @@ def request_to_curl(request: Request) -> str:
|
|||
elif isinstance(request.cookies, list):
|
||||
cookie = "; ".join(
|
||||
f"{_cookie_value_to_unicode(c['name'])}={_cookie_value_to_unicode(c['value'])}"
|
||||
if "name" in c and "value" in c
|
||||
else f"{_cookie_value_to_unicode(next(iter(c.keys())))}={_cookie_value_to_unicode(next(iter(c.values())))}"
|
||||
for c in request.cookies
|
||||
if "name" in c and "value" in c
|
||||
)
|
||||
cookies = f"--cookie '{cookie}'"
|
||||
|
||||
|
|
|
|||
|
|
@ -354,16 +354,18 @@ class TestCustomRequestFingerprinter:
|
|||
|
||||
|
||||
class TestRequestToCurl:
|
||||
def _test_request(self, request_object, expected_curl_command):
|
||||
def _test_request(
|
||||
self, request_object: Request, expected_curl_command: str
|
||||
) -> None:
|
||||
curl_command = request_to_curl(request_object)
|
||||
assert curl_command == expected_curl_command
|
||||
|
||||
def test_get(self):
|
||||
def test_get(self) -> None:
|
||||
request_object = Request("https://www.example.com")
|
||||
expected_curl_command = "curl -X GET https://www.example.com"
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_post(self):
|
||||
def test_post(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -374,7 +376,7 @@ class TestRequestToCurl:
|
|||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_headers(self):
|
||||
def test_headers(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -388,7 +390,7 @@ class TestRequestToCurl:
|
|||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_dict(self):
|
||||
def test_cookies_dict(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -401,7 +403,7 @@ class TestRequestToCurl:
|
|||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_dict_bytes(self):
|
||||
def test_cookies_dict_bytes(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -414,20 +416,7 @@ class TestRequestToCurl:
|
|||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_list(self):
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
cookies=[{"foo": "bar"}],
|
||||
body=json.dumps({"foo": "bar"}),
|
||||
)
|
||||
expected_curl_command = (
|
||||
"curl -X POST https://www.httpbin.org/post"
|
||||
" --data-raw '{\"foo\": \"bar\"}' --cookie 'foo=bar'"
|
||||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_list_verbose(self):
|
||||
def test_cookies_list_verbose(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -448,7 +437,7 @@ class TestRequestToCurl:
|
|||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_list_verbose_non_string_value(self):
|
||||
def test_cookies_list_verbose_non_string_value(self) -> None:
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
|
|
@ -468,16 +457,3 @@ class TestRequestToCurl:
|
|||
" --data-raw '{\"foo\": \"bar\"}' --cookie 'foo=1'"
|
||||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
||||
def test_cookies_list_bytes_nonstandard_key(self):
|
||||
request_object = Request(
|
||||
"https://www.httpbin.org/post",
|
||||
method="POST",
|
||||
cookies=[{b"foo": b"bar"}],
|
||||
body=json.dumps({"foo": "bar"}),
|
||||
)
|
||||
expected_curl_command = (
|
||||
"curl -X POST https://www.httpbin.org/post"
|
||||
" --data-raw '{\"foo\": \"bar\"}' --cookie 'foo=bar'"
|
||||
)
|
||||
self._test_request(request_object, expected_curl_command)
|
||||
|
|
|
|||
Loading…
Reference in New Issue