MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / client_factory

Function client_factory

tests/unit/api/test_api_auth.py:33–49  ·  view source on GitHub ↗

Build a TestClient whose get_server dependency is stubbed out. Callers pass the desired CGC_API_KEY (or None to leave it unset) so each test controls whether auth is active.

(monkeypatch)

Source from the content-addressed store, hash-verified

31
32@pytest.fixture
33def client_factory(monkeypatch):
34 """Build a TestClient whose get_server dependency is stubbed out.
35
36 Callers pass the desired CGC_API_KEY (or None to leave it unset) so each
37 test controls whether auth is active.
38 """
39
40 def _make(api_key):
41 if api_key is None:
42 monkeypatch.delenv("CGC_API_KEY", raising=False)
43 else:
44 monkeypatch.setenv("CGC_API_KEY", api_key)
45 app = create_app()
46 app.dependency_overrides[get_server] = lambda: FakeServer()
47 return TestClient(app)
48
49 return _make
50
51
52# --- Key configured: auth is enforced ---------------------------------------

Calls

no outgoing calls

Tested by

no test coverage detected