diff --git a/umap/tests/conftest.py b/umap/tests/conftest.py index 78e207cb..4dafa3dd 100644 --- a/umap/tests/conftest.py +++ b/umap/tests/conftest.py @@ -5,6 +5,8 @@ import pytest from django.core.cache import cache from django.core.signing import get_cookie_signer +from umap.models import Map + from .base import ( DataLayerFactory, LicenceFactory, @@ -48,6 +50,13 @@ def map(licence, tilelayer): return MapFactory(owner=user, licence=licence) +@pytest.fixture +def openmap(map): + map.edit_status = Map.ANONYMOUS + map.save() + return map + + @pytest.fixture def anonymap(map): map.owner = None diff --git a/umap/tests/integration/test_browser.py b/umap/tests/integration/test_browser.py index 8a73c007..41d89584 100644 --- a/umap/tests/integration/test_browser.py +++ b/umap/tests/integration/test_browser.py @@ -4,8 +4,6 @@ from time import sleep import pytest from playwright.sync_api import expect -from umap.models import Map - from ..base import DataLayerFactory pytestmark = pytest.mark.django_db @@ -247,10 +245,8 @@ def test_should_sort_features_in_natural_order(live_server, map, page): expect(features.nth(2)).to_have_text("100. a line") -def test_should_redraw_list_on_feature_delete(live_server, map, page, bootstrap): - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}") +def test_should_redraw_list_on_feature_delete(live_server, openmap, page, bootstrap): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") # Enable edit page.get_by_role("button", name="Edit").click() buttons = page.locator(".umap-browse-data li .feature-delete") @@ -305,11 +301,8 @@ def test_should_allow_to_toggle_datalayer_visibility(live_server, map, page, boo expect(paths).to_have_count(0) -def test_should_have_edit_buttons_in_edit_mode(live_server, map, page, bootstrap): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}") +def test_should_have_edit_buttons_in_edit_mode(live_server, openmap, page, bootstrap): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") browser = page.locator("#umap-ui-container") edit_layer = browser.get_by_title("Edit", exact=True) in_table = browser.get_by_title("Edit properties in a table") diff --git a/umap/tests/integration/test_choropleth.py b/umap/tests/integration/test_choropleth.py index 7b5cdeab..baed5e71 100644 --- a/umap/tests/integration/test_choropleth.py +++ b/umap/tests/integration/test_choropleth.py @@ -4,8 +4,6 @@ from pathlib import Path import pytest from playwright.sync_api import expect -from umap.models import Map - from ..base import DataLayerFactory pytestmark = pytest.mark.django_db @@ -28,19 +26,15 @@ def test_basic_choropleth_map_with_default_color(map, live_server, page): expect(page.locator("path[fill='#eff3ff']")).to_have_count(3) -def test_basic_choropleth_map_with_custom_brewer(map, live_server, page): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - +def test_basic_choropleth_map_with_custom_brewer(openmap, live_server, page): path = Path(__file__).parent.parent / "fixtures/choropleth_region_chomage.geojson" data = json.loads(path.read_text()) # Change brewer at load data["_umap_options"]["choropleth"]["brewer"] = "Reds" - DataLayerFactory(data=data, map=map) + DataLayerFactory(data=data, map=openmap) - page.goto(f"{live_server.url}{map.get_absolute_url()}") + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") # Hauts-de-France expect(page.locator("path[fill='#a50f15']")).to_have_count(1) # Occitanie @@ -71,19 +65,15 @@ def test_basic_choropleth_map_with_custom_brewer(map, live_server, page): expect(page.locator("path[fill='#edf8e9']")).to_have_count(3) -def test_basic_choropleth_map_with_custom_classes(map, live_server, page): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - +def test_basic_choropleth_map_with_custom_classes(openmap, live_server, page): path = Path(__file__).parent.parent / "fixtures/choropleth_region_chomage.geojson" data = json.loads(path.read_text()) # Change brewer at load data["_umap_options"]["choropleth"]["classes"] = 6 - DataLayerFactory(data=data, map=map) + DataLayerFactory(data=data, map=openmap) - page.goto(f"{live_server.url}{map.get_absolute_url()}") + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") # Hauts-de-France expect(page.locator("path[fill='#08519c']")).to_have_count(1) diff --git a/umap/tests/integration/test_collaborative_editing.py b/umap/tests/integration/test_collaborative_editing.py index 35e655b2..d441c68e 100644 --- a/umap/tests/integration/test_collaborative_editing.py +++ b/umap/tests/integration/test_collaborative_editing.py @@ -269,15 +269,12 @@ def test_same_second_edit_doesnt_conflict(context, live_server, tilelayer): } -def test_should_display_alert_on_conflict(context, live_server, datalayer, map): - map.edit_status = Map.ANONYMOUS - map.save() - +def test_should_display_alert_on_conflict(context, live_server, datalayer, openmap): # Open the map on two pages. page_one = context.new_page() - page_one.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + page_one.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") page_two = context.new_page() - page_two.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + page_two.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") page_one.locator(".leaflet-marker-icon").click(modifiers=["Shift"]) page_one.locator('input[name="name"]').fill("new name") diff --git a/umap/tests/integration/test_edit_datalayer.py b/umap/tests/integration/test_edit_datalayer.py index 67a3de89..1198b539 100644 --- a/umap/tests/integration/test_edit_datalayer.py +++ b/umap/tests/integration/test_edit_datalayer.py @@ -2,7 +2,7 @@ import re from playwright.sync_api import expect -from umap.models import DataLayer, Map +from umap.models import DataLayer from ..base import DataLayerFactory @@ -53,12 +53,9 @@ def test_should_have_fieldset_for_layer_type_properties(page, live_server, tilel def test_cancel_deleting_datalayer_should_restore( - live_server, map, login, datalayer, page + live_server, openmap, datalayer, page ): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") layers = page.locator(".umap-browse-datalayers li") markers = page.locator(".leaflet-marker-icon") expect(layers).to_have_count(1) @@ -77,11 +74,8 @@ def test_cancel_deleting_datalayer_should_restore( ).to_be_visible() -def test_can_clone_datalayer(live_server, map, login, datalayer, page): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_clone_datalayer(live_server, openmap, login, datalayer, page): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") layers = page.locator(".umap-browse-datalayers li") markers = page.locator(".leaflet-marker-icon") expect(layers).to_have_count(1) @@ -94,7 +88,7 @@ def test_can_clone_datalayer(live_server, map, login, datalayer, page): expect(markers).to_have_count(2) -def test_can_change_icon_class(live_server, map, page): +def test_can_change_icon_class(live_server, openmap, page): # Faster than doing a login data = { "type": "FeatureCollection", @@ -106,10 +100,8 @@ def test_can_change_icon_class(live_server, map, page): }, ], } - DataLayerFactory(map=map, data=data) - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + DataLayerFactory(map=openmap, data=data) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") expect(page.locator(".umap-div-icon")).to_be_visible() page.get_by_role("link", name="Manage layers").click() expect(page.locator(".umap-circle-icon")).to_be_hidden() @@ -121,11 +113,9 @@ def test_can_change_icon_class(live_server, map, page): expect(page.locator(".umap-div-icon")).to_be_hidden() -def test_can_change_name(live_server, map, page, datalayer): - map.edit_status = Map.ANONYMOUS - map.save() +def test_can_change_name(live_server, openmap, page, datalayer): page.goto( - f"{live_server.url}{map.get_absolute_url()}?edit&datalayersControl=expanded" + f"{live_server.url}{openmap.get_absolute_url()}?edit&datalayersControl=expanded" ) page.get_by_role("link", name="Manage layers").click() page.locator("#umap-ui-container").get_by_title("Edit", exact=True).click() @@ -142,11 +132,9 @@ def test_can_change_name(live_server, map, page, datalayer): expect(page.locator(".umap-is-dirty")).to_be_hidden() -def test_can_create_new_datalayer(live_server, map, page, datalayer): - map.edit_status = Map.ANONYMOUS - map.save() +def test_can_create_new_datalayer(live_server, openmap, page, datalayer): page.goto( - f"{live_server.url}{map.get_absolute_url()}?edit&datalayersControl=expanded" + f"{live_server.url}{openmap.get_absolute_url()}?edit&datalayersControl=expanded" ) page.get_by_role("link", name="Manage layers").click() page.get_by_role("button", name="Add a layer").click() @@ -174,10 +162,8 @@ def test_can_create_new_datalayer(live_server, map, page, datalayer): expect(page.locator(".umap-is-dirty")).to_be_hidden() -def test_can_restore_version(live_server, map, page, datalayer): - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_restore_version(live_server, openmap, page, datalayer): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".leaflet-marker-icon") expect(marker).to_have_class(re.compile(".*umap-ball-icon.*")) marker.click(modifiers=["Shift"]) diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py index a8852c4d..7c278342 100644 --- a/umap/tests/integration/test_import.py +++ b/umap/tests/integration/test_import.py @@ -5,7 +5,7 @@ from pathlib import Path import pytest from playwright.sync_api import expect -from umap.models import DataLayer, Map +from umap.models import DataLayer pytestmark = pytest.mark.django_db @@ -175,11 +175,8 @@ def test_import_csv_from_textarea(tilelayer, live_server, page): expect(markers).to_have_count(2) -def test_can_import_in_existing_datalayer(live_server, datalayer, page, map): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}") +def test_can_import_in_existing_datalayer(live_server, datalayer, page, openmap): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") layers = page.locator(".umap-browse-datalayers li") markers = page.locator(".leaflet-marker-icon") expect(markers).to_have_count(1) @@ -196,11 +193,8 @@ def test_can_import_in_existing_datalayer(live_server, datalayer, page, map): expect(markers).to_have_count(3) -def test_can_replace_datalayer_data(live_server, datalayer, page, map): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}") +def test_can_replace_datalayer_data(live_server, datalayer, page, openmap): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") layers = page.locator(".umap-browse-datalayers li") markers = page.locator(".leaflet-marker-icon") expect(markers).to_have_count(1) @@ -218,11 +212,8 @@ def test_can_replace_datalayer_data(live_server, datalayer, page, map): expect(markers).to_have_count(2) -def test_can_import_in_new_datalayer(live_server, datalayer, page, map): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}") +def test_can_import_in_new_datalayer(live_server, datalayer, page, openmap): + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") layers = page.locator(".umap-browse-datalayers li") markers = page.locator(".leaflet-marker-icon") expect(markers).to_have_count(1) diff --git a/umap/tests/integration/test_map.py b/umap/tests/integration/test_map.py index ef27ab72..fda8dec9 100644 --- a/umap/tests/integration/test_map.py +++ b/umap/tests/integration/test_map.py @@ -3,8 +3,6 @@ import re import pytest from playwright.sync_api import expect -from umap.models import Map - from ..base import DataLayerFactory pytestmark = pytest.mark.django_db @@ -149,18 +147,15 @@ def test_default_view_latest_with_polygon(map, live_server, page): def test_remote_layer_should_not_be_used_as_datalayer_for_created_features( - map, live_server, datalayer, page + openmap, live_server, datalayer, page ): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() datalayer.settings["remoteData"] = { "url": "https://overpass-api.de/api/interpreter?data=[out:xml];node[harbour=yes]({south},{west},{north},{east});out body;", "format": "osm", "from": "10", } datalayer.save() - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") toggle = page.get_by_role("button", name="See data layers") expect(toggle).to_be_visible() toggle.click() @@ -179,13 +174,10 @@ def test_remote_layer_should_not_be_used_as_datalayer_for_created_features( expect(layers).to_have_count(2) -def test_can_hide_datalayer_from_caption(map, live_server, datalayer, page): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() +def test_can_hide_datalayer_from_caption(openmap, live_server, datalayer, page): # Add another DataLayer - other = DataLayerFactory(map=map, name="Hidden", settings={"inCaption": False}) - page.goto(f"{live_server.url}{map.get_absolute_url()}") + other = DataLayerFactory(map=openmap, name="Hidden", settings={"inCaption": False}) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}") toggle = page.get_by_text("About").first expect(toggle).to_be_visible() toggle.click() diff --git a/umap/tests/integration/test_picto.py b/umap/tests/integration/test_picto.py index a44e5a02..33a2c214 100644 --- a/umap/tests/integration/test_picto.py +++ b/umap/tests/integration/test_picto.py @@ -5,7 +5,7 @@ import pytest from django.core.files.base import ContentFile from playwright.sync_api import expect -from umap.models import Map, Pictogram +from umap.models import Pictogram from ..base import DataLayerFactory @@ -37,12 +37,9 @@ def pictos(): Pictogram(name="circle", pictogram=ContentFile(path.read_text(), path.name)).save() -def test_can_change_picto_at_map_level(map, live_server, page, pictos): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - DataLayerFactory(map=map, data=DATALAYER_DATA) - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_change_picto_at_map_level(openmap, live_server, page, pictos): + DataLayerFactory(map=openmap, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".umap-div-icon img") expect(marker).to_have_count(1) # Should have default img @@ -71,13 +68,11 @@ def test_can_change_picto_at_map_level(map, live_server, page, pictos): expect(marker).to_have_attribute("src", "/static/umap/img/marker.svg") -def test_can_change_picto_at_datalayer_level(map, live_server, page, pictos): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.settings["properties"]["iconUrl"] = "/uploads/pictogram/star.svg" - map.save() - DataLayerFactory(map=map, data=DATALAYER_DATA) - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_change_picto_at_datalayer_level(openmap, live_server, page, pictos): + openmap.settings["properties"]["iconUrl"] = "/uploads/pictogram/star.svg" + openmap.save() + DataLayerFactory(map=openmap, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".umap-div-icon img") expect(marker).to_have_count(1) # Should have default img @@ -112,13 +107,11 @@ def test_can_change_picto_at_datalayer_level(map, live_server, page, pictos): expect(marker).to_have_attribute("src", "/uploads/pictogram/star.svg") -def test_can_change_picto_at_marker_level(map, live_server, page, pictos): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.settings["properties"]["iconUrl"] = "/uploads/pictogram/star.svg" - map.save() - DataLayerFactory(map=map, data=DATALAYER_DATA) - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_change_picto_at_marker_level(openmap, live_server, page, pictos): + openmap.settings["properties"]["iconUrl"] = "/uploads/pictogram/star.svg" + openmap.save() + DataLayerFactory(map=openmap, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".umap-div-icon img") expect(marker).to_have_count(1) # Should have default img @@ -152,12 +145,9 @@ def test_can_change_picto_at_marker_level(map, live_server, page, pictos): expect(marker).to_have_attribute("src", "/uploads/pictogram/star.svg") -def test_can_use_remote_url_as_picto(map, live_server, page, pictos): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - DataLayerFactory(map=map, data=DATALAYER_DATA) - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_use_remote_url_as_picto(openmap, live_server, page, pictos): + DataLayerFactory(map=openmap, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".umap-div-icon img") expect(marker).to_have_count(1) # Should have default img @@ -195,12 +185,9 @@ def test_can_use_remote_url_as_picto(map, live_server, page, pictos): expect(symbols).to_have_count(1) -def test_can_use_char_as_picto(map, live_server, page, pictos): - # Faster than doing a login - map.edit_status = Map.ANONYMOUS - map.save() - DataLayerFactory(map=map, data=DATALAYER_DATA) - page.goto(f"{live_server.url}{map.get_absolute_url()}?edit") +def test_can_use_char_as_picto(openmap, live_server, page, pictos): + DataLayerFactory(map=openmap, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") marker = page.locator(".umap-div-icon span") # Should have default img, so not a span expect(marker).to_have_count(0)