Skip to content

Commit 5e9d682

Browse files
committed
Fix test failures: httpx Response request param and mock pattern
httpx.Response needs request param for raise_for_status. Replace broken new_callable pattern with @patch('app.modal').
1 parent 009556a commit 5e9d682

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

tests/test_app.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def _make_webhook_body(
4646

4747
@pytest.mark.asyncio
4848
async def test_call_github_api_success_on_first_attempt():
49-
mock_response = httpx.Response(200, json={"ok": True})
49+
req = httpx.Request("POST", "http://test")
50+
mock_response = httpx.Response(200, json={"ok": True}, request=req)
5051
mock_client = AsyncMock()
5152
mock_client.request = AsyncMock(return_value=mock_response)
5253

@@ -59,15 +60,16 @@ async def test_call_github_api_success_on_first_attempt():
5960

6061
@pytest.mark.asyncio
6162
async def test_call_github_api_retries_on_429():
62-
response_429 = httpx.Response(429)
63-
response_ok = httpx.Response(200, json={"ok": True})
63+
req = httpx.Request("POST", "http://test")
64+
response_429 = httpx.Response(429, request=req)
65+
response_ok = httpx.Response(200, json={"ok": True}, request=req)
6466

6567
mock_client = AsyncMock()
6668
mock_client.request = AsyncMock(
6769
side_effect=[
6870
httpx.HTTPStatusError(
6971
"rate limited",
70-
request=httpx.Request("POST", "http://test"),
72+
request=req,
7173
response=response_429,
7274
),
7375
response_ok,
@@ -85,15 +87,16 @@ async def test_call_github_api_retries_on_429():
8587

8688
@pytest.mark.asyncio
8789
async def test_call_github_api_retries_on_500():
88-
response_500 = httpx.Response(500)
89-
response_ok = httpx.Response(200, json={"ok": True})
90+
req = httpx.Request("POST", "http://test")
91+
response_500 = httpx.Response(500, request=req)
92+
response_ok = httpx.Response(200, json={"ok": True}, request=req)
9093

9194
mock_client = AsyncMock()
9295
mock_client.request = AsyncMock(
9396
side_effect=[
9497
httpx.HTTPStatusError(
9598
"server error",
96-
request=httpx.Request("POST", "http://test"),
99+
request=req,
97100
response=response_500,
98101
),
99102
response_ok,
@@ -111,13 +114,14 @@ async def test_call_github_api_retries_on_500():
111114

112115
@pytest.mark.asyncio
113116
async def test_call_github_api_no_retry_on_404():
114-
response_404 = httpx.Response(404)
117+
req = httpx.Request("POST", "http://test")
118+
response_404 = httpx.Response(404, request=req)
115119

116120
mock_client = AsyncMock()
117121
mock_client.request = AsyncMock(
118122
side_effect=httpx.HTTPStatusError(
119123
"not found",
120-
request=httpx.Request("POST", "http://test"),
124+
request=req,
121125
response=response_404,
122126
)
123127
)
@@ -132,7 +136,8 @@ async def test_call_github_api_no_retry_on_404():
132136

133137
@pytest.mark.asyncio
134138
async def test_call_github_api_retries_on_timeout():
135-
response_ok = httpx.Response(200, json={"ok": True})
139+
req = httpx.Request("POST", "http://test")
140+
response_ok = httpx.Response(200, json={"ok": True}, request=req)
136141

137142
mock_client = AsyncMock()
138143
mock_client.request = AsyncMock(
@@ -153,13 +158,14 @@ async def test_call_github_api_retries_on_timeout():
153158

154159
@pytest.mark.asyncio
155160
async def test_call_github_api_exhausts_retries():
156-
response_429 = httpx.Response(429)
161+
req = httpx.Request("POST", "http://test")
162+
response_429 = httpx.Response(429, request=req)
157163

158164
mock_client = AsyncMock()
159165
mock_client.request = AsyncMock(
160166
side_effect=httpx.HTTPStatusError(
161167
"rate limited",
162-
request=httpx.Request("POST", "http://test"),
168+
request=req,
163169
response=response_429,
164170
)
165171
)
@@ -254,16 +260,9 @@ async def test_verify_signature_bad_content_type():
254260
# =============================================================================
255261

256262

257-
def _mock_modal():
258-
modal_mock = MagicMock()
259-
modal_mock.Sandbox.list.return_value = []
260-
modal_mock.Sandbox.create.return_value = MagicMock()
261-
return modal_mock
262-
263-
264263
@pytest.mark.asyncio
265-
@patch("app.modal", new_callable=_mock_modal)
266-
async def test_webhook_missing_workflow_job(_mock_modal_obj):
264+
@patch("app.modal")
265+
async def test_webhook_missing_workflow_job(mock_modal):
267266
from fastapi import HTTPException
268267

269268
from app import github_webhook
@@ -280,8 +279,8 @@ async def test_webhook_missing_workflow_job(_mock_modal_obj):
280279

281280

282281
@pytest.mark.asyncio
283-
@patch("app.modal", new_callable=_mock_modal)
284-
async def test_webhook_missing_repository(_mock_modal_obj):
282+
@patch("app.modal")
283+
async def test_webhook_missing_repository(mock_modal):
285284
from fastapi import HTTPException
286285

287286
from app import github_webhook
@@ -296,8 +295,8 @@ async def test_webhook_missing_repository(_mock_modal_obj):
296295

297296

298297
@pytest.mark.asyncio
299-
@patch("app.modal", new_callable=_mock_modal)
300-
async def test_webhook_missing_labels(_mock_modal_obj):
298+
@patch("app.modal")
299+
async def test_webhook_missing_labels(mock_modal):
301300
from fastapi import HTTPException
302301

303302
from app import github_webhook
@@ -318,8 +317,8 @@ async def test_webhook_missing_labels(_mock_modal_obj):
318317

319318

320319
@pytest.mark.asyncio
321-
@patch("app.modal", new_callable=_mock_modal)
322-
async def test_webhook_ignores_non_modal_labels(_mock_modal_obj):
320+
@patch("app.modal")
321+
async def test_webhook_ignores_non_modal_labels(mock_modal):
323322
from app import github_webhook
324323

325324
body = _make_webhook_body(labels=["self-hosted", "ubuntu"])
@@ -331,8 +330,8 @@ async def test_webhook_ignores_non_modal_labels(_mock_modal_obj):
331330

332331

333332
@pytest.mark.asyncio
334-
@patch("app.modal", new_callable=_mock_modal)
335-
async def test_webhook_ignores_non_queued_action(_mock_modal_obj):
333+
@patch("app.modal")
334+
async def test_webhook_ignores_non_queued_action(mock_modal):
336335
from app import github_webhook
337336

338337
body = _make_webhook_body(action="started")
@@ -343,8 +342,8 @@ async def test_webhook_ignores_non_queued_action(_mock_modal_obj):
343342

344343

345344
@pytest.mark.asyncio
346-
@patch("app.modal", new_callable=_mock_modal)
347-
async def test_webhook_rejects_invalid_json(_mock_modal_obj):
345+
@patch("app.modal")
346+
async def test_webhook_rejects_invalid_json(mock_modal):
348347
from fastapi import HTTPException
349348

350349
from app import github_webhook
@@ -359,8 +358,8 @@ async def test_webhook_rejects_invalid_json(_mock_modal_obj):
359358

360359

361360
@pytest.mark.asyncio
362-
@patch("app.modal", new_callable=_mock_modal)
363-
async def test_webhook_rejects_invalid_repo_url(_mock_modal_obj):
361+
@patch("app.modal")
362+
async def test_webhook_rejects_invalid_repo_url(mock_modal):
364363
from fastapi import HTTPException
365364

366365
from app import github_webhook

0 commit comments

Comments
 (0)