-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from vuilleumierc/issue-521-acceptance-tests
Add acceptance tests
- Loading branch information
Showing
41 changed files
with
1,367 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ignore all python cache files recursively | ||
**/__pycache__/ | ||
poetry.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM ubuntu:24.04 AS base | ||
|
||
RUN apt-get update \ | ||
&& apt-get upgrade --assume-yes \ | ||
&& apt-get install --assume-yes --no-install-recommends \ | ||
vim curl jq libmagic1 zip python3-pip libpq-dev python3-dev gcc \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& rm /usr/lib/python*/EXTERNALLY-MANAGED | ||
|
||
COPY . /acceptance_tests | ||
|
||
WORKDIR /acceptance_tests | ||
RUN python3 -m pip install --disable-pip-version-check . | ||
|
||
COPY entrypoint.py /bin/entrypoint.py | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
ENTRYPOINT ["/bin/entrypoint.py"] | ||
|
||
HEALTHCHECK --interval=5s --start-period=15s --retries=20 CMD test -f /tmp/healthcheck || exit 1 | ||
|
||
CMD ["sleep", "infinity"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# GeoServer Cloud acceptance tests | ||
|
||
## Requirements | ||
|
||
[Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer) | ||
|
||
## Installation | ||
|
||
```shell | ||
poetry install | ||
``` | ||
|
||
# Run the tests | ||
First start the docker composition then run: | ||
|
||
```shell | ||
GEOSERVER_URL=http://localhost:9090/geoserver/cloud poetry run pytest -vvv . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
import time | ||
import os | ||
import requests | ||
import sys | ||
|
||
# Set variables | ||
start_time = time.time() | ||
|
||
# Set a maximum timeout from the environment or use 60 seconds as default | ||
max_time = int(os.getenv('MAX_TIMEOUT', 60)) | ||
|
||
# Set the GEOSERVER_URL from the environment or use the default value | ||
GEOSERVER_URL = os.getenv('GEOSERVER_URL', 'http://gateway:8080/geoserver/cloud') | ||
GEOSERVER_USERNAME = os.getenv('GEOSERVER_USERNAME', 'admin') | ||
GEOSERVER_PASSWORD = os.getenv('GEOSERVER_PASSWORD', 'geoserver') | ||
|
||
# is we want to start directly with the passed command | ||
IGNORE_HEALTH_CHECK = os.getenv('IGNORE_HEALTH_CHECK', False) | ||
|
||
# Timeout function | ||
def timeout(): | ||
current_time = time.time() | ||
if current_time - start_time > max_time: | ||
return True | ||
return False | ||
|
||
# Array of endpoints to check | ||
endpoints = [ | ||
f"{GEOSERVER_URL}/wms?SERVICE=WMS&REQUEST=GetCapabilities", | ||
f"{GEOSERVER_URL}/wfs?SERVICE=WFS&REQUEST=GetCapabilities", | ||
f"{GEOSERVER_URL}/wps?SERVICE=WPS&REQUEST=GetCapabilities", | ||
f"{GEOSERVER_URL}/wcs?SERVICE=WCS&REQUEST=GetCapabilities", | ||
f"{GEOSERVER_URL}/ows?SERVICE=WMS&REQUEST=GetCapabilities", | ||
f"{GEOSERVER_URL}/gwc", | ||
f"{GEOSERVER_URL}/rest", | ||
] | ||
|
||
if not IGNORE_HEALTH_CHECK: | ||
# Loop through each endpoint and check if it's available | ||
for endpoint in endpoints: | ||
print(f"Waiting for {endpoint} to be available...") | ||
if timeout(): | ||
print("Timeout") | ||
break | ||
|
||
while True: | ||
try: | ||
# Make a request to the endpoint | ||
response = requests.get(endpoint, auth=(GEOSERVER_USERNAME, GEOSERVER_PASSWORD)) | ||
if response.status_code == 200: | ||
print(f"{endpoint} is up") | ||
break | ||
else: | ||
print(f"{endpoint} returned status code {response.status_code}") | ||
except requests.exceptions.RequestException as e: | ||
print(f"{endpoint} is not available - retrying...") | ||
|
||
if timeout(): | ||
print("Timeout reached") | ||
break | ||
|
||
time.sleep(1) | ||
|
||
# create /tmp/healthcheck file to signal that the healthcheck is done | ||
with open("/tmp/healthcheck", "w") as f: | ||
f.write("done") | ||
# Execute the command passed to the script anyway, this is useful for | ||
# running the tests and see what breaks | ||
if len(sys.argv) > 1: | ||
command = sys.argv[1:] | ||
os.execvp(command[0], command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[tool.poetry] | ||
name = "acceptance-tests" | ||
version = "0.1.0" | ||
description = "todo" | ||
authors = ["todo"] | ||
readme = "README.md" | ||
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] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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(): | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
.../tests/resources/labels/default_locale/default_value/language_None_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.87 KB
...ests/tests/resources/labels/default_locale/default_value/language__expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.16 KB
...ts/tests/resources/labels/default_locale/default_value/language_de_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
...ts/tests/resources/labels/default_locale/default_value/language_fr_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...ts/tests/resources/labels/default_locale/default_value/language_it_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
...sts/resources/labels/default_locale/no_default_value/language_None_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...s/tests/resources/labels/default_locale/no_default_value/language__expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...tests/resources/labels/default_locale/no_default_value/language_it_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.87 KB
...sts/resources/labels/no_default_locale/default_value/language_None_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.87 KB
...s/tests/resources/labels/no_default_locale/default_value/language__expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.16 KB
...tests/resources/labels/no_default_locale/default_value/language_de_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
...tests/resources/labels/no_default_locale/default_value/language_fr_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...tests/resources/labels/no_default_locale/default_value/language_it_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
.../resources/labels/no_default_locale/no_default_value/language_None_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...ests/resources/labels/no_default_locale/no_default_value/language__expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+670 Bytes
...ts/resources/labels/no_default_locale/no_default_value/language_it_expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.