- test_requirements: replace removed add_import_order with upsert_order + add_sync_run_order, fix add_order_items/update_addresses signatures - E2E logs: replace #runsTableBody with #runsDropdown (dropdown UI) - E2E mappings: rewrite for flat-row list design (no more table headers) - E2E missing_skus: use .filter-pill[data-sku-status] instead of button IDs, #quickMapModal instead of #mapModal - QA logs monitor: 1h session window + known issues filter for pre-existing ORA-00942 errors - Oracle integration: force-update settings singleton to override dummy values from test_requirements module, fix TNS_ADMIN directory in conftest - PL/SQL tests: graceful skip when PARTENERI table inaccessible All 6 test stages now pass in ./test.sh full. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
109 lines
3.3 KiB
Python
109 lines
3.3 KiB
Python
"""
|
|
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)")
|
|
|
|
# TNS_ADMIN must point to the directory containing tnsnames.ora, not the file
|
|
tns_admin = os.environ.get("TNS_ADMIN", "")
|
|
if tns_admin and os.path.isfile(tns_admin):
|
|
os.environ["TNS_ADMIN"] = os.path.dirname(tns_admin)
|
|
elif not tns_admin:
|
|
# Default to api/ directory which contains tnsnames.ora
|
|
os.environ["TNS_ADMIN"] = str(Path(__file__).parents[2])
|
|
|
|
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}")
|