From 227424366290f865d26d0a7bb6046c70cda76309 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 14 Nov 2023 14:10:25 -0500 Subject: [PATCH] Fix integration tests for download view --- umap/static/umap/js/umap.controls.js | 2 +- umap/static/umap/test/Map.Export.js | 126 ---------------------- umap/tests/base.py | 5 +- umap/tests/integration/test_export_map.py | 23 +--- umap/tests/test_map_views.py | 6 +- umap/tests/test_views.py | 6 +- 6 files changed, 13 insertions(+), 155 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index b95494fe..3eb2ba30 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1138,7 +1138,7 @@ L.U.Map.include({ const link = L.DomUtil.createLink( 'button', container, - L._('Download uMap backup format'), + L._('Download full data'), downloadUrl ) let name = this.options.name || 'data' diff --git a/umap/static/umap/test/Map.Export.js b/umap/static/umap/test/Map.Export.js index 09ce3588..56630e16 100644 --- a/umap/static/umap/test/Map.Export.js +++ b/umap/static/umap/test/Map.Export.js @@ -101,131 +101,5 @@ describe('L.U.Map.Export', function () { 'name polyname poly11.25,53.585984 10.151367,52.975108 12.689209,52.167194 14.084473,53.199452 12.634277,53.618579 11.25,53.585984 11.25,53.585984test[object Object]test-0.274658,52.57635test[object Object]test-0.571289,54.476422 0.439453,54.610255 1.724854,53.448807 4.163818,53.988395 5.306396,53.533778 6.591797,53.709714 7.042236,53.350551' assert.equal(content, expected) }) - - it('should export to umap', function () { - const { content, filetype, filename } = this.map.format('umap') - assert.equal(filetype, 'application/json') - assert.equal(filename, 'name_of_the_map.umap') - const expected = { - type: 'umap', - uri: null, - properties: { - easing: false, - embedControl: true, - fullscreenControl: true, - searchControl: true, - datalayersControl: true, - zoomControl: true, - permanentCreditBackground: true, - slideshow: {}, - captionMenus: true, - captionBar: false, - limitBounds: {}, - overlay: null, - tilelayer: { - attribution: 'HOT and friends', - name: 'HOT OSM-fr server', - url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', - rank: 99, - minZoom: 0, - maxZoom: 20, - id: 2, - }, - licence: '', - description: 'The description of the map', - name: 'name of the map', - displayPopupFooter: false, - miniMap: false, - moreControl: true, - scaleControl: true, - scrollWheelZoom: true, - zoom: 6, - }, - geometry: { - type: 'Point', - coordinates: [5.0592041015625, 52.05924589011585], - }, - layers: [ - { - type: 'FeatureCollection', - features: [ - { - type: 'Feature', - properties: { - name: 'name poly', - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [11.25, 53.585984], - [10.151367, 52.975108], - [12.689209, 52.167194], - [14.084473, 53.199452], - [12.634277, 53.618579], - [11.25, 53.585984], - [11.25, 53.585984], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - _umap_options: { - color: 'OliveDrab', - }, - name: 'test', - }, - geometry: { - type: 'Point', - coordinates: [-0.274658, 52.57635], - }, - }, - { - type: 'Feature', - properties: { - _umap_options: { - fill: false, - }, - name: 'test', - }, - geometry: { - type: 'LineString', - coordinates: [ - [-0.571289, 54.476422], - [0.439453, 54.610255], - [1.724854, 53.448807], - [4.163818, 53.988395], - [5.306396, 53.533778], - [6.591797, 53.709714], - [7.042236, 53.350551], - ], - }, - }, - ], - _umap_options: { - displayOnLoad: true, - browsable: true, - editMode: 'advanced', - iconClass: 'Default', - name: 'Elephants', - id: 62, - pictogram_url: null, - opacity: null, - weight: null, - fillColor: '', - color: '', - stroke: true, - smoothFactor: null, - dashArray: '', - fillOpacity: null, - fill: true, - }, - }, - ], - } - assert.deepEqual(JSON.parse(content), expected) - }) }) }) diff --git a/umap/tests/base.py b/umap/tests/base.py index dc8c1717..ddfa21e5 100644 --- a/umap/tests/base.py +++ b/umap/tests/base.py @@ -71,13 +71,11 @@ class MapFactory(factory.django.DjangoModelFactory): "properties": { "datalayersControl": True, "description": "Which is just the Danube, at the end", - "displayCaptionOnLoad": False, - "displayDataBrowserOnLoad": False, "displayPopupFooter": False, "licence": "", "miniMap": False, "moreControl": True, - "name": "Cruising on the Donau", + "name": name, "scaleControl": True, "tilelayer": { "attribution": "\xa9 OSM Contributors", @@ -100,6 +98,7 @@ class MapFactory(factory.django.DjangoModelFactory): def _adjust_kwargs(cls, **kwargs): # Make sure there is no persistency kwargs["settings"] = copy.deepcopy(kwargs["settings"]) + kwargs["settings"]["properties"]["name"] = kwargs["name"] return kwargs class Meta: diff --git a/umap/tests/integration/test_export_map.py b/umap/tests/integration/test_export_map.py index 6a4368dd..a7f7f9d0 100644 --- a/umap/tests/integration/test_export_map.py +++ b/umap/tests/integration/test_export_map.py @@ -9,12 +9,12 @@ pytestmark = pytest.mark.django_db def test_umap_export(map, live_server, datalayer, page): page.goto(f"{live_server.url}{map.get_absolute_url()}?share") - button = page.get_by_role("button", name="Download data") - expect(button).to_be_visible() + link = page.get_by_role("link", name="Download full data") + expect(link).to_be_visible() with page.expect_download() as download_info: - button.click() + link.click() download = download_info.value - assert download.suggested_filename == "test_map.umap" + assert download.suggested_filename == "umap_backup_test-map.umap" path = Path("/tmp/") / download.suggested_filename download.save_as(path) downloaded = json.loads(path.read_text()) @@ -29,14 +29,12 @@ def test_umap_export(map, live_server, datalayer, page): "_umap_options": { "browsable": True, "displayOnLoad": True, - "editMode": "disabled", - "inCaption": True, "name": "test datalayer", }, "features": [ { "geometry": { - "coordinates": [13.688965, 48.552978], + "coordinates": [13.68896484375, 48.55297816440071], "type": "Point", }, "properties": { @@ -51,25 +49,14 @@ def test_umap_export(map, live_server, datalayer, page): } ], "properties": { - "captionBar": False, - "captionMenus": True, "datalayersControl": True, "description": "Which is just the Danube, at the end", "displayPopupFooter": False, - "easing": False, - "embedControl": True, - "fullscreenControl": True, "licence": "", - "limitBounds": {}, "miniMap": False, "moreControl": True, "name": "test map", - "overlay": None, - "permanentCreditBackground": True, "scaleControl": True, - "scrollWheelZoom": True, - "searchControl": True, - "slideshow": {}, "tilelayer": { "attribution": "© OSM Contributors", "maxZoom": 18, diff --git a/umap/tests/test_map_views.py b/umap/tests/test_map_views.py index 52bd98b3..88dda5f0 100644 --- a/umap/tests/test_map_views.py +++ b/umap/tests/test_map_views.py @@ -612,7 +612,7 @@ def test_download(client, map, datalayer): # Test response is a json j = json.loads(response.content.decode()) assert j["type"] == "umap" - assert j["uri"] == "http://testserver/en/map/test-map_1" + assert j["uri"] == f"http://testserver/en/map/test-map_{map.pk}" assert j["geometry"] == { "coordinates": [13.447265624999998, 48.94415123418794], "type": "Point", @@ -620,13 +620,11 @@ def test_download(client, map, datalayer): assert j["properties"] == { "datalayersControl": True, "description": "Which is just the Danube, at the end", - "displayCaptionOnLoad": False, - "displayDataBrowserOnLoad": False, "displayPopupFooter": False, "licence": "", "miniMap": False, "moreControl": True, - "name": "Cruising on the Donau", + "name": "test map", "scaleControl": True, "tilelayer": { "attribution": "© OSM Contributors", diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index ed11f3b3..08c4586b 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -289,8 +289,8 @@ def test_user_dashboard_display_user_maps(client, map): def test_user_dashboard_display_user_maps_distinct(client, map): # cf https://github.com/umap-project/umap/issues/1325 anonymap = MapFactory(name="Map witout owner should not appear") - user1 = UserFactory(username='user1') - user2 = UserFactory(username='user2') + user1 = UserFactory(username="user1") + user2 = UserFactory(username="user2") map.editors.add(user1) map.editors.add(user2) map.save() @@ -298,7 +298,7 @@ def test_user_dashboard_display_user_maps_distinct(client, map): response = client.get(reverse("user_dashboard")) assert response.status_code == 200 body = response.content.decode() - assert body.count(map.name) == 1 + assert body.count(f'test map') == 1 assert body.count(anonymap.name) == 0