chore: import upstream snapshot with attribution
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:08:55 +08:00
commit 7a0da7932b
2985 changed files with 1049377 additions and 0 deletions
+98
View File
@@ -0,0 +1,98 @@
"""
Pytest configuration and shared fixtures for API tests
"""
import json
import subprocess
import uuid
import pytest
import requests
from pathlib import Path
import tempfile
import os
# Base URL for tests
BASE_URL = os.environ.get("LDR_TEST_BASE_URL", "http://127.0.0.1:5000")
# Use UUID for unique usernames to avoid collisions in parallel tests
TEST_USERNAME = f"testuser_{uuid.uuid4().hex[:12]}"
TEST_PASSWORD = "TestPass123"
class AuthHelper:
"""Helper class to handle Puppeteer authentication"""
@staticmethod
def get_auth_cookies():
"""Use Puppeteer to authenticate and get cookies"""
# Create a temporary file for cookie storage
cookie_file = tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
)
cookie_file.close()
# Run the Node.js auth helper. The JS file still lives under
# tests/api_tests_with_login/ — it's shared with other Puppeteer
# suites, so we reference it in place rather than duplicate.
auth_script = (
Path(__file__).parents[2]
/ "api_tests_with_login"
/ "auth_helper.js"
)
cmd = [
"node",
str(auth_script),
BASE_URL,
TEST_USERNAME,
TEST_PASSWORD,
cookie_file.name,
]
try:
result = subprocess.run(
cmd, capture_output=True, text=True, timeout=90
)
if result.returncode != 0:
raise Exception(f"Auth failed: {result.stderr}")
# Read cookies from file
with open(cookie_file.name, "r") as f:
cookies = json.load(f)
# Convert to requests format
cookie_dict = {c["name"]: c["value"] for c in cookies}
# Extract CSRF token
csrf_token = None
for cookie in cookies:
if cookie["name"] == "csrf_token":
csrf_token = cookie["value"]
break
return cookie_dict, csrf_token
finally:
# Clean up temp file
if Path(cookie_file.name).exists():
os.unlink(cookie_file.name)
@pytest.fixture(scope="session")
def auth_session():
"""Session-wide fixture for authenticated requests"""
cookies, csrf_token = AuthHelper.get_auth_cookies()
session = requests.Session()
session.cookies.update(cookies)
session.headers.update(
{"X-CSRFToken": csrf_token, "Accept": "application/json"}
)
yield session, csrf_token
session.close()
@pytest.fixture
def base_url():
"""Fixture to provide base URL"""
return BASE_URL