Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grego118 committed Sep 4, 2024
1 parent 83a6059 commit c27ae2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def patched_version_and_sys():


@pytest.fixture
def patched_session_request():
def patched_request():
mock_response = Mock()
mock_response.content = b"mock data"
mock_response.json.return_value = {"foo": "bar"}
mock_response.status_code = 200

with patch("requests.Session.request", return_value=mock_response) as mock_request:
with patch("requests.request", return_value=mock_response) as mock_request:
yield mock_request


@pytest.fixture
def mock_session_timeout():
with patch("requests.Session.request", side_effect=requests.exceptions.Timeout):
with patch("requests.request", side_effect=requests.exceptions.Timeout):
yield


Expand Down
16 changes: 8 additions & 8 deletions tests/handler/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ def test_build_query_params(self, patched_version_and_sys):
== "https://test.nylas.com/foo?foo=bar&list=a&list=b&list=c&map=key1:value1&map=key2:value2"
)

def test_execute_download_request(self, http_client, patched_session_request):
def test_execute_download_request(self, http_client, patched_request):
response = http_client._execute_download_request(
path="/foo",
)
assert response == b"mock data"

def test_execute_download_request_with_stream(
self, http_client, patched_session_request
self, http_client, patched_request
):
response = http_client._execute_download_request(
path="/foo",
Expand All @@ -189,13 +189,13 @@ def test_execute_download_request_timeout(self, http_client, mock_session_timeou
)

def test_execute_download_request_override_timeout(
self, http_client, patched_version_and_sys, patched_session_request
self, http_client, patched_version_and_sys, patched_request
):
response = http_client._execute_download_request(
path="/foo",
overrides={"timeout": 60},
)
patched_session_request.assert_called_once_with(
patched_request.assert_called_once_with(
"GET",
"https://test.nylas.com/foo",
headers={
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_validate_response_400_keyerror(self):
assert e.value.status_code == 400

def test_execute(
self, http_client, patched_version_and_sys, patched_session_request
self, http_client, patched_version_and_sys, patched_request
):
response = http_client._execute(
method="GET",
Expand All @@ -287,7 +287,7 @@ def test_execute(
)

assert response == {"foo": "bar"}
patched_session_request.assert_called_once_with(
patched_request.assert_called_once_with(
"GET",
"https://test.nylas.com/foo?query=param",
headers={
Expand All @@ -303,7 +303,7 @@ def test_execute(
)

def test_execute_override_timeout(
self, http_client, patched_version_and_sys, patched_session_request
self, http_client, patched_version_and_sys, patched_request
):
response = http_client._execute(
method="GET",
Expand All @@ -315,7 +315,7 @@ def test_execute_override_timeout(
)

assert response == {"foo": "bar"}
patched_session_request.assert_called_once_with(
patched_request.assert_called_once_with(
"GET",
"https://test.nylas.com/foo?query=param",
headers={
Expand Down

0 comments on commit c27ae2b

Please sign in to comment.