73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from src import main
|
|
from src import gitea_proxy
|
|
|
|
|
|
DASHBOARD = Path("frontend/index.html")
|
|
|
|
|
|
def test_dashboard_has_realtime_gitea_event_stream_widget():
|
|
html = DASHBOARD.read_text()
|
|
|
|
assert "Gitea event stream" in html
|
|
assert "id=\"gitea-events\"" in html
|
|
assert "function paintEventStream" in html
|
|
assert "setInterval(loadEventStream, 5000)" in html
|
|
assert "event.actor?.login" in html
|
|
assert "event.repo?.full_name" in html
|
|
|
|
|
|
def test_event_stream_reports_when_activity_was_refreshed():
|
|
html = DASHBOARD.read_text()
|
|
|
|
assert 'id="gitea-events-status"' in html
|
|
assert "setEventStreamStatus('Updating…')" in html
|
|
assert "setEventStreamStatus('Updated ' + fmt(new Date()))" in html
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_event_stream_returns_recent_authenticated_gitea_activity(monkeypatch):
|
|
expected = [{"type": "create", "actor": {"login": "timmy"}}]
|
|
|
|
async def fake_activity_events():
|
|
return expected
|
|
|
|
monkeypatch.setattr(main, "activity_events", fake_activity_events)
|
|
|
|
response = await main.event_stream()
|
|
|
|
assert response == expected
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_activity_events_fetches_feed_for_authenticated_user(monkeypatch):
|
|
paths = []
|
|
|
|
async def fake_current_user():
|
|
return {"login": "timmy"}
|
|
|
|
async def fake_fetch(path):
|
|
paths.append(path)
|
|
return [{
|
|
"op_type": "push",
|
|
"act_user": {"login": "timmy"},
|
|
"repo": {"full_name": "stackchain/stackchain-dashboard"},
|
|
"created": "2026-08-05T03:00:00Z",
|
|
}]
|
|
|
|
monkeypatch.setattr(gitea_proxy, "current_user", fake_current_user)
|
|
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
|
|
|
result = await gitea_proxy.activity_events()
|
|
|
|
assert result == [{
|
|
"type": "push",
|
|
"actor": {"login": "timmy"},
|
|
"repo": {"full_name": "stackchain/stackchain-dashboard"},
|
|
"created_at": "2026-08-05T03:00:00Z",
|
|
}]
|
|
assert paths == ["users/timmy/activities/feeds?limit=20"]
|