Fix tests with playwright

Basically:
- when using playwright, we use live_server
- live_server make django-pytest switch in "transactional db" mode
- when in this mode, it will reset all data of all tables in db
- we relied on data created during the migrations, so only available
  for first test run
This commit is contained in:
Yohan Boniface 2023-09-04 15:04:00 +02:00
parent 1975b93ad8
commit 3a5174c003
2 changed files with 10 additions and 6 deletions

View file

@ -5,8 +5,13 @@ import pytest
from django.core.cache import cache
from django.core.signing import get_cookie_signer
from .base import DataLayerFactory, MapFactory, UserFactory
from umap.models import Licence, TileLayer
from .base import (
DataLayerFactory,
MapFactory,
UserFactory,
TileLayerFactory,
LicenceFactory,
)
TMP_ROOT = tempfile.mkdtemp()
@ -37,8 +42,7 @@ def user2():
@pytest.fixture
def licence():
# Should be created by the migrations.
return Licence.objects.last()
return LicenceFactory()
@pytest.fixture
@ -73,4 +77,4 @@ def datalayer(map):
@pytest.fixture
def tilelayer():
return TileLayer.objects.last()
return TileLayerFactory()

View file

@ -18,7 +18,7 @@ def test_create_map_link(page, live_server, lang, link_name, link_url):
expect(create_map_button).to_have_attribute("href", link_url)
def test_create_map_with_cursor(page, live_server):
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.