fix(tests): patch add_service/remove_service at the router import, not the module
Monkeypatching services_live.add_service had no effect because api_services already held a local reference to the name. Patch api_services.add_service and update fake stubs to accept the config kwarg added to the real signature.
This commit is contained in:
@@ -14,8 +14,8 @@ from __future__ import annotations
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from decnet.engine import services_live
|
||||
from decnet.engine.services_live import ServiceMutationError
|
||||
from decnet.web.router.deckies import api_services
|
||||
|
||||
|
||||
_FLEET_BASE = "/api/v1/deckies"
|
||||
@@ -33,10 +33,10 @@ def _hdr(token: str) -> dict[str, str]:
|
||||
async def test_fleet_add_service_returns_post_mutation_list(
|
||||
client: httpx.AsyncClient, auth_token: str, monkeypatch
|
||||
) -> None:
|
||||
async def _fake_add(repo, *, decky_kind, decky_name, service_name, topology_id=None):
|
||||
async def _fake_add(repo, *, decky_kind, decky_name, service_name, topology_id=None, config=None):
|
||||
assert decky_kind == "fleet" and topology_id is None
|
||||
return ["http", service_name]
|
||||
monkeypatch.setattr(services_live, "add_service", _fake_add)
|
||||
monkeypatch.setattr(api_services, "add_service", _fake_add)
|
||||
|
||||
res = await client.post(
|
||||
f"{_FLEET_BASE}/web1/services",
|
||||
@@ -54,9 +54,9 @@ async def test_fleet_add_service_returns_post_mutation_list(
|
||||
async def test_fleet_add_service_422_unknown_service(
|
||||
client: httpx.AsyncClient, auth_token: str, monkeypatch
|
||||
) -> None:
|
||||
async def _fake_add(*a, **kw):
|
||||
async def _fake_add(*a, **kw): # noqa: RUF029
|
||||
raise ServiceMutationError("unknown service 'bogus'")
|
||||
monkeypatch.setattr(services_live, "add_service", _fake_add)
|
||||
monkeypatch.setattr(api_services, "add_service", _fake_add)
|
||||
res = await client.post(
|
||||
f"{_FLEET_BASE}/web1/services",
|
||||
json={"name": "bogus"},
|
||||
@@ -71,7 +71,7 @@ async def test_fleet_add_service_409_already_present(
|
||||
) -> None:
|
||||
async def _fake_add(*a, **kw):
|
||||
raise ServiceMutationError("service 'ssh' already on decky 'web1'")
|
||||
monkeypatch.setattr(services_live, "add_service", _fake_add)
|
||||
monkeypatch.setattr(api_services, "add_service", _fake_add)
|
||||
res = await client.post(
|
||||
f"{_FLEET_BASE}/web1/services",
|
||||
json={"name": "ssh"},
|
||||
@@ -86,7 +86,7 @@ async def test_fleet_remove_service_returns_remaining(
|
||||
) -> None:
|
||||
async def _fake_remove(repo, *, decky_kind, decky_name, service_name, topology_id=None):
|
||||
return ["http"]
|
||||
monkeypatch.setattr(services_live, "remove_service", _fake_remove)
|
||||
monkeypatch.setattr(api_services, "remove_service", _fake_remove)
|
||||
res = await client.delete(
|
||||
f"{_FLEET_BASE}/web1/services/ssh",
|
||||
headers=_hdr(auth_token),
|
||||
@@ -101,7 +101,7 @@ async def test_fleet_remove_service_404_decky_missing(
|
||||
) -> None:
|
||||
async def _fake_remove(*a, **kw):
|
||||
raise ServiceMutationError("fleet decky 'ghost' not found")
|
||||
monkeypatch.setattr(services_live, "remove_service", _fake_remove)
|
||||
monkeypatch.setattr(api_services, "remove_service", _fake_remove)
|
||||
res = await client.delete(
|
||||
f"{_FLEET_BASE}/ghost/services/ssh",
|
||||
headers=_hdr(auth_token),
|
||||
@@ -116,11 +116,11 @@ async def test_fleet_remove_service_404_decky_missing(
|
||||
async def test_topology_add_service_returns_post_mutation_list(
|
||||
client: httpx.AsyncClient, auth_token: str, monkeypatch
|
||||
) -> None:
|
||||
async def _fake_add(repo, *, decky_kind, topology_id, decky_name, service_name):
|
||||
async def _fake_add(repo, *, decky_kind, topology_id, decky_name, service_name, config=None):
|
||||
assert decky_kind == "topology"
|
||||
assert topology_id == "abc123"
|
||||
return ["http", service_name]
|
||||
monkeypatch.setattr(services_live, "add_service", _fake_add)
|
||||
monkeypatch.setattr(api_services, "add_service", _fake_add)
|
||||
res = await client.post(
|
||||
f"{_TOPO_BASE}/abc123/deckies/web1/services",
|
||||
json={"name": "ssh"},
|
||||
@@ -139,7 +139,7 @@ async def test_topology_remove_service_round_trip(
|
||||
) -> None:
|
||||
async def _fake_remove(repo, *, decky_kind, topology_id, decky_name, service_name):
|
||||
return []
|
||||
monkeypatch.setattr(services_live, "remove_service", _fake_remove)
|
||||
monkeypatch.setattr(api_services, "remove_service", _fake_remove)
|
||||
res = await client.delete(
|
||||
f"{_TOPO_BASE}/abc123/deckies/router/services/dns",
|
||||
headers=_hdr(auth_token),
|
||||
|
||||
Reference in New Issue
Block a user