feat: add CI/CD testing infrastructure with test.sh orchestrator
Complete testing system: pyproject.toml (pytest markers), test.sh orchestrator with auto app start/stop and colorful summary, pre-push hook, Gitea Actions workflow. New QA tests: API health (7 endpoints), responsive (3 viewports), log monitoring (ERROR/ORA-/Traceback detection), real GoMag sync, PL/SQL package validation, smoke prod (read-only). Converted test_app_basic.py and test_integration.py to pytest. Added pytestmark to all existing tests (unit/e2e/oracle). E2E conftest upgraded: console error collector, screenshot on failure, auto-detect live app on :5003. Usage: ./test.sh ci (30s) | ./test.sh full (2-3min) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
100
api/tests/qa/conftest.py
Normal file
100
api/tests/qa/conftest.py
Normal file
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
QA test fixtures — shared across api_health, responsive, smoke_prod, logs_monitor,
|
||||
sync_real, plsql tests.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# Add api/ to path
|
||||
_api_dir = str(Path(__file__).parents[2])
|
||||
if _api_dir not in sys.path:
|
||||
sys.path.insert(0, _api_dir)
|
||||
|
||||
# Directories
|
||||
PROJECT_ROOT = Path(__file__).parents[3]
|
||||
QA_REPORTS_DIR = PROJECT_ROOT / "qa-reports"
|
||||
SCREENSHOTS_DIR = QA_REPORTS_DIR / "screenshots"
|
||||
LOGS_DIR = PROJECT_ROOT / "logs"
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
# --base-url is already provided by pytest-playwright; we reuse it
|
||||
# Use try/except to avoid conflicts when conftest is loaded alongside other plugins
|
||||
try:
|
||||
parser.addoption("--env", default="test", choices=["test", "prod"], help="QA environment")
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
parser.addoption("--qa-log-file", default=None, help="Specific log file to check")
|
||||
except (ValueError, Exception):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def base_url(request):
|
||||
"""Reuse pytest-playwright's --base-url or default to localhost:5003."""
|
||||
url = request.config.getoption("--base-url") or "http://localhost:5003"
|
||||
return url.rstrip("/")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def env_name(request):
|
||||
return request.config.getoption("--env")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def qa_issues():
|
||||
"""Collect issues across all QA tests for the final report."""
|
||||
return []
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def screenshots_dir():
|
||||
SCREENSHOTS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
return SCREENSHOTS_DIR
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def app_log_path(request):
|
||||
"""Return the most recent log file from logs/."""
|
||||
custom = request.config.getoption("--qa-log-file", default=None)
|
||||
if custom:
|
||||
return Path(custom)
|
||||
|
||||
if not LOGS_DIR.exists():
|
||||
return None
|
||||
|
||||
logs = sorted(LOGS_DIR.glob("sync_comenzi_*.log"), key=lambda p: p.stat().st_mtime, reverse=True)
|
||||
return logs[0] if logs else None
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def oracle_connection():
|
||||
"""Create a direct Oracle connection for PL/SQL and sync tests."""
|
||||
from dotenv import load_dotenv
|
||||
env_path = Path(__file__).parents[2] / ".env"
|
||||
load_dotenv(str(env_path), override=True)
|
||||
|
||||
user = os.environ.get("ORACLE_USER", "")
|
||||
password = os.environ.get("ORACLE_PASSWORD", "")
|
||||
dsn = os.environ.get("ORACLE_DSN", "")
|
||||
|
||||
if not all([user, password, dsn]) or user == "dummy":
|
||||
pytest.skip("Oracle not configured (ORACLE_USER/PASSWORD/DSN missing or dummy)")
|
||||
|
||||
import oracledb
|
||||
conn = oracledb.connect(user=user, password=password, dsn=dsn)
|
||||
yield conn
|
||||
conn.close()
|
||||
|
||||
|
||||
def pytest_sessionfinish(session, exitstatus):
|
||||
"""Generate QA report at end of session."""
|
||||
try:
|
||||
from . import qa_report
|
||||
qa_report.generate(session, QA_REPORTS_DIR)
|
||||
except Exception as e:
|
||||
print(f"\n[qa_report] Failed to generate report: {e}")
|
||||
Reference in New Issue
Block a user