Merge pull request #1069 from umap-project/playwright-integration-tests
Setup to create integration tests with Playwright
This commit is contained in:
commit
2152ca3d1a
6 changed files with 68 additions and 7 deletions
6
Makefile
6
Makefile
|
@ -8,6 +8,7 @@ install: ## Install the dependencies
|
||||||
.PHONY: develop
|
.PHONY: develop
|
||||||
develop: ## Install the test and dev dependencies
|
develop: ## Install the test and dev dependencies
|
||||||
python3 -m pip install -e .[test,dev]
|
python3 -m pip install -e .[test,dev]
|
||||||
|
playwright install
|
||||||
|
|
||||||
.PHONY: pretty-templates
|
.PHONY: pretty-templates
|
||||||
pretty-templates: ## Prettify template files
|
pretty-templates: ## Prettify template files
|
||||||
|
@ -45,9 +46,12 @@ publish: ## Publish the Python package to Pypi
|
||||||
@hatch publish
|
@hatch publish
|
||||||
make clean
|
make clean
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
py.test -xv umap/tests/
|
py.test -xv umap/tests/
|
||||||
|
|
||||||
|
test-integration:
|
||||||
|
py.test -xv umap/tests/integration/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f dist/*
|
rm -f dist/*
|
||||||
rm -rf build/*
|
rm -rf build/*
|
||||||
|
|
|
@ -52,8 +52,11 @@ dev = [
|
||||||
]
|
]
|
||||||
test = [
|
test = [
|
||||||
"factory-boy==3.2.1",
|
"factory-boy==3.2.1",
|
||||||
|
"playwright==1.37.0",
|
||||||
"pytest==6.2.5",
|
"pytest==6.2.5",
|
||||||
"pytest-django==4.5.2",
|
"pytest-django==4.5.2",
|
||||||
|
"pytest-playwright==0.4.2",
|
||||||
|
|
||||||
]
|
]
|
||||||
docker = [
|
docker = [
|
||||||
"uwsgi==2.0.21",
|
"uwsgi==2.0.21",
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE=umap.tests.settings
|
DJANGO_SETTINGS_MODULE=umap.tests.settings
|
||||||
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
|
addopts = "--pdbcls=IPython.terminal.debugger:Pdb --no-migrations"
|
||||||
|
|
|
@ -5,8 +5,13 @@ import pytest
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.signing import get_cookie_signer
|
from django.core.signing import get_cookie_signer
|
||||||
|
|
||||||
from .base import DataLayerFactory, MapFactory, UserFactory
|
from .base import (
|
||||||
from umap.models import Licence, TileLayer
|
DataLayerFactory,
|
||||||
|
MapFactory,
|
||||||
|
UserFactory,
|
||||||
|
TileLayerFactory,
|
||||||
|
LicenceFactory,
|
||||||
|
)
|
||||||
|
|
||||||
TMP_ROOT = tempfile.mkdtemp()
|
TMP_ROOT = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
@ -37,8 +42,7 @@ def user2():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def licence():
|
def licence():
|
||||||
# Should be created by the migrations.
|
return LicenceFactory()
|
||||||
return Licence.objects.last()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -73,4 +77,4 @@ def datalayer(map):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def tilelayer():
|
def tilelayer():
|
||||||
return TileLayer.objects.last()
|
return TileLayerFactory()
|
||||||
|
|
3
umap/tests/integration/__init__.py
Normal file
3
umap/tests/integration/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "1"
|
47
umap/tests/integration/test_basics.py
Normal file
47
umap/tests/integration/test_basics.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import pytest
|
||||||
|
from playwright.sync_api import expect
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_title(page, live_server):
|
||||||
|
page.goto(live_server.url)
|
||||||
|
expect(page).to_have_title("uMap")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"lang,link_name,link_url",
|
||||||
|
[("fr", "Créer une carte", "/fr/map/new/"), ("en", "Create a map", "/en/map/new/")],
|
||||||
|
)
|
||||||
|
def test_create_map_link(page, live_server, lang, link_name, link_url):
|
||||||
|
page.goto(f"{live_server.url}/{lang}/")
|
||||||
|
create_map_button = page.locator("header nav a.button")
|
||||||
|
expect(create_map_button).to_have_text(link_name)
|
||||||
|
expect(create_map_button).to_have_attribute("href", link_url)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_map_with_cursor(page, live_server, tilelayer):
|
||||||
|
page.goto(f"{live_server.url}/en/map/new/")
|
||||||
|
|
||||||
|
# Click on the Draw a marker button on a new map.
|
||||||
|
create_marker_link = page.locator(".leaflet-control-toolbar ").get_by_title(
|
||||||
|
"Draw a marker"
|
||||||
|
)
|
||||||
|
expect(create_marker_link).to_have_attribute("href", "#")
|
||||||
|
create_marker_link.click()
|
||||||
|
|
||||||
|
# Check no marker is present by default.
|
||||||
|
marker_pane_children = page.locator(".leaflet-marker-pane > div")
|
||||||
|
expect(marker_pane_children).to_have_count(0)
|
||||||
|
|
||||||
|
# Click on the map, it will place a marker at the given position.
|
||||||
|
map = page.locator("#map")
|
||||||
|
map.click(position={"x": 200, "y": 200})
|
||||||
|
expect(marker_pane_children).to_have_count(1)
|
||||||
|
expect(marker_pane_children).to_have_attribute(
|
||||||
|
"style",
|
||||||
|
(
|
||||||
|
"margin-left: -16px; "
|
||||||
|
"margin-top: -40px; "
|
||||||
|
"transform: translate3d(200px, 200px, 0px); "
|
||||||
|
"z-index: 200;"
|
||||||
|
),
|
||||||
|
)
|
Loading…
Reference in a new issue