mirror of
https://github.com/geoserver/geoserver-cloud.git
synced 2025-12-08 20:16:08 +00:00
The GeoServerCloud client in acceptance tests was not explicitly passing authentication credentials, which worked locally but failed in CI environments. This change explicitly initializes the client with admin/geoserver credentials, ensuring consistent behavior across all environments. This fixes 403 Forbidden errors when running acceptance tests in CI.
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
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")
|
|
GEOSERVER_USERNAME = os.getenv("GEOSERVER_USERNAME", "admin")
|
|
GEOSERVER_PASSWORD = os.getenv("GEOSERVER_PASSWORD", "geoserver")
|
|
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(
|
|
url=GEOSERVER_URL,
|
|
user=GEOSERVER_USERNAME,
|
|
password=GEOSERVER_PASSWORD
|
|
)
|
|
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)
|