Skip to content

Commit 35df61a

Browse files
committed
fix(test): mock Session.request instead of .post/.get in endpoint tests
The 401 tests mocked Session.post/get, but RunPodClient._request() calls Session.request(). Mocks never intercepted, so tests hit the real API and relied on getting 401 back. When the API started returning 404 for non-existent endpoints, these tests broke. Also fix test_missing_api_key to create a new Endpoint after nullifying the key, since the old endpoint already had a valid client.
1 parent 33233ba commit 35df61a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

tests/test_endpoint/test_runner.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def test_client_custom_overrides_global(self):
5959
self.assertEqual(client.api_key, custom_key)
6060

6161

62-
@patch.object(requests.Session, "post")
63-
def test_post_with_401(self, mock_post):
62+
@patch.object(requests.Session, "request")
63+
def test_post_with_401(self, mock_request):
6464
"""
6565
Tests RunPodClient.post with 401 status code
6666
"""
6767
mock_response = Mock()
6868
mock_response.status_code = 401
69-
mock_post.return_value = mock_response
69+
mock_request.return_value = mock_response
7070

7171
with self.assertRaises(RuntimeError):
7272
runpod.api_key = "MOCK_API_KEY"
@@ -89,14 +89,14 @@ def test_post(self, mock_post):
8989

9090
self.assertEqual(response, {"id": "123"})
9191

92-
@patch.object(requests.Session, "get")
93-
def test_get_with_401(self, mock_get):
92+
@patch.object(requests.Session, "request")
93+
def test_get_with_401(self, mock_request):
9494
"""
9595
Tests RunPodClient.get with 401 status code
9696
"""
9797
mock_response = Mock()
9898
mock_response.status_code = 401
99-
mock_get.return_value = mock_response
99+
mock_request.return_value = mock_response
100100

101101
with self.assertRaises(RuntimeError):
102102
runpod.api_key = "MOCK_API_KEY"
@@ -211,16 +211,16 @@ def test_missing_api_key(self):
211211
"""
212212
with self.assertRaises(RuntimeError):
213213
runpod.api_key = None
214-
self.endpoint.run(self.MODEL_INPUT)
214+
Endpoint("ENDPOINT_ID").run(self.MODEL_INPUT)
215215

216-
@patch.object(requests.Session, "post")
217-
def test_run_with_401(self, mock_post):
216+
@patch.object(requests.Session, "request")
217+
def test_run_with_401(self, mock_request):
218218
"""
219219
Tests Endpoint.run with 401 status code
220220
"""
221221
mock_response = Mock()
222222
mock_response.status_code = 401
223-
mock_post.return_value = mock_response
223+
mock_request.return_value = mock_response
224224

225225
endpoint = runpod.Endpoint("ENDPOINT_ID")
226226
request_data = {"YOUR_MODEL_INPUT_JSON": "YOUR_MODEL_INPUT_VALUE"}

0 commit comments

Comments
 (0)