Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Aug 23, 2024
1 parent 90273d2 commit 10ac34a
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ jobs:
- name: Install
run: make install

- name: Build
run: make build

- name: Tests
run: make tests

Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ help: ## Display this help message

.PHONY: install
install: ## Install package
poetry lock --no-update
poetry install

.PHONY: build
build: ## Build package
poetry build

.PHONY: tests
tests: ## Run unit tests
poetry run pytest -vvv tests --color=yes
tests: ## Run unit tests with coverage
poetry run coverage run --source=geoservercloud -m pytest tests -vvv --color=yes
poetry run coverage report
8 changes: 5 additions & 3 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ def delete_workspace(self, workspace: str) -> Response:

def recreate_workspace(
self, workspace: str, set_default_workspace: bool = False
) -> None:
) -> Response:
"""
Create a workspace in GeoServer, and first delete it if it already exists.
"""
self.delete_workspace(workspace)
self.create_workspace(workspace, set_default_workspace=set_default_workspace)
return self.create_workspace(
workspace, set_default_workspace=set_default_workspace
)

def publish_workspace(self, workspace) -> Response:
path: str = f"{self.workspace_wms_settings_path(workspace)}"
Expand Down Expand Up @@ -333,7 +335,7 @@ def publish_gwc_layer(
self.post_request(
"/gwc/rest/reload",
headers={"Content-Type": "application/json"},
data="reload_configuration=1",
data="reload_configuration=1", # type: ignore
)
payload = Templates.gwc_layer(workspace, layer, f"EPSG:{epsg}")
return self.put_request(
Expand Down
107 changes: 106 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Lightweight Python client to interact with GeoServer Cloud REST A
authors = ["Camptocamp <[email protected]>"]
license = "BSD-2-Clause"
readme = "README.md"
packages = [{include = "geoservercloud"}]
packages = [{ include = "geoservercloud" }]

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand All @@ -15,12 +15,14 @@ xmltodict = "0.13.0"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.2"
responses = "0.25.3"
coverage = "7.6.1"

[build-system]
requires = [
"poetry-core>=1.0.0",
"poetry-dynamic-versioning[plugin]",
"poetry-plugin-tweak-dependencies-version"
"poetry-plugin-tweak-dependencies-version",
]
build-backend = "poetry.core.masonry.api"

Expand Down
Empty file added tests/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from geoservercloud import GeoServerCloud

GEOSERVER_URL = "http://localhost:8080/geoserver"


@pytest.fixture(scope="session")
def geoserver():
geoserver = GeoServerCloud(url=GEOSERVER_URL)
yield geoserver
68 changes: 68 additions & 0 deletions tests/test_cascaded_wmts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import Any

import pytest
import responses

from geoservercloud.geoservercloud import GeoServerCloud

WORKSPACE = "test_workspace"
STORE = "test_wmtsstore"
CAPABILITIES_URL = "http://wms?request=GetCapabilities&service=WMS"


@pytest.fixture(scope="module")
def wmts_store_payload() -> dict[str, dict[str, Any]]:
return {
"wmtsStore": {
"name": STORE,
"type": "WMTS",
"capabilitiesURL": CAPABILITIES_URL,
"workspace": {"name": WORKSPACE},
"enabled": True,
"metadata": {"entry": {"@key": "useConnectionPooling", "text": True}},
}
}


def test_create_wmts_store(
geoserver: GeoServerCloud, wmts_store_payload: dict[str, dict[str, Any]]
) -> None:
with responses.RequestsMock() as rsps:
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
status=404,
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores.json",
json=wmts_store_payload,
status=201,
)
response = geoserver.create_wmts_store(
workspace=WORKSPACE,
name=STORE,
capabilities=CAPABILITIES_URL,
)
assert response
assert response.status_code == 201


def test_update_wmts_store(
geoserver: GeoServerCloud, wmts_store_payload: dict[str, dict[str, Any]]
) -> None:
with responses.RequestsMock() as rsps:
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
status=200,
)
rsps.put(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
json=wmts_store_payload,
status=200,
)
response = geoserver.create_wmts_store(
workspace=WORKSPACE,
name=STORE,
capabilities=CAPABILITIES_URL,
)
assert response
assert response.status_code == 200
Loading

0 comments on commit 10ac34a

Please sign in to comment.