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
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-23 11:36:20 +01:00
parent 541eb04351
commit 65e26014e3
14 changed files with 325 additions and 95 deletions

View File

@@ -2,37 +2,71 @@ PYTHON ?= python3
COMPOSE_FILE := tests/e2e/docker-compose.yml
COMPOSE := docker compose -f $(COMPOSE_FILE)
.PHONY: help e2e-up e2e-install e2e-test e2e-down e2e logs clean
VENV_DIR := .venv
VENV_PY := $(VENV_DIR)/bin/python
VENV_PIP := $(VENV_DIR)/bin/pip
# E2E defaults (override like: make e2e MATOMO_URL=http://127.0.0.1:8081)
MATOMO_URL ?= http://127.0.0.1:8080
MATOMO_ADMIN_USER ?= administrator
MATOMO_ADMIN_PASSWORD ?= AdminSecret123!
MATOMO_ADMIN_EMAIL ?= administrator@example.org
MATOMO_TOKEN_DESCRIPTION ?= e2e-make-token
.PHONY: help venv deps-e2e playwright-install e2e-up e2e-install e2e-test e2e-down e2e logs clean
help:
@echo "Targets:"
@echo " e2e-up Start Matomo + DB for E2E tests"
@echo " e2e-install Run Matomo installation (product code)"
@echo " e2e-test Run E2E tests (unittest)"
@echo " e2e-down Stop and remove E2E containers"
@echo " e2e Full cycle: up → install → test → down"
@echo " logs Show Matomo logs"
@echo " venv Create local venv in $(VENV_DIR)"
@echo " deps-e2e Install package + E2E deps into venv"
@echo " playwright-install Install Chromium for Playwright (inside venv)"
@echo " e2e-up Start Matomo + DB for E2E tests"
@echo " e2e-install Run Matomo bootstrap (product code)"
@echo " e2e-test Run E2E tests (unittest)"
@echo " e2e-down Stop and remove E2E containers"
@echo " e2e Full cycle: up → install → test → down"
@echo " logs Show Matomo logs"
@echo " clean Stop containers + remove venv"
@echo ""
@echo "Variables (override like: make e2e MATOMO_URL=http://127.0.0.1:8081):"
@echo " MATOMO_URL, MATOMO_ADMIN_USER, MATOMO_ADMIN_PASSWORD, MATOMO_ADMIN_EMAIL, MATOMO_TOKEN_DESCRIPTION"
venv:
@test -x "$(VENV_PY)" || ($(PYTHON) -m venv $(VENV_DIR))
@$(VENV_PIP) -q install -U pip setuptools wheel >/dev/null
deps-e2e: venv
@$(VENV_PIP) install -e ".[e2e]"
playwright-install: deps-e2e
@$(VENV_PY) -m playwright install chromium
e2e-up:
$(COMPOSE) up -d
@echo "Waiting for Matomo to answer on http://127.0.0.1:8080/ ..."
@echo "Waiting for Matomo to answer (any HTTP code) on $(MATOMO_URL)/ ..."
@for i in $$(seq 1 180); do \
if curl -fsS --max-time 2 http://127.0.0.1:8080/ >/dev/null 2>&1; then \
echo "Matomo is reachable."; \
code=$$(curl -sS -o /dev/null -w "%{http_code}" --max-time 2 "$(MATOMO_URL)/" || true); \
if [ "$$code" != "000" ]; then \
echo "Matomo answered with HTTP $$code."; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Matomo did not become reachable on host port 8080."; \
echo "Matomo did not answer on $(MATOMO_URL)"; \
$(COMPOSE) ps; \
$(COMPOSE) logs --no-color --tail=200 matomo; \
exit 1
e2e-install:
PYTHONPATH=src $(PYTHON) -m matomo_bootstrap.install.web_installer
e2e-install: playwright-install
MATOMO_URL="$(MATOMO_URL)" \
MATOMO_ADMIN_USER="$(MATOMO_ADMIN_USER)" \
MATOMO_ADMIN_PASSWORD="$(MATOMO_ADMIN_PASSWORD)" \
MATOMO_ADMIN_EMAIL="$(MATOMO_ADMIN_EMAIL)" \
MATOMO_TOKEN_DESCRIPTION="$(MATOMO_TOKEN_DESCRIPTION)" \
PYTHONPATH=src $(VENV_PY) -m matomo_bootstrap
e2e-test:
PYTHONPATH=src $(PYTHON) -m unittest discover -s tests/e2e -v
e2e-test: deps-e2e
PYTHONPATH=src $(VENV_PY) -m unittest discover -s tests/e2e -v
e2e-down:
$(COMPOSE) down -v
@@ -43,3 +77,4 @@ logs:
$(COMPOSE) logs -f matomo
clean: e2e-down
rm -rf $(VENV_DIR)