feat(projects): automate project infrastructure provisioning
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user