mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
test(generator): add end-to-end integration test + README
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""End-to-end: api + worker in-process + mocked fetcher HTTP."""
|
||||
import os, tempfile
|
||||
import pytest
|
||||
import responses
|
||||
from src import api as apimod, db as dbmod, worker
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def env(monkeypatch):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
monkeypatch.setattr(dbmod, "SETTINGS_DB_PATH", os.path.join(d, "s.db"))
|
||||
monkeypatch.setattr(dbmod, "WIDGETS_DB_PATH", os.path.join(d, "w.db"))
|
||||
monkeypatch.setattr(apimod.config, "FETCHER_URL", "http://fetcher-mock")
|
||||
monkeypatch.setattr(apimod.config, "FETCHER_INTERNAL_TOKEN", "t")
|
||||
dbmod.init_dbs()
|
||||
yield
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_first_request_builds_then_serves_ready(env):
|
||||
responses.add(
|
||||
responses.GET, "http://fetcher-mock/data/alice",
|
||||
json={"data": {"user": {"login": "alice"}, "repos": [], "events": [],
|
||||
"commits": [], "total_commits": 0, "recent_commits": 0,
|
||||
"total_prs": 0, "collaborators_data": [], "avatar_b64": ""},
|
||||
"payload_hash": "h1"}, status=200,
|
||||
)
|
||||
client = apimod.app.test_client()
|
||||
|
||||
r1 = client.get("/api/alice")
|
||||
assert r1.headers["X-Widget-Status"] == "building"
|
||||
|
||||
for _ in range(5):
|
||||
if not worker.process_one():
|
||||
break
|
||||
|
||||
r2 = client.get("/api/alice")
|
||||
assert r2.headers["X-Widget-Status"] == "ready"
|
||||
assert r2.data.startswith(b"<svg") or r2.data.startswith(b"<?xml")
|
||||
Reference in New Issue
Block a user