mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 11:33:14 +00:00
Applies the plan's C5 step: git mv every test per the domain-reorg
move-map (movemap-m50.txt) into tests/{agent,analyzer,auth,dashboard,
github,middleware,models,reviewer,sandbox,slack,tools,webhooks}/, plus
the 13 fork-only placements from the scoping report §2c (Atlassian
webhook tests -> tests/webhooks/, test_atlassian_connect.py and
test_auth_error_leak.py -> tests/auth/, jira/confluence util tests ->
tests/tools/, test_repo_binding_isolation.py -> tests/sandbox/,
bot-identity/autofix tests -> tests/github/).
Path-only move: the only content edits are parents[1] -> parents[2]
fixes in test_e2b_integration.py and test_daytona_integration.py,
required because their __file__-relative ROOT path gained one more
directory level in the move.
Monkeypatch retargets for these files were already completed in C4;
none remained outstanding here.
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
import httpx
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from agent.dashboard import routes
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_paginate_converts_github_timeout_to_503() -> None:
|
|
request = httpx.Request("GET", "https://api.github.com/user/installations")
|
|
|
|
async def handler(_request: httpx.Request) -> httpx.Response:
|
|
raise httpx.ConnectTimeout("connect timed out", request=request)
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
async with httpx.AsyncClient(transport=transport) as client:
|
|
with pytest.raises(HTTPException) as exc:
|
|
await routes._paginate(
|
|
client,
|
|
"https://api.github.com/user/installations",
|
|
headers={},
|
|
items_key="installations",
|
|
)
|
|
|
|
assert exc.value.status_code == 503
|
|
assert exc.value.detail == "github API request timed out"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_paginate_converts_github_status_error_to_502() -> None:
|
|
async def handler(request: httpx.Request) -> httpx.Response:
|
|
return httpx.Response(500, request=request, json={"message": "server error"})
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
async with httpx.AsyncClient(transport=transport) as client:
|
|
with pytest.raises(HTTPException) as exc:
|
|
await routes._paginate(
|
|
client,
|
|
"https://api.github.com/user/installations",
|
|
headers={},
|
|
items_key="installations",
|
|
)
|
|
|
|
assert exc.value.status_code == 502
|
|
assert exc.value.detail == "github API error (500)"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_repos_propagates_repository_page_timeouts(monkeypatch) -> None:
|
|
monkeypatch.setattr(routes, "get_valid_access_token", AsyncMock(return_value="token"))
|
|
calls = 0
|
|
|
|
async def fake_paginate(*args: object, **kwargs: object) -> list[dict[str, object]]:
|
|
nonlocal calls
|
|
calls += 1
|
|
if calls == 1:
|
|
return [{"id": 123, "account": {"login": "acme", "type": "Organization"}}]
|
|
raise HTTPException(503, "github API request timed out")
|
|
|
|
monkeypatch.setattr(routes, "_paginate", fake_paginate)
|
|
|
|
with pytest.raises(HTTPException) as exc:
|
|
await routes.list_repos(session={"sub": "octocat"})
|
|
|
|
assert exc.value.status_code == 503
|
|
assert exc.value.detail == "github API request timed out"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_repos_skips_inaccessible_installations(monkeypatch) -> None:
|
|
monkeypatch.setattr(routes, "get_valid_access_token", AsyncMock(return_value="token"))
|
|
calls = 0
|
|
|
|
async def fake_paginate(*args: object, **kwargs: object) -> list[dict[str, object]]:
|
|
nonlocal calls
|
|
calls += 1
|
|
if calls == 1:
|
|
return [{"id": 123, "account": {"login": "acme", "type": "Organization"}}]
|
|
raise HTTPException(403, "github API forbidden")
|
|
|
|
monkeypatch.setattr(routes, "_paginate", fake_paginate)
|
|
|
|
result = await routes.list_repos(session={"sub": "octocat"})
|
|
|
|
assert result == {
|
|
"installations": [{"id": 123, "account": "acme", "account_type": "Organization"}],
|
|
"repositories": [],
|
|
}
|