Files
TJWaterServerBinary/tests/unit/test_geoserver_client.py
jiang 90b02057bc
Generic Container CI/CD / test-build-publish (push) Successful in 1m13s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 1m13s
feat(projects): automate project infrastructure provisioning
2026-09-11 10:57:51 +08:00

47 lines
1.7 KiB
Python

from xml.etree import ElementTree
import httpx
from app.infra.geoserver import client as geoserver_client
def test_project_workspace_sets_30_day_client_cache(monkeypatch):
cache_updates: list[str] = []
def handler(request: httpx.Request) -> httpx.Response:
path = request.url.path
if request.method == "GET" and path.endswith("/rest/workspaces/demo.json"):
return httpx.Response(404)
if request.method == "GET" and "/gwc/rest/layers/" in path:
return httpx.Response(
200,
content=b"<GeoServerLayer><name>demo</name><expireClients>0</expireClients></GeoServerLayer>",
)
if request.method == "PUT" and "/gwc/rest/layers/" in path:
root = ElementTree.fromstring(request.content)
cache_updates.append(root.findtext("expireClients"))
return httpx.Response(200)
return httpx.Response(201)
monkeypatch.setattr(geoserver_client.settings, "GEOSERVER_USERNAME", "admin")
monkeypatch.setattr(geoserver_client.settings, "GEOSERVER_PASSWORD", "secret")
monkeypatch.setattr(
geoserver_client.settings,
"GEOSERVER_CLIENT_CACHE_SECONDS",
2_592_000,
)
http_client = httpx.Client(
base_url="http://geoserver.example/geoserver",
transport=httpx.MockTransport(handler),
)
client = geoserver_client.GeoServerAdminClient(client=http_client)
layers = client.create_project_workspace(
workspace="demo",
database_name="demo",
map_bbox=(1.0, 2.0, 3.0, 4.0),
)
assert layers == geoserver_client.PROJECT_LAYER_NAMES
assert cache_updates == ["2592000"] * len(layers)