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

fixing bug where default was set to debug #44

Merged
merged 1 commit into from
Feb 14, 2024
Merged
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
4 changes: 2 additions & 2 deletions pyrit/common/net_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def make_request_and_raise_if_error(
method: str,
request_body: dict[str, str] = None,
headers: dict[str, str] = None,
use_proxy: bool = True,
debug: bool = False,
) -> httpx.Response:
"""Make a request and raise an exception if it fails."""
headers = headers or {}
request_body = request_body or {}

with get_httpx_client(debug=use_proxy) as client:
with get_httpx_client(debug=debug) as client:
if request_body:
headers["Content-Type"] = "application/json"
response = client.request(method=method, url=endpoint_uri, json=request_body, headers=headers)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_common_net_utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import httpx
import respx

from unittest.mock import patch, MagicMock
from tenacity import RetryError
from pyrit.common.net_utility import get_httpx_client, make_request_and_raise_if_error

Expand Down Expand Up @@ -61,3 +63,13 @@ def response_callback(request):
make_request_and_raise_if_error(endpoint_uri=url, method=method)
assert call_count == 2, "The request should have been retried exactly once."
assert mock_route.called


def test_debug_is_false_by_default():
with patch("pyrit.common.net_utility.get_httpx_client") as mock_get_httpx_client:
mock_client_instance = MagicMock()
mock_get_httpx_client.return_value = mock_client_instance

make_request_and_raise_if_error(endpoint_uri="http://example.com", method="GET")

mock_get_httpx_client.assert_called_with(debug=False)
Loading