Fix integration tests for download view
This commit is contained in:
parent
30e83a143c
commit
2274243662
6 changed files with 13 additions and 155 deletions
|
@ -1138,7 +1138,7 @@ L.U.Map.include({
|
||||||
const link = L.DomUtil.createLink(
|
const link = L.DomUtil.createLink(
|
||||||
'button',
|
'button',
|
||||||
container,
|
container,
|
||||||
L._('Download uMap backup format'),
|
L._('Download full data'),
|
||||||
downloadUrl
|
downloadUrl
|
||||||
)
|
)
|
||||||
let name = this.options.name || 'data'
|
let name = this.options.name || 'data'
|
||||||
|
|
|
@ -101,131 +101,5 @@ describe('L.U.Map.Export', function () {
|
||||||
'<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark><name>name poly</name><ExtendedData><Data name="name"><value>name poly</value></Data></ExtendedData><Polygon><outerBoundaryIs><LinearRing><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</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark><Placemark><name>test</name><ExtendedData><Data name="_umap_options"><value>[object Object]</value></Data><Data name="name"><value>test</value></Data></ExtendedData><Point><coordinates>-0.274658,52.57635</coordinates></Point></Placemark><Placemark><name>test</name><ExtendedData><Data name="_umap_options"><value>[object Object]</value></Data><Data name="name"><value>test</value></Data></ExtendedData><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</coordinates></LineString></Placemark></Document></kml>'
|
'<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark><name>name poly</name><ExtendedData><Data name="name"><value>name poly</value></Data></ExtendedData><Polygon><outerBoundaryIs><LinearRing><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</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark><Placemark><name>test</name><ExtendedData><Data name="_umap_options"><value>[object Object]</value></Data><Data name="name"><value>test</value></Data></ExtendedData><Point><coordinates>-0.274658,52.57635</coordinates></Point></Placemark><Placemark><name>test</name><ExtendedData><Data name="_umap_options"><value>[object Object]</value></Data><Data name="name"><value>test</value></Data></ExtendedData><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</coordinates></LineString></Placemark></Document></kml>'
|
||||||
assert.equal(content, expected)
|
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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -71,13 +71,11 @@ class MapFactory(factory.django.DjangoModelFactory):
|
||||||
"properties": {
|
"properties": {
|
||||||
"datalayersControl": True,
|
"datalayersControl": True,
|
||||||
"description": "Which is just the Danube, at the end",
|
"description": "Which is just the Danube, at the end",
|
||||||
"displayCaptionOnLoad": False,
|
|
||||||
"displayDataBrowserOnLoad": False,
|
|
||||||
"displayPopupFooter": False,
|
"displayPopupFooter": False,
|
||||||
"licence": "",
|
"licence": "",
|
||||||
"miniMap": False,
|
"miniMap": False,
|
||||||
"moreControl": True,
|
"moreControl": True,
|
||||||
"name": "Cruising on the Donau",
|
"name": name,
|
||||||
"scaleControl": True,
|
"scaleControl": True,
|
||||||
"tilelayer": {
|
"tilelayer": {
|
||||||
"attribution": "\xa9 OSM Contributors",
|
"attribution": "\xa9 OSM Contributors",
|
||||||
|
@ -100,6 +98,7 @@ class MapFactory(factory.django.DjangoModelFactory):
|
||||||
def _adjust_kwargs(cls, **kwargs):
|
def _adjust_kwargs(cls, **kwargs):
|
||||||
# Make sure there is no persistency
|
# Make sure there is no persistency
|
||||||
kwargs["settings"] = copy.deepcopy(kwargs["settings"])
|
kwargs["settings"] = copy.deepcopy(kwargs["settings"])
|
||||||
|
kwargs["settings"]["properties"]["name"] = kwargs["name"]
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -9,12 +9,12 @@ pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
def test_umap_export(map, live_server, datalayer, page):
|
def test_umap_export(map, live_server, datalayer, page):
|
||||||
page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
|
page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
|
||||||
button = page.get_by_role("button", name="Download data")
|
link = page.get_by_role("link", name="Download full data")
|
||||||
expect(button).to_be_visible()
|
expect(link).to_be_visible()
|
||||||
with page.expect_download() as download_info:
|
with page.expect_download() as download_info:
|
||||||
button.click()
|
link.click()
|
||||||
download = download_info.value
|
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
|
path = Path("/tmp/") / download.suggested_filename
|
||||||
download.save_as(path)
|
download.save_as(path)
|
||||||
downloaded = json.loads(path.read_text())
|
downloaded = json.loads(path.read_text())
|
||||||
|
@ -29,14 +29,12 @@ def test_umap_export(map, live_server, datalayer, page):
|
||||||
"_umap_options": {
|
"_umap_options": {
|
||||||
"browsable": True,
|
"browsable": True,
|
||||||
"displayOnLoad": True,
|
"displayOnLoad": True,
|
||||||
"editMode": "disabled",
|
|
||||||
"inCaption": True,
|
|
||||||
"name": "test datalayer",
|
"name": "test datalayer",
|
||||||
},
|
},
|
||||||
"features": [
|
"features": [
|
||||||
{
|
{
|
||||||
"geometry": {
|
"geometry": {
|
||||||
"coordinates": [13.688965, 48.552978],
|
"coordinates": [13.68896484375, 48.55297816440071],
|
||||||
"type": "Point",
|
"type": "Point",
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -51,25 +49,14 @@ def test_umap_export(map, live_server, datalayer, page):
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"captionBar": False,
|
|
||||||
"captionMenus": True,
|
|
||||||
"datalayersControl": True,
|
"datalayersControl": True,
|
||||||
"description": "Which is just the Danube, at the end",
|
"description": "Which is just the Danube, at the end",
|
||||||
"displayPopupFooter": False,
|
"displayPopupFooter": False,
|
||||||
"easing": False,
|
|
||||||
"embedControl": True,
|
|
||||||
"fullscreenControl": True,
|
|
||||||
"licence": "",
|
"licence": "",
|
||||||
"limitBounds": {},
|
|
||||||
"miniMap": False,
|
"miniMap": False,
|
||||||
"moreControl": True,
|
"moreControl": True,
|
||||||
"name": "test map",
|
"name": "test map",
|
||||||
"overlay": None,
|
|
||||||
"permanentCreditBackground": True,
|
|
||||||
"scaleControl": True,
|
"scaleControl": True,
|
||||||
"scrollWheelZoom": True,
|
|
||||||
"searchControl": True,
|
|
||||||
"slideshow": {},
|
|
||||||
"tilelayer": {
|
"tilelayer": {
|
||||||
"attribution": "© OSM Contributors",
|
"attribution": "© OSM Contributors",
|
||||||
"maxZoom": 18,
|
"maxZoom": 18,
|
||||||
|
|
|
@ -612,7 +612,7 @@ def test_download(client, map, datalayer):
|
||||||
# Test response is a json
|
# Test response is a json
|
||||||
j = json.loads(response.content.decode())
|
j = json.loads(response.content.decode())
|
||||||
assert j["type"] == "umap"
|
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"] == {
|
assert j["geometry"] == {
|
||||||
"coordinates": [13.447265624999998, 48.94415123418794],
|
"coordinates": [13.447265624999998, 48.94415123418794],
|
||||||
"type": "Point",
|
"type": "Point",
|
||||||
|
@ -620,13 +620,11 @@ def test_download(client, map, datalayer):
|
||||||
assert j["properties"] == {
|
assert j["properties"] == {
|
||||||
"datalayersControl": True,
|
"datalayersControl": True,
|
||||||
"description": "Which is just the Danube, at the end",
|
"description": "Which is just the Danube, at the end",
|
||||||
"displayCaptionOnLoad": False,
|
|
||||||
"displayDataBrowserOnLoad": False,
|
|
||||||
"displayPopupFooter": False,
|
"displayPopupFooter": False,
|
||||||
"licence": "",
|
"licence": "",
|
||||||
"miniMap": False,
|
"miniMap": False,
|
||||||
"moreControl": True,
|
"moreControl": True,
|
||||||
"name": "Cruising on the Donau",
|
"name": "test map",
|
||||||
"scaleControl": True,
|
"scaleControl": True,
|
||||||
"tilelayer": {
|
"tilelayer": {
|
||||||
"attribution": "© OSM Contributors",
|
"attribution": "© OSM Contributors",
|
||||||
|
|
|
@ -289,8 +289,8 @@ def test_user_dashboard_display_user_maps(client, map):
|
||||||
def test_user_dashboard_display_user_maps_distinct(client, map):
|
def test_user_dashboard_display_user_maps_distinct(client, map):
|
||||||
# cf https://github.com/umap-project/umap/issues/1325
|
# cf https://github.com/umap-project/umap/issues/1325
|
||||||
anonymap = MapFactory(name="Map witout owner should not appear")
|
anonymap = MapFactory(name="Map witout owner should not appear")
|
||||||
user1 = UserFactory(username='user1')
|
user1 = UserFactory(username="user1")
|
||||||
user2 = UserFactory(username='user2')
|
user2 = UserFactory(username="user2")
|
||||||
map.editors.add(user1)
|
map.editors.add(user1)
|
||||||
map.editors.add(user2)
|
map.editors.add(user2)
|
||||||
map.save()
|
map.save()
|
||||||
|
@ -298,7 +298,7 @@ def test_user_dashboard_display_user_maps_distinct(client, map):
|
||||||
response = client.get(reverse("user_dashboard"))
|
response = client.get(reverse("user_dashboard"))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
body = response.content.decode()
|
body = response.content.decode()
|
||||||
assert body.count(map.name) == 1
|
assert body.count(f'<a href="/en/map/test-map_{map.pk}">test map</a>') == 1
|
||||||
assert body.count(anonymap.name) == 0
|
assert body.count(anonymap.name) == 0
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue