Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and optimize codebase #6816

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ def test_request_url_trims_leading_path_separators():
a = requests.adapters.HTTPAdapter()
p = requests.Request(method="GET", url="http://127.0.0.1:10000//v:h").prepare()
assert "/v:h" == a.request_url(p, {})


def test_http_adapter_send():
"""Test the send method of HTTPAdapter."""
adapter = requests.adapters.HTTPAdapter()
request = requests.Request(method="GET", url="http://httpbin.org/get").prepare()
response = adapter.send(request)
assert response.status_code == 200
assert response.request == request
assert response.connection == adapter


def test_http_adapter_cert_verify():
"""Test the cert_verify method of HTTPAdapter."""
adapter = requests.adapters.HTTPAdapter()
conn = adapter.get_connection("https://httpbin.org")
adapter.cert_verify(conn, "https://httpbin.org", True, None)
assert conn.cert_reqs == "CERT_REQUIRED"
assert conn.ca_certs is not None
assert conn.ca_cert_dir is None
18 changes: 18 additions & 0 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ def test_hooks(hooks_list, result):

def test_default_hooks():
assert hooks.default_hooks() == {"response": []}


def test_hooks_with_multiple_hooks():
def hook1(value):
return value + "1"

def hook2(value):
return value + "2"

hooks_list = [hook1, hook2]
result = hooks.dispatch_hook("response", {"response": hooks_list}, "Data")
assert result == "Data12"


def test_hooks_with_no_hooks():
hooks_list = []
result = hooks.dispatch_hook("response", {"response": hooks_list}, "Data")
assert result == "Data"