fix: Normalize nullable pull request authors #57
|
|
@ -94,7 +94,7 @@ async def context() -> JSONResponse:
|
|||
if isinstance(i, dict)
|
||||
]
|
||||
pr_models = [
|
||||
PullRequest(id=p["id"], number=p["number"], title=p["title"], state=p["state"], user=p.get("user", {}).get("login", ""), url=p["html_url"])
|
||||
PullRequest(id=p["id"], number=p["number"], title=p["title"], state=p["state"], user=(p.get("user") or {}).get("login", ""), url=p["html_url"])
|
||||
for p in prs_data[:50]
|
||||
if isinstance(p, dict)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -90,4 +90,33 @@ async def test_context_normalizes_nullable_repository_description(monkeypatch):
|
|||
response = await main.context()
|
||||
repository = json.loads(response.body)["repos"][0]
|
||||
|
||||
assert repository["description"] == ""
|
||||
assert repository["description"] == ""
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_context_normalizes_nullable_pull_request_author(monkeypatch):
|
||||
async def user():
|
||||
return {"id": 1, "login": "timmy"}
|
||||
|
||||
async def empty_collection():
|
||||
return []
|
||||
|
||||
async def pull_request_collection():
|
||||
return [{
|
||||
"id": 56,
|
||||
"number": 56,
|
||||
"title": "Nullable author",
|
||||
"state": "open",
|
||||
"user": None,
|
||||
"html_url": "https://forge.example/pulls/56",
|
||||
}]
|
||||
|
||||
monkeypatch.setattr(main, "current_user", user)
|
||||
monkeypatch.setattr(main, "repos", empty_collection)
|
||||
monkeypatch.setattr(main, "issues", empty_collection)
|
||||
monkeypatch.setattr(main, "pull_requests", pull_request_collection)
|
||||
|
||||
response = await main.context()
|
||||
pull_request = json.loads(response.body)["pull_requests"][0]
|
||||
|
||||
assert pull_request["user"] == ""
|
||||
Loading…
Reference in New Issue
Block a user