From 6bcc0780f9a97e999a2cd31e4e480f1118812464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9cile=20Vuilleumier?= Date: Tue, 15 Oct 2024 10:44:01 +0200 Subject: [PATCH] wip --- geoservercloud/geoservercloud.py | 51 ++--- geoservercloud/models/workspace.py | 6 + geoservercloud/services/__init__.py | 5 - geoservercloud/services/endpoints.py | 174 --------------- geoservercloud/services/restclient.py | 87 ++++++++ geoservercloud/services/restservice.py | 287 ++++++++++++++++++------- tests/test_workspace.py | 32 ++- 7 files changed, 333 insertions(+), 309 deletions(-) delete mode 100644 geoservercloud/services/endpoints.py create mode 100644 geoservercloud/services/restclient.py diff --git a/geoservercloud/geoservercloud.py b/geoservercloud/geoservercloud.py index 2b81c1c..e8199b2 100644 --- a/geoservercloud/geoservercloud.py +++ b/geoservercloud/geoservercloud.py @@ -14,20 +14,13 @@ DataStores, FeatureType, FeatureTypes, - KeyDollarListDict, PostGisDataStore, Style, Styles, Workspace, Workspaces, ) -from geoservercloud.services import ( - AclEndpoints, - GwcEndpoints, - OwsEndpoints, - RestEndpoints, - RestService, -) +from geoservercloud.services import RestService from geoservercloud.templates import Templates @@ -44,10 +37,6 @@ def __init__( self.password: str = password self.auth: tuple[str, str] = (user, password) self.rest_service: RestService = RestService(url, self.auth) - self.acl_endpoints: AclEndpoints = AclEndpoints() - self.gwc_endpoints: GwcEndpoints = GwcEndpoints() - self.ows_endpoints: OwsEndpoints = OwsEndpoints() - self.rest_endpoints: RestEndpoints = RestEndpoints() self.wms: WebMapService_1_3_0 | None = None self.wmts: WebMapTileService | None = None self.default_workspace: str | None = None @@ -84,50 +73,39 @@ def create_wmts(self) -> None: password=self.password, ) - def get_workspaces(self) -> Workspaces: - response: Response = self.get_request(self.rest_endpoints.workspaces()) - workspaces = Workspaces.from_dict(response.json()) - return workspaces + def get_workspaces(self) -> list[str]: + return self.rest_service.get_workspaces().workspaces def create_workspace( self, workspace_name: str, isolated: bool = False, set_default_workspace: bool = False, - ) -> Response: + ) -> dict[str, Any]: """ Create a workspace in GeoServer, if it does not already exist. It if exists, update it """ - response: Response = self.post_request( - self.rest_endpoints.workspaces(), - json=Workspace(workspace_name, isolated).post_payload(), - ) - if response.status_code == 409: - response = self.put_request( - self.rest_endpoints.workspace(workspace_name), - json=Workspace(workspace_name, isolated).put_payload(), - ) + workspace = self.rest_service.create_workspace( + workspace_name, isolated + ).asdict() if set_default_workspace: self.default_workspace = workspace_name - return response + return workspace - def delete_workspace(self, workspace_name: str) -> Response: + def delete_workspace(self, workspace_name: str) -> None: """ Delete a GeoServer workspace (recursively) """ - response: Response = self.delete_request( - self.rest_endpoints.workspace(workspace_name), params={"recurse": "true"} - ) + self.rest_service.delete_workspace(workspace_name) if self.default_workspace == workspace_name: self.default_workspace = None self.wms = None self.wmts = None - return response def recreate_workspace( self, workspace_name: str, set_default_workspace: bool = False - ) -> Response: + ) -> dict[str, Any]: """ Create a workspace in GeoServer, and first delete it if it already exists. """ @@ -136,14 +114,11 @@ def recreate_workspace( workspace_name, set_default_workspace=set_default_workspace ) - def publish_workspace(self, workspace_name) -> Response: + def publish_workspace(self, workspace_name) -> None: """ Publish the WMS service for a given workspace """ - data: dict[str, dict[str, Any]] = Templates.workspace_wms(workspace_name) - return self.put_request( - self.rest_endpoints.workspace_wms_settings(workspace_name), json=data - ) + self.rest_service.publish_workspace(workspace_name) def set_default_locale_for_service( self, workspace_name: str, locale: str | None diff --git a/geoservercloud/models/workspace.py b/geoservercloud/models/workspace.py index 29448f0..19f509b 100644 --- a/geoservercloud/models/workspace.py +++ b/geoservercloud/models/workspace.py @@ -28,5 +28,11 @@ def from_dict(cls, content: dict): content.get("workspace", {}).get("isolated", False), ) + def asdict(self): + return { + "name": self.name, + "isolated": self.isolated, + } + def __repr__(self): return json.dumps(self.put_payload(), indent=4) diff --git a/geoservercloud/services/__init__.py b/geoservercloud/services/__init__.py index d885ea3..65b583e 100644 --- a/geoservercloud/services/__init__.py +++ b/geoservercloud/services/__init__.py @@ -1,10 +1,5 @@ -from .endpoints import AclEndpoints, GwcEndpoints, OwsEndpoints, RestEndpoints from .restservice import RestService __all__ = [ "RestService", - "AclEndpoints", - "OwsEndpoints", - "GwcEndpoints", - "RestEndpoints", ] diff --git a/geoservercloud/services/endpoints.py b/geoservercloud/services/endpoints.py deleted file mode 100644 index 6a7f557..0000000 --- a/geoservercloud/services/endpoints.py +++ /dev/null @@ -1,174 +0,0 @@ -class AclEndpoints: - def __init__(self, base_url: str = "/acl") -> None: - self.base_url: str = base_url - - def adminrules(self) -> str: - return f"{self.base_url}/api/adminrules" - - def adminrule(self, id: int) -> str: - return f"{self.base_url}/api/adminrules/id/{id}" - - def rules(self) -> str: - return f"{self.base_url}/api/rules" - - -class GwcEndpoints: - def __init__(self, base_url: str = "/gwc/rest") -> None: - self.base_url: str = base_url - - def reload(self) -> str: - return f"{self.base_url}/reload" - - def layers(self, workspace_name: str) -> str: - return f"{self.base_url}/layers.json" - - def layer(self, workspace_name: str, layer_name: str) -> str: - return f"{self.base_url}/layers/{workspace_name}:{layer_name}.json" - - def gridsets(self) -> str: - return f"{self.base_url}/gridsets.json" - - def gridset(self, epsg: int) -> str: - return f"{self.base_url}/gridsets/EPSG:{str(epsg)}.xml" - - -class OwsEndpoints: - def __init__(self, base_url: str = "") -> None: - self.base_url: str = base_url - - def ows(self) -> str: - return f"{self.base_url}/ows" - - def wms(self) -> str: - return f"{self.base_url}/wms" - - def wfs(self) -> str: - return f"{self.base_url}/wfs" - - def wcs(self) -> str: - return f"{self.base_url}/wcs" - - def wmts(self) -> str: - return f"{self.base_url}/gwc/service/wmts" - - def workspace_ows(self, workspace_name: str) -> str: - return f"{self.base_url}/{workspace_name}/ows" - - def workspace_wms(self, workspace_name: str) -> str: - return f"{self.base_url}/{workspace_name}/wms" - - def workspace_wfs(self, workspace_name: str) -> str: - return f"{self.base_url}/{workspace_name}/wfs" - - def workspace_wcs(self, workspace_name: str) -> str: - return f"{self.base_url}/{workspace_name}/wcs" - - -class RestEndpoints: - def __init__(self, base_url: str = "/rest") -> None: - self.base_url: str = base_url - - def styles(self) -> str: - return f"{self.base_url}/styles.json" - - def style(self, style_name: str) -> str: - return f"{self.base_url}/styles/{style_name}.json" - - def workspaces(self) -> str: - return f"{self.base_url}/workspaces.json" - - def workspace(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}.json" - - def workspace_styles(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/styles.json" - - def workspace_style(self, workspace_name: str, style_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/styles/{style_name}.json" - - def workspace_layer(self, workspace_name: str, layer_name: str) -> str: - return f"{self.base_url}/layers/{workspace_name}:{layer_name}.json" - - def workspace_wms_settings(self, workspace_name: str) -> str: - return f"{self.base_url}/services/wms/workspaces/{workspace_name}/settings.json" - - def workspace_wfs_settings(self, workspace_name: str) -> str: - return f"{self.base_url}/services/wfs/workspaces/{workspace_name}/settings.json" - - def datastores(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/datastores.json" - - def datastore(self, workspace_name: str, datastore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}.json" - - def featuretypes(self, workspace_name: str, datastore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}/featuretypes.json" - - def featuretype( - self, workspace_name: str, datastore_name: str, featuretype_name: str - ) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}/featuretypes/{featuretype_name}.json" - - def layergroup(self, workspace_name: str, layergroup_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/layergroups/{layergroup_name}.json" - - def layergroups(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/layergroups.json" - - def coveragestores(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/coveragestores.json" - - def coveragestore(self, workspace_name: str, coveragestore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}.json" - - def coverages(self, workspace_name: str, coveragestore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}/coverages.json" - - def coverage( - self, workspace_name: str, coveragestore_name: str, coverage_name: str - ) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}/coverages/{coverage_name}.json" - - def wmsstores(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmsstores.json" - - def wmsstore(self, workspace_name: str, wmsstore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmsstores/{wmsstore_name}.json" - - def wmtsstores(self, workspace_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores.json" - - def wmtsstore(self, workspace_name: str, wmtsstore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}.json" - - def wmtslayers(self, workspace_name: str, wmtsstore_name: str) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}/layers.json" - - def wmtslayer( - self, workspace_name: str, wmtsstore_name: str, wmtslayer_name: str - ) -> str: - return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}/layers/{wmtslayer_name}.json" - - def namespaces(self) -> str: - return f"{self.base_url}/namespaces.json" - - def namespace(self, namespace_name: str) -> str: - return f"{self.base_url}/namespaces/{namespace_name}.json" - - def users(self) -> str: - return f"{self.base_url}/security/usergroup/users.json" - - def user(self, username: str) -> str: - return f"{self.base_url}/security/usergroup/user/{username}.json" - - def roles(self) -> str: - return f"{self.base_url}/security/roles.json" - - def user_roles(self, username: str) -> str: - return f"{self.base_url}/security/roles/user/{username}.json" - - def role(self, role_name: str) -> str: - return f"{self.base_url}/security/roles/role/{role_name}.json" - - def role_user(self, role_name: str, username: str) -> str: - return f"{self.base_url}/security/roles/role/{role_name}/user/{username}.json" diff --git a/geoservercloud/services/restclient.py b/geoservercloud/services/restclient.py new file mode 100644 index 0000000..2d3c768 --- /dev/null +++ b/geoservercloud/services/restclient.py @@ -0,0 +1,87 @@ +from typing import Any + +import requests + +TIMEOUT = 120 + + +class RestClient: + def __init__(self, url: str, auth: tuple[str, str]) -> None: + self.url: str = url + self.auth: tuple[str, str] = auth + + def get( + self, + path: str, + params: dict[str, str] | None = None, + headers: dict[str, str] | None = None, + ) -> requests.Response: + response: requests.Response = requests.get( + f"{self.url}{path}", + params=params, + headers=headers, + auth=self.auth, + timeout=TIMEOUT, + ) + if response.status_code != 404: + response.raise_for_status() + return response + + def post( + self, + path: str, + params: dict[str, str] | None = None, + headers: dict[str, str] | None = None, + json: dict[str, dict[str, Any]] | None = None, + data: bytes | None = None, + ) -> requests.Response: + + response: requests.Response = requests.post( + f"{self.url}{path}", + params=params, + headers=headers, + json=json, + data=data, + auth=self.auth, + timeout=TIMEOUT, + ) + if response.status_code != 409: + response.raise_for_status() + return response + + def put( + self, + path: str, + params: dict[str, str] | None = None, + headers: dict[str, str] | None = None, + json: dict[str, dict[str, Any]] | None = None, + data: bytes | None = None, + ) -> requests.Response: + response: requests.Response = requests.put( + f"{self.url}{path}", + params=params, + headers=headers, + json=json, + data=data, + auth=self.auth, + timeout=TIMEOUT, + ) + response.raise_for_status() + return response + + def delete( + self, + path: str, + params: dict[str, str] | None = None, + headers: dict[str, str] | None = None, + ) -> requests.Response: + response: requests.Response = requests.delete( + f"{self.url}{path}", + params=params, + headers=headers, + auth=self.auth, + timeout=TIMEOUT, + ) + if response.status_code != 404: + response.raise_for_status() + return response diff --git a/geoservercloud/services/restservice.py b/geoservercloud/services/restservice.py index 14e67b3..44cdd66 100644 --- a/geoservercloud/services/restservice.py +++ b/geoservercloud/services/restservice.py @@ -1,87 +1,224 @@ from typing import Any - -import requests - -TIMEOUT = 120 +from requests import Response +from geoservercloud.models import Workspace, Workspaces +from geoservercloud.services.restclient import RestClient +from geoservercloud.templates import Templates class RestService: + def __init__(self, url: str, auth: tuple[str, str]) -> None: self.url: str = url self.auth: tuple[str, str] = auth + self.rest_client = RestClient(url, auth) + self.acl_endpoints = self.AclEndpoints() + self.gwc_endpoints = self.GwcEndpoints() + self.ows_endpoints = self.OwsEndpoints() + self.rest_endpoints = self.RestEndpoints() - def get( - self, - path: str, - params: dict[str, str] | None = None, - headers: dict[str, str] | None = None, - ) -> requests.Response: - response: requests.Response = requests.get( - f"{self.url}{path}", - params=params, - headers=headers, - auth=self.auth, - timeout=TIMEOUT, + def get_workspaces(self) -> Workspaces: + return Workspaces.from_dict( + self.rest_client.get(self.rest_endpoints.workspaces()).json() ) - if response.status_code != 404: - response.raise_for_status() - return response - - def post( - self, - path: str, - params: dict[str, str] | None = None, - headers: dict[str, str] | None = None, - json: dict[str, dict[str, Any]] | None = None, - data: bytes | None = None, - ) -> requests.Response: - - response: requests.Response = requests.post( - f"{self.url}{path}", - params=params, - headers=headers, - json=json, - data=data, - auth=self.auth, - timeout=TIMEOUT, + + def create_workspace( + self, workspace_name: str, isolated: bool = False + ) -> Workspace: + workspace = Workspace(workspace_name, isolated) + response: Response = self.rest_client.post( + self.rest_endpoints.workspaces(), + json=workspace.post_payload(), ) - if response.status_code != 409: - response.raise_for_status() - return response - - def put( - self, - path: str, - params: dict[str, str] | None = None, - headers: dict[str, str] | None = None, - json: dict[str, dict[str, Any]] | None = None, - data: bytes | None = None, - ) -> requests.Response: - response: requests.Response = requests.put( - f"{self.url}{path}", - params=params, - headers=headers, - json=json, - data=data, - auth=self.auth, - timeout=TIMEOUT, + if response.status_code == 409: + response = self.rest_client.put( + self.rest_endpoints.workspace(workspace_name), + json=workspace.put_payload(), + ) + return workspace + + def delete_workspace(self, workspace_name: str) -> None: + self.rest_client.delete( + self.rest_endpoints.workspace(workspace_name), params={"recurse": "true"} ) - response.raise_for_status() - return response - - def delete( - self, - path: str, - params: dict[str, str] | None = None, - headers: dict[str, str] | None = None, - ) -> requests.Response: - response: requests.Response = requests.delete( - f"{self.url}{path}", - params=params, - headers=headers, - auth=self.auth, - timeout=TIMEOUT, + + def publish_workspace(self, workspace_name) -> None: + data: dict[str, dict[str, Any]] = Templates.workspace_wms(workspace_name) + self.rest_client.put( + self.rest_endpoints.workspace_wms_settings(workspace_name), json=data ) - if response.status_code != 404: - response.raise_for_status() - return response + + class AclEndpoints: + def __init__(self, base_url: str = "/acl") -> None: + self.base_url: str = base_url + + def adminrules(self) -> str: + return f"{self.base_url}/api/adminrules" + + def adminrule(self, id: int) -> str: + return f"{self.base_url}/api/adminrules/id/{id}" + + def rules(self) -> str: + return f"{self.base_url}/api/rules" + + class GwcEndpoints: + def __init__(self, base_url: str = "/gwc/rest") -> None: + self.base_url: str = base_url + + def reload(self) -> str: + return f"{self.base_url}/reload" + + def layers(self, workspace_name: str) -> str: + return f"{self.base_url}/layers.json" + + def layer(self, workspace_name: str, layer_name: str) -> str: + return f"{self.base_url}/layers/{workspace_name}:{layer_name}.json" + + def gridsets(self) -> str: + return f"{self.base_url}/gridsets.json" + + def gridset(self, epsg: int) -> str: + return f"{self.base_url}/gridsets/EPSG:{str(epsg)}.xml" + + class OwsEndpoints: + def __init__(self, base_url: str = "") -> None: + self.base_url: str = base_url + + def ows(self) -> str: + return f"{self.base_url}/ows" + + def wms(self) -> str: + return f"{self.base_url}/wms" + + def wfs(self) -> str: + return f"{self.base_url}/wfs" + + def wcs(self) -> str: + return f"{self.base_url}/wcs" + + def wmts(self) -> str: + return f"{self.base_url}/gwc/service/wmts" + + def workspace_ows(self, workspace_name: str) -> str: + return f"{self.base_url}/{workspace_name}/ows" + + def workspace_wms(self, workspace_name: str) -> str: + return f"{self.base_url}/{workspace_name}/wms" + + def workspace_wfs(self, workspace_name: str) -> str: + return f"{self.base_url}/{workspace_name}/wfs" + + def workspace_wcs(self, workspace_name: str) -> str: + return f"{self.base_url}/{workspace_name}/wcs" + + class RestEndpoints: + def __init__(self, base_url: str = "/rest") -> None: + self.base_url: str = base_url + + def styles(self) -> str: + return f"{self.base_url}/styles.json" + + def style(self, style_name: str) -> str: + return f"{self.base_url}/styles/{style_name}.json" + + def workspaces(self) -> str: + return f"{self.base_url}/workspaces.json" + + def workspace(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}.json" + + def workspace_styles(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/styles.json" + + def workspace_style(self, workspace_name: str, style_name: str) -> str: + return ( + f"{self.base_url}/workspaces/{workspace_name}/styles/{style_name}.json" + ) + + def workspace_layer(self, workspace_name: str, layer_name: str) -> str: + return f"{self.base_url}/layers/{workspace_name}:{layer_name}.json" + + def workspace_wms_settings(self, workspace_name: str) -> str: + return f"{self.base_url}/services/wms/workspaces/{workspace_name}/settings.json" + + def workspace_wfs_settings(self, workspace_name: str) -> str: + return f"{self.base_url}/services/wfs/workspaces/{workspace_name}/settings.json" + + def datastores(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/datastores.json" + + def datastore(self, workspace_name: str, datastore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}.json" + + def featuretypes(self, workspace_name: str, datastore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}/featuretypes.json" + + def featuretype( + self, workspace_name: str, datastore_name: str, featuretype_name: str + ) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/datastores/{datastore_name}/featuretypes/{featuretype_name}.json" + + def layergroup(self, workspace_name: str, layergroup_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/layergroups/{layergroup_name}.json" + + def layergroups(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/layergroups.json" + + def coveragestores(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/coveragestores.json" + + def coveragestore(self, workspace_name: str, coveragestore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}.json" + + def coverages(self, workspace_name: str, coveragestore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}/coverages.json" + + def coverage( + self, workspace_name: str, coveragestore_name: str, coverage_name: str + ) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/coveragestores/{coveragestore_name}/coverages/{coverage_name}.json" + + def wmsstores(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmsstores.json" + + def wmsstore(self, workspace_name: str, wmsstore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmsstores/{wmsstore_name}.json" + + def wmtsstores(self, workspace_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores.json" + + def wmtsstore(self, workspace_name: str, wmtsstore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}.json" + + def wmtslayers(self, workspace_name: str, wmtsstore_name: str) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}/layers.json" + + def wmtslayer( + self, workspace_name: str, wmtsstore_name: str, wmtslayer_name: str + ) -> str: + return f"{self.base_url}/workspaces/{workspace_name}/wmtsstores/{wmtsstore_name}/layers/{wmtslayer_name}.json" + + def namespaces(self) -> str: + return f"{self.base_url}/namespaces.json" + + def namespace(self, namespace_name: str) -> str: + return f"{self.base_url}/namespaces/{namespace_name}.json" + + def users(self) -> str: + return f"{self.base_url}/security/usergroup/users.json" + + def user(self, username: str) -> str: + return f"{self.base_url}/security/usergroup/user/{username}.json" + + def roles(self) -> str: + return f"{self.base_url}/security/roles.json" + + def user_roles(self, username: str) -> str: + return f"{self.base_url}/security/roles/user/{username}.json" + + def role(self, role_name: str) -> str: + return f"{self.base_url}/security/roles/role/{role_name}.json" + + def role_user(self, role_name: str, username: str) -> str: + return ( + f"{self.base_url}/security/roles/role/{role_name}/user/{username}.json" + ) diff --git a/tests/test_workspace.py b/tests/test_workspace.py index a2d28bf..a68beab 100644 --- a/tests/test_workspace.py +++ b/tests/test_workspace.py @@ -21,8 +21,7 @@ def test_list_workspaces(geoserver: GeoServerCloud) -> None: } }, ) - workspaces = geoserver.get_workspaces() - assert workspaces.workspaces == ["test_workspace"] + assert geoserver.get_workspaces() == ["test_workspace"] def test_create_workspace(geoserver: GeoServerCloud) -> None: @@ -45,9 +44,10 @@ def test_create_workspace(geoserver: GeoServerCloud) -> None: ], ) - response = geoserver.create_workspace(workspace, isolated=isolated) - - assert response.status_code == 201 + assert geoserver.create_workspace(workspace, isolated=isolated) == { + "name": workspace, + "isolated": isolated, + } def test_update_workspace(geoserver: GeoServerCloud) -> None: @@ -63,9 +63,10 @@ def test_update_workspace(geoserver: GeoServerCloud) -> None: status=200, ) - response = geoserver.create_workspace(workspace) - - assert response.status_code == 200 + assert geoserver.create_workspace(workspace) == { + "name": workspace, + "isolated": False, + } def test_delete_workspace(geoserver: GeoServerCloud) -> None: @@ -77,9 +78,7 @@ def test_delete_workspace(geoserver: GeoServerCloud) -> None: status=200, ) - response = geoserver.delete_workspace(workspace) - - assert response.status_code == 200 + assert geoserver.delete_workspace(workspace) == None def test_recreate_workspace(geoserver: GeoServerCloud) -> None: @@ -95,9 +94,10 @@ def test_recreate_workspace(geoserver: GeoServerCloud) -> None: status=201, ) - response = geoserver.recreate_workspace(workspace) - - assert response.status_code == 201 + assert geoserver.recreate_workspace(workspace) == { + "name": workspace, + "isolated": False, + } def test_publish_workspace(geoserver: GeoServerCloud) -> None: @@ -155,6 +155,4 @@ def test_publish_workspace(geoserver: GeoServerCloud) -> None: ], ) - response = geoserver.publish_workspace(workspace) - - assert response.status_code == 200 + assert geoserver.publish_workspace(workspace) == None