42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import types
|
|
|
|
import ariadne.k8s.client as k8s_client
|
|
|
|
|
|
class DummyResponse:
|
|
def __init__(self, payload):
|
|
self._payload = payload
|
|
|
|
def raise_for_status(self):
|
|
return None
|
|
|
|
def json(self):
|
|
return self._payload
|
|
|
|
|
|
class DummyClient:
|
|
def __init__(self, *args, **kwargs):
|
|
self.calls = []
|
|
|
|
def request(self, method, url, json=None):
|
|
self.calls.append((method, url, json))
|
|
return DummyResponse({"ok": True})
|
|
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb):
|
|
return False
|
|
|
|
|
|
def test_get_json_builds_url(monkeypatch) -> None:
|
|
dummy_settings = types.SimpleNamespace(k8s_api_timeout_sec=5.0)
|
|
monkeypatch.setattr(k8s_client, "settings", dummy_settings)
|
|
monkeypatch.setattr(k8s_client, "_read_service_account", lambda: ("token", "/tmp/ca"))
|
|
monkeypatch.setattr(k8s_client.httpx, "Client", DummyClient)
|
|
|
|
result = k8s_client.get_json("/api/test")
|
|
assert result == {"ok": True}
|