diff --git a/geonode/maps/tests.py b/geonode/maps/tests.py index 1f6dc1591a9..b0a0de816e0 100644 --- a/geonode/maps/tests.py +++ b/geonode/maps/tests.py @@ -168,6 +168,51 @@ def test_map_json(self): self.assertEquals(map_obj.abstract, "Abstract2") self.assertEquals(map_obj.layer_set.all().count(), 1) + @on_ogc_backend(qgis_server.BACKEND_PACKAGE) + def test_map_json_on_qgis_server(self): + json_payload = InitialSetup.generate_initial_map() + # First, create a map with two layers (and 2 background layers) + # Need to log in for saving a map + self.client.login(username='admin', password='admin') + + result_new_map = self.client.post( + reverse('new_map_json'), + json.dumps(json_payload), + content_type='application/json') + # the new map is successfully saved + self.assertEqual(result_new_map.status_code, 200) + + map_id = json.loads(result_new_map.content).get('id') + old_map_obj = Map.objects.get(id=map_id) + + # try to update by removing one layer + layers = json_payload['map']['layers'] + before_remove = len(layers) + after_remove = before_remove - 1 + layer = layers[0] + layers.remove(layer) + + # update the map + result_update_map = self.client.post( + reverse('map_json', kwargs={'mapid': map_id}), + data=json.dumps(json_payload), + content_type='application/json') + # successfully updated + self.assertEqual(result_update_map.status_code, 200) + new_map_obj = Map.objects.get(id=map_id) + # check if the layer is eliminated from the map + # the number of layers on the map decrease by 1 + self.assertEqual( + len(result_update_map.context_data['map'].layers), + after_remove) + # new thumbnail exist and has the same url with the old one + self.assertEqual( + old_map_obj.get_thumbnail_url(), + new_map_obj.get_thumbnail_url()) + + # clean up + Map.objects.get(id=map_id).delete() + def test_map_save(self): """POST /maps/new/data -> Test saving a new map""" @@ -445,7 +490,6 @@ def test_map_remove(self): # which removes map and associated layers, and redirects webpage response = self.client.post(url) self.assertEquals(response.status_code, 302) - # self.assertEquals(response['Location'], '/maps/') self.assertEquals(response['Location'], 'http://testserver/maps/') # After removal, map is not existent @@ -475,11 +519,18 @@ def test_map_download_leaflet(self): # then, obtain the map using leaflet response = self.client.get( reverse( - 'map_download_leaflet', args=(map_id, ))) + 'map_download_leaflet', args=(map_id,))) - # download map leafleT should return OK - self.assertEquals(response.status_code, 200) - self.assertEquals(response.get('Content-Type'), 'html') + if check_ogc_backend(geoserver.BACKEND_PACKAGE): + # download map leaflet hasn't supported in geoserver + self.assertEquals(response.status_code, 400) + elif check_ogc_backend(qgis_server.BACKEND_PACKAGE): + # download map leaflet should return OK + self.assertEquals(response.status_code, 200) + self.assertEquals(response.get('Content-Type'), 'html') + else: + # failed if the test reaches this point + self.assertFalse(True) def test_map_embed(self): """Test that map can be properly embedded @@ -647,15 +698,15 @@ def test_new_map_config(self): # Check # BBox format: [xmin, xmax, ymin, ymax bbox_str = [ - '-90.193207913954200', '-79.206792062465500', - '9.059219904470890', '16.540780092025600', 'EPSG:4326'] + '-90.1932079140', '-79.2067920625', + '9.0592199045', '16.5407800920', 'EPSG:4326'] - self.assertEqual( + self.assertAlmostEqual( bbox_str, - [str(c) for c in map_obj.bbox]) - bbox_long_str = '-90.193207913954200,9.059219904470890,' \ - '-79.206792062465500,16.540780092025600' - self.assertEqual(bbox_long_str, map_obj.bbox_string) + [c for c in map_obj.bbox]) + bbox_long_str = '-90.1932079140,9.0592199045,' \ + '-79.2067920625,16.5407800920' + self.assertAlmostEqual(bbox_long_str, map_obj.bbox_string) # Test methods other than GET or POST and no layer in params response = self.client.put(url) @@ -795,6 +846,82 @@ def test_batch_edit(self): self.assertTrue(word.name in keywords.split(',')) +class InitialSetup(): + + @classmethod + def generate_initial_map(cls): + # construct json request for new map + json_payload = { + "sources": { + "source_OpenMapSurfer Roads": { + "url": "http://korona.geog.uni-heidelberg.de/tiles" + "/roads/x={x}&y={y}&z={z}" + }, + "source_OpenStreetMap": { + "url": "http://{s}.tile.osm.org/{z}/{x}/{y}.png" + }, + "source_san_andres_y_providencia_administrative": { + "url": "http://geonode.dev/qgis-server/tiles" + "/san_andres_y_providencia_administrative/" + "{z}/{x}/{y}.png" + }, + "source_relief_san_andres": { + "url": "http://geonode.dev/qgis-server/tiles" + "/relief_san_andres/{z}/{x}/{y}.png" + } + }, + "about": { + "title": "San Andreas", + "abstract": "San Andreas sample map" + }, + "map": { + "center": [12.91890657418042, -81.298828125], + "zoom": 6, + "projection": "", + "layers": [ + { + "name": "OpenMapSurfer_Roads", + "title": "OpenMapSurfer Roads", + "visibility": True, + "url": "http://korona.geog.uni-heidelberg.de/tiles/" + "roads/x={x}&y={y}&z={z}", + "group": "background", + "source": "source_OpenMapSurfer Roads" + }, + { + "name": "osm", + "title": "OpenStreetMap", + "visibility": False, + "url": "http://{s}.tile.osm.org/{z}/{x}/{y}.png", + "group": "background", + "source": "source_OpenStreetMap" + }, + { + "name": "geonode:" + "san_andres_y_providencia_administrative", + "title": "san_andres_y_providencia_administrative", + "visibility": True, + "url": "http://geonode.dev/qgis-server/tiles" + "/san_andres_y_providencia_administrative/" + "{z}/{x}/{y}.png", + "source": "source_" + "san_andres_y_providencia_administrative" + }, + { + "name": "geonode:relief_san_andres", + "title": "relief_san_andres", + "visibility": True, + "url": "http://geonode.dev/qgis-server/tiles" + "/relief_san_andres/{z}/{x}/{y}.png", + "source": "source_relief_san_andres" + } + ] + } + } + + return json_payload + + class MapModerationTestCase(TestCase): fixtures = ['initial_data.json', 'bobby']