Skip to content

Commit

Permalink
Add tests for refactored _update_url_params
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet committed Aug 3, 2024
1 parent 9c13b83 commit 699e6dc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/unittest/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from curl_cffi.const import CurlECode, CurlInfo
from curl_cffi.requests.errors import SessionClosed
from curl_cffi.requests.models import Response
from curl_cffi.requests.session import _update_url_params


def test_head(server):
Expand Down Expand Up @@ -117,6 +118,36 @@ def test_options(server):
assert r.status_code == 200


def test_update_url_params():
# should be quoted
url = "https://example.com/post.json?limit=1&tags=id:<1000&page=0"
quoted = "https://example.com/post.json?limit=1&tags=id%3A%3C1000&page=0"
assert _update_url_params(url) == quoted

# should not change
url = "https://example.com/post.json?limit=1&tags=foo&page=0"
assert _update_url_params(url) == url

# update url params
url = "https://example.com/post.json?limit=1&tags=foo&page=0"
params = {"tags": "bar"}
updated_url = "https://example.com/post.json?limit=1&tags=bar&page=0"
assert _update_url_params(url, params) == updated_url

# append url params
url = "https://example.com/post.json?limit=1&tags=foo&tags=a"
params = {"tags": "bar"}
updated_url = "https://example.com/post.json?limit=1&tags=foo&tags=a&tags=bar"
assert _update_url_params(url, params) == updated_url

# update url params in a row
url = "https://example.com/post.json?limit=1&tags=foo&page=0"
session_params = {"tags": "a"}
request_params = {"tags": "bar"}
updated_url = "https://example.com/post.json?limit=1&tags=bar&page=0"
assert _update_url_params(url, session_params, request_params) == updated_url


def test_params(server):
r = requests.get(str(server.url.copy_with(path="/echo_params")), params={"foo": "bar"})
assert r.content == b'{"params": {"foo": ["bar"]}}'
Expand Down

0 comments on commit 699e6dc

Please sign in to comment.