|
2 | 2 | Test Serverless Job Module |
3 | 3 | """ |
4 | 4 |
|
5 | | -import asyncio |
6 | 5 | from unittest.mock import Mock, patch |
7 | 6 |
|
8 | 7 | from unittest import IsolatedAsyncioTestCase |
9 | | -from aiohttp import ClientResponse |
| 8 | +from aiohttp import ClientResponse, ClientResponseError |
10 | 9 | from aiohttp.test_utils import make_mocked_coro |
11 | 10 |
|
| 11 | +from runpod.http_client import TooManyRequests |
12 | 12 | from runpod.serverless.modules import rp_job |
13 | 13 |
|
14 | 14 |
|
@@ -63,6 +63,38 @@ async def test_get_job_400(self): |
63 | 63 | job = await rp_job.get_job(mock_session) |
64 | 64 | self.assertIsNone(job) |
65 | 65 |
|
| 66 | + async def test_get_job_429(self): |
| 67 | + """Tests the get_job function with a 429 response.""" |
| 68 | + response = Mock(ClientResponse) |
| 69 | + response.raise_for_status.side_effect = TooManyRequests( |
| 70 | + request_info=None, |
| 71 | + history=(), |
| 72 | + status=429, |
| 73 | + ) |
| 74 | + |
| 75 | + with patch("aiohttp.ClientSession") as mock_session, patch( |
| 76 | + "runpod.serverless.modules.rp_job.JOB_GET_URL", "http://mock.url" |
| 77 | + ): |
| 78 | + mock_session.get.return_value.__aenter__.return_value = response |
| 79 | + with self.assertRaises(ClientResponseError): |
| 80 | + await rp_job.get_job(mock_session) |
| 81 | + |
| 82 | + async def test_get_job_500(self): |
| 83 | + """Tests the get_job function with a 500 response.""" |
| 84 | + # Mock 500 response |
| 85 | + response = Mock(ClientResponse) |
| 86 | + response.raise_for_status.side_effect = TooManyRequests( |
| 87 | + request_info=None, # Not needed for the test |
| 88 | + history=(), # Not needed for the test |
| 89 | + status=500, |
| 90 | + ) |
| 91 | + with patch("aiohttp.ClientSession") as mock_session, patch( |
| 92 | + "runpod.serverless.modules.rp_job.JOB_GET_URL", "http://mock.url" |
| 93 | + ): |
| 94 | + mock_session.get.return_value.__aenter__.return_value = response |
| 95 | + with self.assertRaises(Exception): |
| 96 | + await rp_job.get_job(mock_session) |
| 97 | + |
66 | 98 | async def test_get_job_no_id(self): |
67 | 99 | """Tests the get_job function with a 200 response but no 'id' field.""" |
68 | 100 | response = Mock(ClientResponse) |
|
0 commit comments