Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Sep 11, 2024
1 parent 5795feb commit 8388246
Show file tree
Hide file tree
Showing 13 changed files with 778 additions and 26 deletions.
4 changes: 2 additions & 2 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ def publish_workspace(self, workspace) -> Response:

def set_default_locale_for_service(
self, workspace: str, locale: str | None
) -> None:
) -> Response:
path: str = self.workspace_wms_settings_path(workspace)
data: dict[str, dict[str, Any]] = {
"wms": {
"defaultLocale": locale,
}
}
self.put_request(path, json=data)
return self.put_request(path, json=data)

def unset_default_locale_for_service(self, workspace) -> None:
self.set_default_locale_for_service(workspace, None)
Expand Down
1 change: 1 addition & 0 deletions tests/resources/style.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<style></style>
Empty file added tests/resources/style.zip
Empty file.
43 changes: 43 additions & 0 deletions tests/resources/test_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import responses

from geoservercloud.geoservercloud import GeoServerCloud


def test_create_resource(geoserver: GeoServerCloud) -> None:
path = "/new/resource"
resource_path = "/new/resource/resource.json"
payload = {"something": "new"}
with responses.RequestsMock() as rsps:
rsps.get(
url=f"{geoserver.url}{resource_path}",
status=404,
)
rsps.post(
url=f"{geoserver.url}{path}",
status=201,
match=[responses.matchers.json_params_matcher(payload)],
)

response = geoserver.create_or_update_resource(path, resource_path, payload)

assert response.status_code == 201


def test_update_resource(geoserver: GeoServerCloud) -> None:
path = "/some/resource"
resource_path = "/some/resource/resource.json"
payload = {"something": "something"}
with responses.RequestsMock() as rsps:
rsps.get(
url=f"{geoserver.url}{resource_path}",
status=200,
)
rsps.put(
url=f"{geoserver.url}{resource_path}",
status=200,
match=[responses.matchers.json_params_matcher(payload)],
)

response = geoserver.create_or_update_resource(path, resource_path, payload)

assert response.status_code == 200
93 changes: 93 additions & 0 deletions tests/test_acl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import responses
import responses.matchers

from geoservercloud.geoservercloud import GeoServerCloud


def test_create_acl_admin_rule(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.post(
url=f"{geoserver.url}/acl/api/adminrules",
status=201,
match=[
responses.matchers.json_params_matcher(
{
"priority": 1,
"access": "ADMIN",
"role": "TEST_ROLE",
"user": "TEST_USER",
"workspace": "TEST_WORKSPACE",
}
)
],
)

response = geoserver.create_acl_admin_rule(
priority=1,
access="ADMIN",
role="TEST_ROLE",
user="TEST_USER",
workspace="TEST_WORKSPACE",
)
assert response.status_code == 201


def test_create_acl_rule(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.post(
url=f"{geoserver.url}/acl/api/rules",
status=201,
match=[
responses.matchers.json_params_matcher(
{
"priority": 1,
"access": "ALLOW",
"role": "TEST_ROLE",
"workspace": "TEST_WORKSPACE",
"service": "WMS",
}
)
],
)

response = geoserver.create_acl_rule(
priority=1,
access="ALLOW",
role="TEST_ROLE",
workspace="TEST_WORKSPACE",
service="WMS",
)
assert response.status_code == 201


def test_delete_acl_admin_rule(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
url=f"{geoserver.url}/acl/api/adminrules/id/1",
status=200,
)

response = geoserver.delete_acl_admin_rule(1)
assert response.status_code == 200


def test_delete_all_acl_admin_rules(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
url=f"{geoserver.url}/acl/api/adminrules",
status=200,
)

response = geoserver.delete_all_acl_admin_rules()
assert response.status_code == 200


def test_delete_all_acl_rules(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
url=f"{geoserver.url}/acl/api/rules",
status=200,
)

response = geoserver.delete_all_acl_rules()
assert response.status_code == 200
20 changes: 11 additions & 9 deletions tests/test_cascaded_wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
LAYER = "test_layer"
NATIVE_LAYER = "test_native_layer"
CAPABILITIES = """<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" version="1.0.0">
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" version="1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1">
<Contents>
<Layer>
<WGS84BoundingBox>
<LowerCorner>5.140242 45.398181</LowerCorner>
<UpperCorner>11.47757 48.230651</UpperCorner>
</WGS84BoundingBox>
<ows:Identifier>test_native_layer</ows:Identifier>
<ows:WGS84BoundingBox>
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
</ows:WGS84BoundingBox>
</Layer>
</Contents>
</Capabilities>
Expand Down Expand Up @@ -58,7 +59,7 @@ def wmts_layer_payload() -> dict[str, dict[str, Any]]:
"maxy": 48.230651,
},
"nativeBoundingBox": {
"crs": {"$": "EPSG:4326", "@class": "projected"},
"crs": "EPSG:4326",
"minx": 5.140242,
"maxx": 11.47757,
"miny": 45.398181,
Expand All @@ -78,7 +79,7 @@ def test_create_wmts_store(
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores.json",
json=wmts_store_payload,
match=[responses.matchers.json_params_matcher(wmts_store_payload)],
status=201,
)
response = geoserver.create_wmts_store(
Expand All @@ -100,7 +101,7 @@ def test_update_wmts_store(
)
rsps.put(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
json=wmts_store_payload,
match=[responses.matchers.json_params_matcher(wmts_store_payload)],
status=200,
)
response = geoserver.create_wmts_store(
Expand Down Expand Up @@ -129,10 +130,11 @@ def test_create_wmts_layer(
CAPABILITIES_URL,
status=200,
body=CAPABILITIES,
headers={"Content-Type": "application/xml"},
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers.json",
json=wmts_layer_payload,
match=[responses.matchers.json_params_matcher(wmts_layer_payload)],
status=201,
)
response = geoserver.create_wmts_layer(
Expand Down
38 changes: 23 additions & 15 deletions tests/test_feature_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,36 @@ def feature_type_payload() -> dict[str, dict[str, Any]]:
"name": f"{WORKSPACE}:{STORE}",
},
"attributes": {
"attribute": {
"geom": {
"type": "Point",
"required": True,
"attribute": [
{
"name": "geom",
"minOccurs": 1,
"maxOccurs": 1,
"nillable": False,
"binding": "org.locationtech.jts.geom.Point",
}
},
]
},
"latLonBoundingBox": {
"crs": "EPSG:4326",
"minx": 5.140242,
"maxx": 11.47757,
"miny": 45.398181,
"maxy": 48.230651,
"maxx": 180,
"maxy": 90,
"minx": -180,
"miny": -90,
},
"nativeBoundingBox": {
"crs": {"$": "EPSG:4326", "@class": "projected"},
"minx": 5.140242,
"maxx": 11.47757,
"miny": 45.398181,
"maxy": 48.230651,
"maxx": 180,
"maxy": 90,
"minx": -180,
"miny": -90,
},
"internationalTitle": {
"en": "English",
},
"internationalAbstract": {
"en": "English",
},
}
}

Expand All @@ -60,14 +66,15 @@ def test_create_feature_type(
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/datastores/{STORE}/featuretypes.json",
json=feature_type_payload,
match=[responses.matchers.json_params_matcher(feature_type_payload)],
status=201,
)
response = geoserver.create_feature_type(
workspace=WORKSPACE,
datastore=STORE,
layer=LAYER,
title={"en": "English"},
abstract={"en": "English"},
)

assert response
Expand All @@ -84,14 +91,15 @@ def test_update_feature_type(
)
rsps.put(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/datastores/{STORE}/featuretypes/{LAYER}.json",
json=feature_type_payload,
match=[responses.matchers.json_params_matcher(feature_type_payload)],
status=200,
)
response = geoserver.create_feature_type(
workspace=WORKSPACE,
datastore=STORE,
layer=LAYER,
title={"en": "English"},
abstract={"en": "English"},
)

assert response
Expand Down
Loading

0 comments on commit 8388246

Please sign in to comment.