Add multi-username activity support
ci / test (push) Successful in 10s
ci / push-image (push) Successful in 52s
ci / deploy-coolify (push) Successful in 6s

This commit is contained in:
Space-Banane
2026-06-04 22:42:48 +02:00
parent ad792b8137
commit 4444174365
5 changed files with 142 additions and 44 deletions
+40
View File
@@ -0,0 +1,40 @@
from datetime import date
import pytest
from app.main import QueryOptions, collect_merged_activity
from app.settings import Settings
@pytest.mark.asyncio
async def test_collect_merged_activity_combines_multiple_usernames(monkeypatch) -> None:
settings = Settings(
_env_file=None,
GITHUB_USERNAME="octocat, hubot",
GITEA_BASE_URL="https://gitea.example.com",
GITEA_USERNAME="alice, bob",
)
github_calls: list[str] = []
gitea_calls: list[str] = []
async def fake_fetch_github_activity(username, token, from_date, to_date, timeout_seconds=20.0):
github_calls.append(username)
return {"2026-01-01": 1 if username == "octocat" else 2}
async def fake_fetch_gitea_activity(base_url, username, token, from_date, to_date, timeout_seconds=20.0):
gitea_calls.append(username)
return {"2026-01-01": 3 if username == "alice" else 4}
monkeypatch.setattr("app.main.fetch_github_activity", fake_fetch_github_activity)
monkeypatch.setattr("app.main.fetch_gitea_activity", fake_fetch_gitea_activity)
result = await collect_merged_activity(
settings=settings,
cache=None,
options=QueryOptions(year=None, days=1, theme="light", source="all"),
)
assert sorted(github_calls) == ["hubot", "octocat"]
assert sorted(gitea_calls) == ["alice", "bob"]
assert result.merged["2026-01-01"] == {"github": 3, "gitea": 7, "total": 10}
+9
View File
@@ -0,0 +1,9 @@
from app.settings import split_usernames
def test_split_usernames_trims_and_deduplicates() -> None:
assert split_usernames("octocat, hubot, octocat, , gitea-user") == [
"octocat",
"hubot",
"gitea-user",
]