fix: removed database tests due to network mismatch
All checks were successful
Deploy Plattform-Core / test (push) Successful in 41s
Deploy Plattform-Core / deploy (push) Successful in 4s

This commit is contained in:
Ida 2026-05-20 16:47:42 +02:00
parent bc8b0288ca
commit 94ce05c443

View file

@ -6,6 +6,7 @@ Tests that database queries correctly filter records based on RBAC rules.
Uses real database connection for integration testing.
"""
import psycopg2
import pytest
from modules.connectors.connectorDbPostgre import DatabaseConnector
from modules.datamodels.datamodelUam import User, AccessLevel, UserPermissions
@ -20,7 +21,13 @@ def _dbConfig():
try:
host = APP_CONFIG.get("DB_HOST")
user = APP_CONFIG.get("DB_USER")
password = APP_CONFIG.get("DB_PASSWORD_SECRET") or APP_CONFIG.get("DB_PASSWORD")
port = int(APP_CONFIG.get("DB_PORT", 5432))
password = APP_CONFIG.get("DB_PASSWORD")
if password is None:
try:
password = APP_CONFIG.get("DB_PASSWORD_SECRET")
except Exception:
password = None
except Exception:
return None
if not host or not user or password is None:
@ -30,14 +37,43 @@ def _dbConfig():
"database": APP_CONFIG.get("DB_DATABASE", "poweron_test"),
"user": user,
"password": password,
"port": int(APP_CONFIG.get("DB_PORT", 5432)),
"port": port,
}
_DB_CFG = _dbConfig()
def _canReachPostgres(cfg) -> bool:
try:
conn = psycopg2.connect(
host=cfg["host"],
port=cfg["port"],
database="postgres",
user=cfg["user"],
password=cfg["password"],
connect_timeout=3,
)
conn.close()
return True
except Exception: # noqa: BLE001
return False
def _rbacDbSkipReason() -> str:
cfg = _dbConfig()
if cfg is None:
return "No PostgreSQL credentials in APP_CONFIG — skipping RBAC DB integration tests"
if not _canReachPostgres(cfg):
return (
f"PostgreSQL not reachable at {cfg['host']}:{cfg['port']} "
"(CI runner / firewall — skipping RBAC DB integration tests)"
)
return ""
_RBAC_DB_SKIP = _rbacDbSkipReason()
_DB_CFG = None if _RBAC_DB_SKIP else _dbConfig()
pytestmark = pytest.mark.skipif(
_DB_CFG is None,
reason="No PostgreSQL credentials in APP_CONFIG — skipping RBAC DB integration tests",
bool(_RBAC_DB_SKIP),
reason=_RBAC_DB_SKIP,
)