109 lines
3.5 KiB
Python
109 lines
3.5 KiB
Python
import pytest
|
|
import json
|
|
|
|
from src import gitea_proxy
|
|
from src import main
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_work_collections_include_supported_review_request_search(monkeypatch):
|
|
requested_paths = []
|
|
|
|
async def fake_fetch(path):
|
|
requested_paths.append(path)
|
|
return []
|
|
|
|
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
|
|
|
assert await gitea_proxy.issues() == []
|
|
assert await gitea_proxy.pull_requests() == []
|
|
assert requested_paths == [
|
|
"repos/issues/search?state=open&assigned=true&type=issues&limit=50",
|
|
"repos/issues/search?state=open&assigned=true&type=pulls&limit=50",
|
|
"repos/issues/search?state=open&review_requested=true&type=pulls&limit=50",
|
|
]
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_pull_requests_merge_assignment_and_review_responsibilities(monkeypatch):
|
|
assigned = {
|
|
"id": 11,
|
|
"number": 7,
|
|
"title": "Review API",
|
|
"repository": {"full_name": "stackchain/api"},
|
|
}
|
|
review_only = {
|
|
"id": 12,
|
|
"number": 8,
|
|
"title": "Review mobile",
|
|
"repository": {"full_name": "stackchain/mobile"},
|
|
}
|
|
|
|
async def fake_fetch(path):
|
|
if "assigned=true" in path:
|
|
return [assigned]
|
|
return [assigned.copy(), review_only]
|
|
|
|
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
|
|
|
pulls = await gitea_proxy.pull_requests()
|
|
|
|
assert [pull["id"] for pull in pulls] == [11, 12]
|
|
assert pulls[0]["work_reasons"] == ["assigned_to_me", "review_requested"]
|
|
assert pulls[1]["work_reasons"] == ["review_requested"]
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_context_preserves_repository_and_update_time_for_cross_repo_work(monkeypatch):
|
|
async def user():
|
|
return {"id": 1, "login": "timmy"}
|
|
|
|
async def repositories():
|
|
return []
|
|
|
|
async def issues():
|
|
return [{
|
|
"id": 10,
|
|
"number": 7,
|
|
"title": "Ship mobile flow",
|
|
"state": "open",
|
|
"labels": [{"name": "P0"}],
|
|
"assignees": [{"login": "timmy"}],
|
|
"repository": {"full_name": "stackchain/mobile"},
|
|
"updated_at": "2026-08-06T12:00:00Z",
|
|
"html_url": "https://forge.example/stackchain/mobile/issues/7",
|
|
}]
|
|
|
|
async def pulls():
|
|
return [{
|
|
"id": 11,
|
|
"number": 7,
|
|
"title": "Review API",
|
|
"state": "open",
|
|
"user": {"login": "alex"},
|
|
"labels": [{"name": "priority-high"}],
|
|
"assignees": [{"login": "timmy"}],
|
|
"work_reasons": ["assigned_to_me", "review_requested"],
|
|
"repository": {"full_name": "stackchain/api"},
|
|
"updated_at": "2026-08-06T11:00:00Z",
|
|
"html_url": "https://forge.example/stackchain/api/pulls/7",
|
|
}]
|
|
|
|
monkeypatch.setattr(main, "current_user", user)
|
|
monkeypatch.setattr(main, "repos", repositories)
|
|
monkeypatch.setattr(main, "issues", issues)
|
|
monkeypatch.setattr(main, "pull_requests", pulls)
|
|
|
|
payload = json.loads((await main.context()).body)
|
|
|
|
assert payload["issues"][0]["repository"] == "stackchain/mobile"
|
|
assert payload["issues"][0]["updated_at"] == "2026-08-06T12:00:00Z"
|
|
assert payload["pull_requests"][0]["repository"] == "stackchain/api"
|
|
assert payload["pull_requests"][0]["updated_at"] == "2026-08-06T11:00:00Z"
|
|
assert payload["pull_requests"][0]["labels"] == ["priority-high"]
|
|
assert payload["pull_requests"][0]["assignees"] == ["timmy"]
|
|
assert payload["pull_requests"][0]["work_reasons"] == [
|
|
"assigned_to_me",
|
|
"review_requested",
|
|
]
|