Skip to content

Commit

Permalink
Setup playwright and implement login test
Browse files Browse the repository at this point in the history
  • Loading branch information
deen13 committed Jun 25, 2024
1 parent 3f3a2fb commit 0cb1eb3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ jobs:
test:
docker:
- image: cimg/python:3.11.7
environment:
DJANGO_ALLOW_ASYNC_UNSAFE: True
- image: cimg/postgres:14.1
environment:
POSTGRES_USER: integreat
Expand All @@ -298,6 +300,9 @@ jobs:
- run:
name: Enable virtual environment
command: echo "source .venv/bin/activate" >> $BASH_ENV
- run:
name: Install playwright dependencies
command: playwright install --with-deps
- run:
name: Migrate database
command: integreat-cms-cli migrate --settings=integreat_cms.core.circleci_settings
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ dev = [
"types-python-dateutil",
"types-PyYAML",
"types-requests",
"pytest-playwright",
"playwright"
]
pinned = [
"aiohttp==3.9.5",
Expand Down Expand Up @@ -330,6 +332,8 @@ dev-pinned = [
"virtualenv==20.26.2",
"Werkzeug==3.0.3",
"zipp==3.19.2",
"pytest-playwright==0.5.0",
"playwright==1.44.0"
]

[project.urls]
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test.client import AsyncClient, Client
from playwright.sync_api import Page
from pytest_django.live_server_helper import LiveServer
from pytest_httpserver.httpserver import HTTPServer

from integreat_cms.cms.constants.roles import (
Expand All @@ -31,7 +33,6 @@
from _pytest.fixtures import SubRequest
from pytest_django.plugin import _DatabaseBlocker # type: ignore[attr-defined]


#: A role identifier for superusers
ROOT: Final = "ROOT"
#: A role identifier for anonymous users
Expand Down Expand Up @@ -132,3 +133,9 @@ def login_role_user_async(
@pytest.fixture(scope="function")
def mock_server(httpserver: HTTPServer) -> MockServer:
return MockServer(httpserver)


@pytest.fixture()
def test_server(page: Page, live_server: LiveServer, load_test_data: None) -> Page:
page.goto(live_server.url)
return page
3 changes: 3 additions & 0 deletions tests/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
This package contains tests of the :mod:`integreat_cms` app
"""
13 changes: 13 additions & 0 deletions tests/ui/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from playwright.sync_api import expect, Page
from pytest_django.live_server_helper import LiveServer


def test_login(page: Page, test_server: LiveServer) -> None:
page.goto(test_server.url)

page.fill("input[name='username']", "root")
page.fill("input[type='password']", "root1234")

page.get_by_text("Anmelden").click()

expect(page.get_by_role("heading", name="Admin Dashboard")).to_be_visible()
2 changes: 2 additions & 0 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export INTEGREAT_CMS_LINKCHECK_DISABLE_LISTENERS=1
# Disable background tasks during testing
export INTEGREAT_CMS_BACKGROUND_TASKS_ENABLED=0

export DJANGO_ALLOW_ASYNC_UNSAFE="True"

TESTS=()

# Parse given command line arguments
Expand Down

0 comments on commit 0cb1eb3

Please sign in to comment.