Skip to content

Commit

Permalink
Add more acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Oct 1, 2024
1 parent fe35e23 commit 9b290af
Show file tree
Hide file tree
Showing 31 changed files with 888 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ acceptance-tests: build-acceptance

.PHONY: stop-acceptance-tests
stop-acceptance-tests: build-acceptance
(cd compose/ && TAG=$(TAG) GS_USER=$(UID):$(GID) docker compose $(COMPOSE_ACCEPTANCE_DATADIR_OPTIONS) down -v)
(cd compose/ && TAG=$(TAG) GS_USER=$(UID):$(GID) docker compose $(COMPOSE_ACCEPTANCE_DATADIR_OPTIONS) down -v)
2 changes: 2 additions & 0 deletions acceptance_tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ packages = [{ include = "tests" }]
[tool.poetry.dependencies]
python = "^3.10"
pytest = "^8.3.3"
psycopg2-binary = "^2.9.9"
geoservercloud = "^0.2.5"
sqlalchemy = "^2.0.35"


[build-system]
Expand Down
52 changes: 50 additions & 2 deletions acceptance_tests/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
import os
from pathlib import Path

import pytest
import sqlalchemy
from geoservercloud import GeoServerCloud


GEOSERVER_URL = os.getenv("GEOSERVER_URL", "http://gateway:8080/geoserver/cloud")
RESOURCE_DIR = Path(__file__).parent / "resources"
# Database connection
PGHOST = "geodatabase"
PGPORT = 5432
PGDATABASE = "geodata"
PGUSER = "geodata"
PGPASSWORD = "geodata"
PGSCHEMA = "test1"
WORKSPACE = "test_workspace"
DATASTORE = "test_datastore"


@pytest.fixture(scope="session", autouse=True)
def engine():
yield sqlalchemy.create_engine(
f"postgresql://{PGUSER}:{PGPASSWORD}@{PGHOST}:{PGPORT}/{PGDATABASE}",
)


@pytest.fixture(scope="session", autouse=True)
def db_session(engine):
with engine.connect() as connection:
connection.execute(
sqlalchemy.sql.text(f"CREATE SCHEMA IF NOT EXISTS {PGSCHEMA}")
)
connection.execute(sqlalchemy.sql.text(f"SET SEARCH_PATH = {PGSCHEMA}"))
connection.commit()
yield connection
connection.execute(
sqlalchemy.sql.text(f"DROP SCHEMA IF EXISTS {PGSCHEMA} CASCADE")
)
connection.commit()


@pytest.fixture(scope="module")
def geoserver():
yield GeoServerCloud(GEOSERVER_URL)
geoserver = GeoServerCloud(GEOSERVER_URL)
geoserver.recreate_workspace(WORKSPACE, set_default_workspace=True)
geoserver.create_pg_datastore(
workspace=WORKSPACE,
datastore=DATASTORE,
pg_host=PGHOST,
pg_port=PGPORT,
pg_db=PGDATABASE,
pg_user=PGUSER,
pg_password=PGPASSWORD,
pg_schema=PGSCHEMA,
set_default_datastore=True,
)
geoserver.publish_workspace(WORKSPACE)
yield geoserver
geoserver.delete_workspace(WORKSPACE)
15 changes: 15 additions & 0 deletions acceptance_tests/tests/lib/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path


def write_actual_image(response, tag):
file = Path(f"/tmp/{tag}_actual.png")
file.parent.mkdir(parents=True, exist_ok=True)
with open(file, "wb") as fs:
fs.write(response.read())


def compare_images(dir, tag):
actual = f"/tmp/{tag}_actual.png"
expected = f"{dir}/{tag}_expected.png"
with open(actual, "rb") as fs1, open(expected, "rb") as fs2:
assert fs1.read() == fs2.read()
Binary file added acceptance_tests/tests/resources/getmap_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions acceptance_tests/tests/resources/localized_labels.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:se="http://www.opengis.net/se"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>localized_labels</Name>
<UserStyle>
<Name>localized_labels</Name>
<FeatureTypeStyle>
<Rule>
<Name>Localized labels</Name>
<TextSymbolizer>
<Label>
<ogc:Function name="Recode">
<ogc:Function name="language"/>
<ogc:Literal/>
<ogc:PropertyName>label_default</ogc:PropertyName>
<ogc:Literal>de</ogc:Literal>
<ogc:PropertyName>label_de</ogc:PropertyName>
<ogc:Literal>fr</ogc:Literal>
<ogc:PropertyName>label_fr</ogc:PropertyName>
</ogc:Function>
</Label>
<Fill>
<CssParameter name="fill">#000000</CssParameter>
</Fill>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
37 changes: 37 additions & 0 deletions acceptance_tests/tests/resources/localized_no_default.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:se="http://www.opengis.net/se"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>localized_style</Name>
<UserStyle>
<Name>localized_no_default</Name>
<FeatureTypeStyle>
<Rule>
<Name>Localized, no default value</Name>
<Title>
<Localized lang="en">English</Localized>
<Localized lang="de">Deutsch</Localized>
<Localized lang="fr">Français</Localized>
<Localized lang="it">Italiano</Localized>
</Title>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
37 changes: 37 additions & 0 deletions acceptance_tests/tests/resources/localized_with_default.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:se="http://www.opengis.net/se"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>localized_style</Name>
<UserStyle>
<Name>localized_with_default</Name>
<FeatureTypeStyle>
<Rule>
<Name>Localized, with default value</Name>
<Title>
Default label<Localized lang="en">English</Localized>
<Localized lang="de">Deutsch</Localized>
<Localized lang="fr">Français</Localized>
<Localized lang="it">Italiano</Localized>
</Title>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
16 changes: 16 additions & 0 deletions acceptance_tests/tests/resources/wfs_payload.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<Insert>
<test_wfs xmlns="test_wfs">
<geom>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:2056">
<pos srsDimension="2">2600000.0 1200000.0</pos>
</Point>
</geom>
<timestamp>2024-05-13T08:14:48.763Z</timestamp>
<id>10</id>
<title>Title</title>
</test_wfs>
</Insert>
</Transaction>
24 changes: 24 additions & 0 deletions acceptance_tests/tests/test_datastore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from conftest import PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD, PGSCHEMA


def test_create_get_and_delete_datastore(geoserver):
workspace = datastore = "test_create_pg_datastore"
geoserver.create_workspace(workspace)
response = geoserver.create_pg_datastore(
workspace=workspace,
datastore=datastore,
pg_host=PGHOST,
pg_port=PGPORT,
pg_db=PGDATABASE,
pg_user=PGUSER,
pg_password=PGPASSWORD,
pg_schema=PGSCHEMA,
set_default_datastore=True,
)
assert response.status_code == 201
response = geoserver.get_request(
f"/rest/workspaces/{workspace}/datastores/{datastore}.json"
)
assert response.status_code == 200
response = geoserver.delete_workspace(workspace)
assert response.status_code == 200
47 changes: 47 additions & 0 deletions acceptance_tests/tests/test_gwc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

WORKSPACE = "test_gwc"
WMTS_STORE = "test_gwc_store"
WMTS_LAYER = "ch.swisstopo.swissimage"


@pytest.fixture(scope="module")
def geoserver_with_gwc_layers(geoserver):
geoserver.create_workspace(WORKSPACE)
geoserver.create_wmts_store(
WORKSPACE,
WMTS_STORE,
capabilities="https://wmts.geo.admin.ch/EPSG/4326/1.0.0/WMTSCapabilities.xml",
)
geoserver.create_wmts_layer(WORKSPACE, WMTS_STORE, WMTS_LAYER)
geoserver.get_request(
f"/rest/workspaces/{WORKSPACE}/wmtsstores/{WMTS_STORE}/layers/{WMTS_LAYER}.json"
)
response = geoserver.publish_gwc_layer(WORKSPACE, WMTS_LAYER)
assert response.status_code == 200
yield geoserver
geoserver.delete_workspace(WORKSPACE)


def test_tile_cache(geoserver_with_gwc_layers):

response = geoserver_with_gwc_layers.get_tile(
format="image/png",
layer=f"{WORKSPACE}:{WMTS_LAYER}",
tile_matrix_set="EPSG:4326",
tile_matrix="EPSG:4326:9",
row=122,
column=534,
)
assert response.info().get("Content-Type") == "image/png"
assert response.info().get("Geowebcache-Cache-Result") == "MISS"

response = geoserver_with_gwc_layers.get_tile(
format="image/png",
layer=f"{WORKSPACE}:{WMTS_LAYER}",
tile_matrix_set="EPSG:4326",
tile_matrix="EPSG:4326:9",
row=122,
column=534,
)
assert response.info().get("Geowebcache-Cache-Result") == "HIT"
Loading

0 comments on commit 9b290af

Please sign in to comment.