Skip to content

Commit

Permalink
Add more tests and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lexiforest committed Oct 6, 2024
1 parent fe21f7f commit 02fc225
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .. import AsyncCurl, Curl, CurlError, CurlHttpVersion, CurlInfo, CurlOpt, CurlSslVersion
from ..curl import CURL_WRITEFUNC_ERROR, CurlMime
from .cookies import Cookies, CookieTypes, CurlMorsel
from .exceptions import ImpersonateError, InvalidURL, RequestException, SessionClosed, code2error
from .exceptions import ImpersonateError, RequestException, SessionClosed, code2error
from .headers import Headers, HeaderTypes
from .impersonate import BrowserType # noqa: F401
from .impersonate import (
Expand Down
6 changes: 6 additions & 0 deletions tests/unittest/test_impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test_customized_akamai_safari():
assert r["akamai_text"] == akamai


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_sig_hash_algs():
url = "https://tls.peet.ws/api/all"
safari_algs = [
Expand All @@ -160,6 +161,7 @@ def test_customized_extra_fp_sig_hash_algs():
assert safari_algs == result_algs


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_tls_min_version():
url = "https://tls.peet.ws/api/all"
safari_min_version = CurlSslVersion.TLSv1_0
Expand All @@ -171,6 +173,7 @@ def test_customized_extra_fp_tls_min_version():
assert len(ex["versions"]) >= 4


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_grease():
url = "https://tls.peet.ws/api/all"
fp = requests.ExtraFingerprints(tls_grease=True)
Expand All @@ -196,6 +199,7 @@ def test_customized_extra_fp_permute():
assert extensions != "65037-65281-0-11-23-5-18-27-16-17513-10-35-43-45-13-51"


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_cert_compression():
url = "https://tls.peet.ws/api/all"
fp = requests.ExtraFingerprints(tls_cert_compression="zlib")
Expand All @@ -207,13 +211,15 @@ def test_customized_extra_fp_cert_compression():
assert result_algs[0] == "zlib (1)"


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_stream_weight():
url = "https://tls.peet.ws/api/all"
fp = requests.ExtraFingerprints(http2_stream_weight=64)
r = requests.get(url, extra_fp=fp).json()
assert r["http2"]["sent_frames"][2]["priority"]["weight"] == 64


@pytest.mark.skip(reason="Unstable API")
def test_customized_extra_fp_stream_exclusive():
url = "https://tls.peet.ws/api/all"
fp = requests.ExtraFingerprints(http2_stream_exclusive=0)
Expand Down
18 changes: 18 additions & 0 deletions tests/unittest/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ def test_url_encode(server):
r = requests.get(str(url))
assert r.url == url

# Non-ASCII URL should be percent encoded as UTF-8 sequence
non_ascii_url = "http://127.0.0.1:8000/search?q=测试"
encoded_non_ascii_url = "http://127.0.0.1:8000/search?q=%E6%B5%8B%E8%AF%95"

r = requests.get(non_ascii_url)
assert r.url == encoded_non_ascii_url

r = requests.get(encoded_non_ascii_url)
assert r.url == encoded_non_ascii_url

# should be quoted
url = "http://127.0.0.1:8000/e x a m p l e"
quoted = "http://127.0.0.1:8000/e%20x%20a%20m%20p%20l%20e"
Expand All @@ -191,6 +201,14 @@ def test_url_encode(server):
r = requests.get(url, quote=":")
assert r.url == quoted

# Do not quote at all
url = "http://127.0.0.1:8000/query={}"
quoted = "http://127.0.0.1:8000/query=%7B%7D"
r = requests.get(url)
assert r.url == quoted
r = requests.get(url, quote=False)
assert r.url == url


def test_headers(server):
r = requests.get(str(server.url.copy_with(path="/echo_headers")), headers={"foo": "bar"})
Expand Down

0 comments on commit 02fc225

Please sign in to comment.