mirror of
https://github.com/PRVTPRO/Amnezia-Web-Panel.git
synced 2026-09-18 01:44:10 +02:00
e537823184
tests/test_playwright_e2e.py starts with a bare `import pytest`, but pytest is not in requirements.txt - only playwright is. CI installs requirements.txt and runs `python -m unittest discover -s tests`, which imports every module under tests/, so collection aborts on that import and the whole suite fails. `main` has been red since the module landed: the runs for #134, the v1.6.4 tag and the follow-up commit all report `FAILED (errors=1)` with `ModuleNotFoundError: No module named 'pytest'`, and none of the 152 real unit tests are reported. The import is now guarded and raises unittest.SkipTest, so `unittest discover` skips the module and keeps running the rest. Nothing changes for pytest users: with pytest installed the import succeeds and `pytest tests/test_playwright_e2e.py` behaves exactly as before. The module docstring now also says it expects a panel already serving on BASE_URL. An alternative would be adding pytest to requirements.txt, but that pulls a test runner into the runtime dependencies of the panel, and `unittest discover` still would not run these tests - they are pytest fixtures and plain classes, not unittest.TestCase. Before: Ran 152 tests ... FAILED (errors=1) After: Ran 152 tests ... OK (skipped=1) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
"""Playwright E2E tests for Amnezia Web Panel.
|
|
|
|
Run with pytest against a panel already serving on BASE_URL. `unittest
|
|
discover` imports every tests/ module, and pytest is not in requirements.txt,
|
|
so the import is guarded: without it the module skips instead of failing the
|
|
whole suite.
|
|
"""
|
|
import unittest
|
|
|
|
try:
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
except ImportError as exc: # pragma: no cover - depends on the environment
|
|
raise unittest.SkipTest(f"Playwright e2e tests need pytest: {exc}")
|
|
|
|
BASE_URL = "http://127.0.0.1:8000"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def base_url():
|
|
return BASE_URL
|
|
|
|
|
|
class TestLoginPage:
|
|
def test_login_page_loads(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page).to_have_url(f"{BASE_URL}/login")
|
|
expect(page).to_have_title("Amnezia — Login")
|
|
|
|
def test_login_page_has_username_field(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('#username')).to_be_visible()
|
|
|
|
def test_login_page_has_password_field(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('#password')).to_be_visible()
|
|
|
|
def test_login_page_has_login_button(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('button[type="submit"]')).to_be_visible()
|
|
|
|
def test_login_page_has_logo(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('.login-logo')).to_be_visible()
|
|
|
|
def test_login_page_has_theme_toggle(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('#themeToggle')).to_be_visible()
|
|
|
|
def test_login_page_has_language_toggle(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('#langToggle')).to_be_visible()
|
|
|
|
def test_login_form_structure(self, page: Page):
|
|
page.goto(BASE_URL)
|
|
expect(page.locator('#loginForm')).to_be_visible()
|
|
expect(page.locator('.login-card')).to_be_visible()
|
|
|
|
|
|
class TestDashboard:
|
|
def test_dashboard_requires_auth(self, page: Page):
|
|
page.goto(f"{BASE_URL}/")
|
|
expect(page).to_have_url(f"{BASE_URL}/login")
|
|
|
|
class TestAPI:
|
|
def test_openapi_json_available(self, page: Page):
|
|
response = page.request.get(f"{BASE_URL}/openapi.json")
|
|
assert response.status == 200
|
|
body = response.json()
|
|
assert "paths" in body
|
|
assert "info" in body
|
|
|
|
def test_static_files_served(self, page: Page):
|
|
response = page.request.get(f"{BASE_URL}/static/js/searchable-select.js")
|
|
assert response.status == 200
|
|
|
|
def test_favicon_served(self, page: Page):
|
|
response = page.request.get(f"{BASE_URL}/static/favicon.svg")
|
|
assert response.status == 200
|
|
|
|
def test_manifest_served(self, page: Page):
|
|
response = page.request.get(f"{BASE_URL}/manifest.webmanifest")
|
|
assert response.status == 200
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__, "-v", "--headed", "--browser", "chromium"])
|