Files
matomo-bootstrap/tests/e2e/test_bootstrap.py
Kevin Veen-Birkenbach 65e26014e3 test(e2e): add venv + playwright deps and robust Matomo API auth flow
- Add optional dependency group "e2e" with Playwright in pyproject.toml
- Teach Makefile to create/use local .venv, install e2e deps, and fetch Chromium
- Wait for Matomo HTTP response (any status) before running bootstrap
- Switch API calls to /index.php and add HttpClient.get()
- Use UsersManager.getTokenAuth (md5Password) to obtain token_auth for privileged calls
- Make web installer more resilient to HTTPError/500 and locale/button variations
- Update E2E test to pass admin email and call API via /index.php

https://chatgpt.com/share/694a70b0-e520-800f-a3e4-eaf5e96530bd
2025-12-23 11:36:20 +01:00

48 lines
1.4 KiB
Python

import json
import os
import subprocess
import unittest
import urllib.request
MATOMO_URL = os.environ.get("MATOMO_URL", "http://127.0.0.1:8080")
ADMIN_USER = os.environ.get("MATOMO_ADMIN_USER", "administrator")
ADMIN_PASSWORD = os.environ.get("MATOMO_ADMIN_PASSWORD", "AdminSecret123!")
ADMIN_EMAIL = os.environ.get("MATOMO_ADMIN_EMAIL", "administrator@example.org")
class TestMatomoBootstrapE2E(unittest.TestCase):
def test_bootstrap_creates_api_token(self) -> None:
cmd = [
"python3",
"-m",
"matomo_bootstrap",
"--base-url",
MATOMO_URL,
"--admin-user",
ADMIN_USER,
"--admin-password",
ADMIN_PASSWORD,
"--admin-email",
ADMIN_EMAIL,
"--token-description",
"e2e-test-token",
]
token = subprocess.check_output(
cmd,
env={**os.environ, "PYTHONPATH": "src"},
).decode().strip()
self.assertRegex(token, r"^[a-f0-9]{32,64}$", f"Expected token_auth, got: {token}")
api_url = (
f"{MATOMO_URL}/index.php"
f"?module=API&method=SitesManager.getSitesWithAtLeastViewAccess"
f"&format=json&token_auth={token}"
)
with urllib.request.urlopen(api_url, timeout=10) as resp:
data = json.loads(resp.read().decode())
self.assertIsInstance(data, list)