diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 135 | ||||
| -rw-r--r-- | ishtar_common/tests.py | 360 | 
2 files changed, 248 insertions, 247 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index aa7263f7f..4403c7b62 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -146,9 +146,9 @@ var TrackPositionControl = (function (Control) {      if ( Control ) TrackPositionControl.__proto__ = Control;      TrackPositionControl.prototype = Object.create( Control && Control.prototype ); -    TrackPositionControl.prototype.varructor = TrackPositionControl; +    TrackPositionControl.prototype.constructor = TrackPositionControl; -    TrackPositionControl.prototype.handvarrackPosition = function handvarrackPosition () { +    TrackPositionControl.prototype.handleTrackPosition = function handleTrackPosition () {          if (!geolocation[this.map_id]){              set_geoloc_source(this.map_id);          } else { @@ -452,7 +452,7 @@ var open_map_window = function(map_id){      };  }; -var complete_list_label = "compvare list..."; +var complete_list_label = "complete list...";  var _display_items = function(map_id, features, offset_x, offset_y){      // console.log("display_items"); @@ -550,11 +550,12 @@ var vector_source = {};  var vector_layer = {};  var vector_features = {}; -// for test -var geo_items_features = null; -var current_test = false; +/* for test */ + +let geo_items_features = null; +let current_test = false;  var initialize_test_map = function (slug_pk) { -    var id = "http-geo-items-ready-" + slug_pk; +    const id = "http-geo-items-ready-" + slug_pk;      geo_items_features = {};      current_test = true;      if ($("#"+id).length === 0) { @@ -663,7 +664,7 @@ var display_lines_and_polys = function(map_id, lines_and_polys){  var display_geo_items = function(map_id, base_url, slug, pk,                                disp_cr, disp_bf, get_poly) { -    var url = base_url; +    let url = base_url;      if (slug === "operation") {          url += "?operation_pk=";      } @@ -677,9 +678,7 @@ var display_geo_items = function(map_id, base_url, slug, pk,      httpRequest.onreadystatechange = function() {          if (httpRequest.readyState === XMLHttpRequest.DONE) {              if (httpRequest.status === 200) { -                geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, disp_cr, disp_bf) -                console.log('geoitems') -                console.log(geo_items) +                const geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, disp_cr, disp_bf)                  if (current_test) {                      geo_items_features[map_id] = [];                  } @@ -710,7 +709,7 @@ var to_geo_items = function (obj, slug, disp_cr, disp_bf) {      if (slug === "operation") {          const crs = obj['properties']['context-records'];          for (const cr of crs['features']) { -            if (disp_bf) {console.log(cr); +            if (disp_bf) {                  for (const bf of cr['properties']['base-finds']['features']) {                      objects['base-finds']['features'].push(bf)                  } @@ -730,14 +729,14 @@ var to_geo_items = function (obj, slug, disp_cr, disp_bf) {  }  var display_associated_polys = function (map_id, polys, slug) { -    _vector_features = geojson_format.readFeatures(polys); -    _vector_source = new ol.source.Vector(); +    const _vector_features = geojson_format.readFeatures(polys); +    const _vector_source = new ol.source.Vector();      _vector_source.addFeatures(_vector_features); -    style = get_associated_base_find_style; +    let style = get_associated_base_find_style;      if (slug === 'contextrecord') {          style = get_associated_context_record_style;      } -    _vector_layer = new ol.layer.Vector({ +    const _vector_layer = new ol.layer.Vector({          source: _vector_source,          style: style      }); @@ -771,20 +770,15 @@ var get_associated_context_record_style = function (feature) {  };  var display_associated_points = function (map_id, points, slug) { -    console.log('geo items points') -    console.log(points); -    _point_features = geojson_format.readFeatures(points); -    _cluster_source = new ol.source.Cluster({ +    const _point_features = geojson_format.readFeatures(points); +    const _cluster_source = new ol.source.Cluster({          distance: 40,          source: new ol.source.Vector()      });      _cluster_source.getSource().addFeatures(_point_features);      // TODO: create own style -    style = cluster_get_style; -    if (slug === 'contextrecord') { -        style = style; -    } -    _cluster_layer = new ol.layer.Vector({ +    const style = cluster_get_style; +    const _cluster_layer = new ol.layer.Vector({          name: 'Cluster',          source: _cluster_source,          style: style @@ -793,86 +787,16 @@ var display_associated_points = function (map_id, points, slug) {      return _point_features;  } -// for test purpose -// to insert in sheet_simple_map.html when working with maps -// wait_for_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"); -var wait_for_map = function(map_id) { -    map[map_id].on('rendercomplete', function(event) { -        console.log("map fully loaded"); -    }) -    if (map_id in cluster_layer) { -        console.log('cluster layer'); -        cluster_layer[map_id].on('change', function(event) { -            if (cluster_layer.getState === "ready") { -                console.log("cluster fully loaded"); -            } -        }) -    } -    if (map_id in vector_layer) { -        console.log('vector layer'); -        vector_layer[map_id].on('change', function(event) { -            if (vector_layer.getState === "ready") { -                console.log("vector fully loaded"); -            } -        }) -    } -    if (map_id in cluster_source) { -        console.log('cluster source'); -        cluster_source[map_id].on('change', function(event) { -            if (cluster_source.getState === "ready") { -                console.log("cluster source fully loaded"); -            } -        }) -    } -    if (map_id in vector_source) { -        console.log('vector source'); -        vector_source[map_id].on('change', function(event) { -            if (vector_source.getState === "ready") { -                console.log("vector source fully loaded"); -            } -        }) -    } -} - -var get_map_by_id_test = function (id) { -// problem here: async function because map and layers are not fully loaded directly -    map[id].getLayers().getArray()[0].getSource().on( -        'change', function (evt) { -            console.log('change') -            var source = evt.target; -            if (source.getState() === "ready") { -                console.log('ready'); -                console.log(map_layers[id][0].getSource().getKeys()) -            } -        } -    ) -    map[id].on( -        'change', function (evt) { -            console.log('change') -            var map = evt.target; -            if (map.getState() === "ready") { -                console.log('ready'); -                console.log(map_layers[id][0].getSource().getKeys()) -            } -        } -    ) -    console.log("vector_features") -    console.log(vector_features[id]) -    console.log("layers") -    console.log(map_layers[id]) -    console.log("source") -    console.log(map_layers[id][0].getSource()) -} -  var get_features_by_id = function (id) { +    let base_features = null      if (vector_features[id] == null) { -        var base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 5}); +        base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 5});      } else { -        var base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 5}); +        base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 5});      } -    var geo_items_feats = []; +    const geo_items_feats = [];      if (geo_items_features && id in geo_items_features) { -        for (var features of geo_items_features[id]) { +        for (const features of geo_items_features[id]) {              geo_items_feats.push(geojson_format.writeFeaturesObject(features, {decimals: 5}));          }      } @@ -880,5 +804,14 @@ var get_features_by_id = function (id) {  }  var base_features_type = function (id) { -    return "vector " + typeof vector_features[id] + ", cluster " + typeof point_features[id] ; +    if (vector_features[id] == null) { +        if (point_features[id] == null) { +            return 'both null'; +        } +        else { return 'Point'; } +    } +    if (point_features[id] == null) { +        return 'MultiPolygon'; +    } +    else { return 'Point and MultiPolygon' }  } diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 4283e6c6f..b7c0a674e 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -84,6 +84,9 @@ from ishtar_common.utils import (  from ishtar_common.tasks import launch_export  from ishtar_common import utils_secretary +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from selenium.webdriver.firefox.webdriver import WebDriver +  COMMON_FIXTURES = [      settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", @@ -797,7 +800,7 @@ class SerializationTest(GenericSerializationTest, TestCase):              AlterationCauseType,              TreatmentEmergencyType,              CommunicabilityType, -            FunctionalArea +            FunctionalArea,          )          from archaeological_operations.models import CulturalAttributionType @@ -2745,18 +2748,24 @@ class GeomaticTest(TestCase):          from ishtar_common.models_common import SpatialReferenceSystem          wgs84 = SpatialReferenceSystem.objects.get(srid=4326) -        poly_ope = ("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))," -                    "((6 3,9 2,9 4,6 3)))") +        poly_ope = ( +            "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))," +            "((6 3,9 2,9 4,6 3)))" +        )          point_ope = GEOSGeometry("POINT({} {} {})".format(3.8, 3, 1), srid=4326)          point_2d_ope = GEOSGeometry("POINT({} {})".format(3.8, 3), srid=4326)          xy_ope = 3.8, 3 -        poly_cr = ("MULTIPOLYGON(((2 1,5 1,5 5,1 5,2 1),(2 2,2 3,3 3,3 2,2 2))," -                   "((6 3,9 2,9 4,6 3)))") +        poly_cr = ( +            "MULTIPOLYGON(((2 1,5 1,5 5,1 5,2 1),(2 2,2 3,3 3,3 2,2 2))," +            "((6 3,9 2,9 4,6 3)))" +        )          point_cr = GEOSGeometry("POINT({} {} {})".format(3.9, 3, 1), srid=4326)          point_2d_cr = GEOSGeometry("POINT({} {})".format(3.9, 3), srid=4326)          xy_cr = 3.9, 3 -        poly_bf = ("MULTIPOLYGON(((2 1,4 1,4 4,1 4,2 1),(2 2,2 3,3 3,3 2,2 2))," -                   "((6 3,9 2,9 4,6 3)))") +        poly_bf = ( +            "MULTIPOLYGON(((2 1,4 1,4 4,1 4,2 1),(2 2,2 3,3 3,3 2,2 2))," +            "((6 3,9 2,9 4,6 3)))" +        )          point_bf = GEOSGeometry("POINT({} {} {})".format(3.9, 2.9, 1), srid=4326)          point_2d_bf = GEOSGeometry("POINT({} {})".format(3.9, 2.9), srid=4326)          xy_bf = 3.9, 2.9 @@ -2818,7 +2827,7 @@ class GeomaticTest(TestCase):              bf.save()              bf = BaseFind.objects.get(pk=bf.pk)              bfs.append(bf) -            pks[default['label']] = bf.pk +            pks[default["label"]] = bf.pk              find = Find.objects.create()              find.base_finds.add(bf) @@ -2831,30 +2840,61 @@ class GeomaticTest(TestCase):          ope1 = create_operation(user)          ope2 = create_operation(user) -        pks = {'Pt': ope1.pk, 'Poly': ope2.pk} +        pks = {"Pt": ope1.pk, "Poly": ope2.pk} -        pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt")) -        pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly")) -        pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt")) -        pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly")) +        pks.update( +            GeomaticTest.create_cr_with_bfs( +                ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt" +            ) +        ) +        pks.update( +            GeomaticTest.create_cr_with_bfs( +                ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly" +            ) +        ) +        pks.update( +            GeomaticTest.create_cr_with_bfs( +                ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt" +            ) +        ) +        pks.update( +            GeomaticTest.create_cr_with_bfs( +                ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly" +            ) +        )          geom_ope = [ -            [[[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -             [[[6, 3], [9, 2], [9, 4], [6, 3]]]], +            [ +                [ +                    [[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], +                    [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]], +                ], +                [[[6, 3], [9, 2], [9, 4], [6, 3]]], +            ],              [3.86111, 3.02778], -            [3.8, 3] +            [3.8, 3],          ]          geom_cr = [ -            [[[[2, 1], [5, 1], [5, 5], [1, 5], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -             [[[6, 3], [9, 2], [9, 4], [6, 3]]]], +            [ +                [ +                    [[2, 1], [5, 1], [5, 5], [1, 5], [2, 1]], +                    [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]], +                ], +                [[[6, 3], [9, 2], [9, 4], [6, 3]]], +            ],              [4.17708, 3.11458], -            [3.9, 3] +            [3.9, 3],          ]          geom_bf = [ -            [[[[2, 1], [4, 1], [4, 4], [1, 4], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -             [[[6, 3], [9, 2], [9, 4], [6, 3]]]], +            [ +                [ +                    [[2, 1], [4, 1], [4, 4], [1, 4], [2, 1]], +                    [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]], +                ], +                [[[6, 3], [9, 2], [9, 4], [6, 3]]], +            ],              [4.42105, 2.73684], -            [3.9, 2.9] +            [3.9, 2.9],          ]          return [geom_ope, geom_cr, geom_bf], pks @@ -2893,38 +2933,63 @@ class GeomaticTest(TestCase):      def test_setUpDefaultGeoItems(self):          from django.contrib.gis.geos import GEOSGeometry          from archaeological_operations.models import Operation +          username, password, user = create_superuser()          base_geoms, pks = self.setUpDefaultGeoItems(user)          geoms = []          for geom in base_geoms: -            poly = GEOSGeometry(json.dumps({'type': 'MultiPolygon', 'coordinates': geom[0]})) -            centr = GEOSGeometry(json.dumps({'type': 'Point', 'coordinates': geom[1]})) -            pt = GEOSGeometry(json.dumps({'type': 'Point', 'coordinates': geom[2]})) +            poly = GEOSGeometry( +                json.dumps({"type": "MultiPolygon", "coordinates": geom[0]}) +            ) +            centr = GEOSGeometry(json.dumps({"type": "Point", "coordinates": geom[1]})) +            pt = GEOSGeometry(json.dumps({"type": "Point", "coordinates": geom[2]}))              geoms.append([poly, centr, pt]) -        ope_pt = Operation.objects.get(pk=pks['Pt']) +        ope_pt = Operation.objects.get(pk=pks["Pt"])          self.assertPt(ope_pt, geoms[0]) -        ope_poly = Operation.objects.get(pk=pks['Poly']) -        print(ope_poly) -        print(ope_poly.point_2d) +        ope_poly = Operation.objects.get(pk=pks["Poly"])          self.assertPoly(ope_poly, geoms[0]) -        cr_poly_poly = ope_poly.context_record.get(pk=pks['CR Poly Poly']) +        cr_poly_poly = ope_poly.context_record.get(pk=pks["CR Poly Poly"])          self.assertPoly(cr_poly_poly, geoms[1]) -        cr_poly_pt = ope_poly.context_record.get(pk=pks['CR Poly Pt']) +        cr_poly_pt = ope_poly.context_record.get(pk=pks["CR Poly Pt"])          self.assertPt(cr_poly_pt, geoms[1]) -        cr_pt_poly = ope_pt.context_record.get(pk=pks['CR Pt Poly']) +        cr_pt_poly = ope_pt.context_record.get(pk=pks["CR Pt Poly"])          self.assertPoly(cr_pt_poly, geoms[1], geoms[0][2]) -        cr_pt_pt = ope_pt.context_record.get(pk=pks['CR Pt Pt']) +        cr_pt_pt = ope_pt.context_record.get(pk=pks["CR Pt Pt"])          self.assertPt(cr_pt_pt, geoms[1]) -        self.assertPt(cr_pt_pt.base_finds.get(pk=pks['Find Point from CR Pt Pt']), geoms[2]) -        self.assertPoly(cr_pt_pt.base_finds.get(pk=pks['Find Polygon from CR Pt Pt']), geoms[2], geoms[1][2]) -        self.assertPt(cr_poly_pt.base_finds.get(pk=pks['Find Point from CR Poly Pt']), geoms[2]) -        self.assertPoly(cr_poly_pt.base_finds.get(pk=pks['Find Polygon from CR Poly Pt']), geoms[2], geoms[1][2]) -        self.assertPt(cr_pt_poly.base_finds.get(pk=pks['Find Point from CR Pt Poly']), geoms[2]) -        self.assertPoly(cr_pt_poly.base_finds.get(pk=pks['Find Polygon from CR Pt Poly']), geoms[2], geoms[0][2]) -        self.assertPt(cr_poly_poly.base_finds.get(pk=pks['Find Point from CR Poly Poly']), geoms[2]) -        self.assertPoly(cr_poly_poly.base_finds.get(pk=pks['Find Polygon from CR Poly Poly']), geoms[2]) +        self.assertPt( +            cr_pt_pt.base_finds.get(pk=pks["Find Point from CR Pt Pt"]), geoms[2] +        ) +        self.assertPoly( +            cr_pt_pt.base_finds.get(pk=pks["Find Polygon from CR Pt Pt"]), +            geoms[2], +            geoms[1][2], +        ) +        self.assertPt( +            cr_poly_pt.base_finds.get(pk=pks["Find Point from CR Poly Pt"]), geoms[2] +        ) +        self.assertPoly( +            cr_poly_pt.base_finds.get(pk=pks["Find Polygon from CR Poly Pt"]), +            geoms[2], +            geoms[1][2], +        ) +        self.assertPt( +            cr_pt_poly.base_finds.get(pk=pks["Find Point from CR Pt Poly"]), geoms[2] +        ) +        self.assertPoly( +            cr_pt_poly.base_finds.get(pk=pks["Find Polygon from CR Pt Poly"]), +            geoms[2], +            geoms[0][2], +        ) +        self.assertPt( +            cr_poly_poly.base_finds.get(pk=pks["Find Point from CR Poly Poly"]), +            geoms[2], +        ) +        self.assertPoly( +            cr_poly_poly.base_finds.get(pk=pks["Find Polygon from CR Poly Poly"]), +            geoms[2], +        )      @staticmethod      def geojson_geo_items(geoms, pks, test_get_geo_items=False): @@ -2952,15 +3017,14 @@ class GeomaticTest(TestCase):              if label[:4] == "Find":                  dic_t = {                      "type": "Feature", -                    "geometry": { -                        "type": "MultiPolygon", "coordinates": geoms[2][0] -                    }, +                    "geometry": {"type": "MultiPolygon", "coordinates": geoms[2][0]},                      "properties": {"label": label},                  }                  dic_f = {                      "type": "Feature",                      "geometry": { -                        "type": "Point", "coordinates": pt_coords, +                        "type": "Point", +                        "coordinates": pt_coords,                      },                      "properties": {"label": label},                  } @@ -2968,7 +3032,9 @@ class GeomaticTest(TestCase):                  cache_dics_f[label] = dic_f                  if test_get_geo_items:                      res_t = BaseFind.objects.get(pk=pk).get_geo_items(get_polygons=True) -                    res_f = BaseFind.objects.get(pk=pk).get_geo_items(get_polygons=False) +                    res_f = BaseFind.objects.get(pk=pk).get_geo_items( +                        get_polygons=False +                    )                      get_pk = "?pk="                  else:                      get_polys = dic_t @@ -2978,47 +3044,56 @@ class GeomaticTest(TestCase):                  cache_key = lambda x: "Find " + x + " from " + label                  dic_t = {                      "type": "Feature", -                    "geometry": { -                        "type": "MultiPolygon", "coordinates": geoms[1][0] -                    }, +                    "geometry": {"type": "MultiPolygon", "coordinates": geoms[1][0]},                      "properties": {                          "label": label,                          "base-finds": { -                            'type': 'FeatureCollection', -                            'features': [ +                            "type": "FeatureCollection", +                            "features": [                                  cache_dics_t[cache_key("Polygon")],                                  cache_dics_t[cache_key("Point")], -                            ] -                        } +                            ], +                        },                      },                  }                  dic_f = {                      "type": "Feature",                      "geometry": { -                        "type": "Point", "coordinates": pt_coords, +                        "type": "Point", +                        "coordinates": pt_coords,                      },                      "properties": {                          "label": label,                          "base-finds": { -                            'type': 'FeatureCollection', -                            'features': [ +                            "type": "FeatureCollection", +                            "features": [                                  cache_dics_f[cache_key("Polygon")],                                  cache_dics_f[cache_key("Point")], -                            ] -                        } +                            ], +                        },                      },                  }                  cache_dics_t[label] = dic_t                  cache_dics_f[label] = dic_f                  if test_get_geo_items: -                    res_t = ContextRecord.objects.get(pk=pk).get_geo_items(get_polygons=True) -                    res_f = ContextRecord.objects.get(pk=pk).get_geo_items(get_polygons=False) +                    res_t = ContextRecord.objects.get(pk=pk).get_geo_items( +                        get_polygons=True +                    ) +                    res_f = ContextRecord.objects.get(pk=pk).get_geo_items( +                        get_polygons=False +                    )                      get_pk = "?context_record_pk="                  else:                      get_polys = copy.deepcopy(dic_t) -                    get_polys['properties']['base-finds'] = [cache_key("Polygon"), cache_key("Point")] +                    get_polys["properties"]["base-finds"] = [ +                        cache_key("Polygon"), +                        cache_key("Point"), +                    ]                      get_pts = copy.deepcopy(dic_f) -                    get_pts['properties']['base-finds'] = [cache_key("Polygon"), cache_key("Point")] +                    get_pts["properties"]["base-finds"] = [ +                        cache_key("Polygon"), +                        cache_key("Point"), +                    ]              else:                  real_label = "OA3"                  cache_key_prefix = "CR " + label + " " @@ -3026,78 +3101,86 @@ class GeomaticTest(TestCase):                      real_label = "OA2"                  dic_t = {                      "type": "Feature", -                    "geometry": { -                        "type": "MultiPolygon", "coordinates": geoms[0][0] -                    }, +                    "geometry": {"type": "MultiPolygon", "coordinates": geoms[0][0]},                      "properties": {                          "label": real_label,                          "context-records": { -                            'type': 'FeatureCollection', -                            'features': [ +                            "type": "FeatureCollection", +                            "features": [                                  cache_dics_t[cache_key_prefix + "Poly"],                                  cache_dics_t[cache_key_prefix + "Pt"], -                            ] -                        } +                            ], +                        },                      },                  }                  dic_f = {                      "type": "Feature",                      "geometry": { -                        "type": "Point", "coordinates": pt_coords, +                        "type": "Point", +                        "coordinates": pt_coords,                      },                      "properties": {                          "label": real_label,                          "context-records": { -                            'type': 'FeatureCollection', -                            'features': [ +                            "type": "FeatureCollection", +                            "features": [                                  cache_dics_f[cache_key_prefix + "Poly"],                                  cache_dics_f[cache_key_prefix + "Pt"], -                            ] -                        } +                            ], +                        },                      },                  }                  if test_get_geo_items: -                    res_t = Operation.objects.get(pk=pk).get_geo_items(get_polygons=True) -                    res_f = Operation.objects.get(pk=pk).get_geo_items(get_polygons=False) +                    res_t = Operation.objects.get(pk=pk).get_geo_items( +                        get_polygons=True +                    ) +                    res_f = Operation.objects.get(pk=pk).get_geo_items( +                        get_polygons=False +                    )                      get_pk = "?operation_pk="                  else:                      get_polys = copy.deepcopy(dic_t)                      bf_labels = [] -                    for cr in dic_t['properties']['context-records']['features']: -                        for bf in cr['properties']['base-finds']['features']: -                            bf_labels.append(bf['properties']['label']) -                    get_polys['properties'] = { -                        'context-records': [ +                    for cr in dic_t["properties"]["context-records"]["features"]: +                        for bf in cr["properties"]["base-finds"]["features"]: +                            bf_labels.append(bf["properties"]["label"]) +                    get_polys["properties"] = { +                        "context-records": [                              cache_key_prefix + "Poly", -                            cache_key_prefix + "Pt" +                            cache_key_prefix + "Pt",                          ], -                        'base-finds': bf_labels +                        "base-finds": bf_labels,                      }                      get_pts = copy.deepcopy(dic_f)                      bf_labels = [] -                    for cr in dic_f['properties']['context-records']['features']: -                        for bf in cr['properties']['base-finds']['features']: -                            bf_labels.append(bf['properties']['label']) -                    get_pts['properties'] = { -                        'context-records': [ +                    for cr in dic_f["properties"]["context-records"]["features"]: +                        for bf in cr["properties"]["base-finds"]["features"]: +                            bf_labels.append(bf["properties"]["label"]) +                    get_pts["properties"] = { +                        "context-records": [                              cache_key_prefix + "Poly", -                            cache_key_prefix + "Pt" +                            cache_key_prefix + "Pt",                          ], -                        'base-finds': bf_labels +                        "base-finds": bf_labels,                      }              if test_get_geo_items: -                res[label] = {'get_polys': dic_t, -                              'get_pts': dic_f, -                              'res_polys': res_t, -                              'res_pts': res_f, -                              'get_pk': get_pk} +                res[label] = { +                    "get_polys": dic_t, +                    "get_pts": dic_f, +                    "res_polys": res_t, +                    "res_pts": res_f, +                    "get_pk": get_pk, +                }              else: -                res[label] = {'get_polys': get_polys, -                              'get_pts': get_pts, -                              'precise': precise} +                res[label] = { +                    "get_polys": get_polys, +                    "get_pts": get_pts, +                    "precise": precise, +                }          return res +  class NewItems(TestCase):      fixtures = COMMON_FIXTURES @@ -3572,8 +3655,6 @@ class TemplateGenerationTest(TestCase):                  for key in expected_keys:                      self.assertIn(key, filtr) -from django.contrib.staticfiles.testing import StaticLiveServerTestCase -from selenium.webdriver.firefox.webdriver import WebDriver  @tag("ui")  class SeleniumTests(StaticLiveServerTestCase): @@ -3584,8 +3665,9 @@ class SeleniumTests(StaticLiveServerTestCase):      @classmethod      def setUpClass(cls):          super().setUpClass() +        cls.waiting_time = 20          cls.selenium = WebDriver() -        cls.selenium.implicitly_wait(20) +        cls.selenium.implicitly_wait(cls.waiting_time)      @classmethod      def tearDownClass(cls): @@ -3604,14 +3686,17 @@ class SeleniumTests(StaticLiveServerTestCase):          # login          self.username, self.password, self.user = create_superuser() -        self.selenium.get('%s%s' % (self.live_server_url, '/accounts/login/')) -        self.WebDriverWait(self.selenium, 2).until( -            lambda driver: driver.find_element_by_name("username")) +        self.selenium.get("%s%s" % (self.live_server_url, "/accounts/login/")) +        self.WebDriverWait(self.selenium, self.waiting_time).until( +            lambda driver: driver.find_element_by_name("username") +        )          username_input = self.selenium.find_element_by_name("username")          username_input.send_keys(self.username)          password_input = self.selenium.find_element_by_name("password")          password_input.send_keys(self.password) -        self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click() +        self.selenium.find_element_by_xpath( +            '//button[@type="submit"][@class="btn btn-primary"]' +        ).click()      def setUpDefaultGeoItems(self):          return GeomaticTest.setUpDefaultGeoItems(self.user) @@ -3626,67 +3711,50 @@ class SeleniumTests(StaticLiveServerTestCase):              "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"              + "var elementTop = arguments[0].getBoundingClientRect().top;"              + "window.scrollBy(0, elementTop-(viewPortHeight/2));", -            element) - -    ''' -    arguments:  -        i is the number of the row (starting at 1) -        target and source are a tuple of french/english slugs corresponding respectively to the slug of the item of  -        which we want some details and the slug of the item from which we launched the search -    ''' -    def click_on_details(self, i, target, source=None): -        table = '//table[contains(@id, ' + target[0] + ') or contains(@id, ' + target[1] + ')]' -        if source: -            table += '[contains(@id, ' + source[0] + ') or contains(@id, ' + source[1] + ')]' -        details = table + '/tbody/' + '/tr[' + str(i) + ']/td/a[@class="display_details"]' -        details = self.selenium.find_element_by_xpath(details) -        self.scroll(details) -        details.click() +            element, +        )      def assertNotInDOM(self, xpath): -        self.selenium.implicitly_wait(3) +        self.selenium.implicitly_wait(self.waiting_time / 5)          try: -            self.WebDriverWait(self.selenium, 2).until( +            self.WebDriverWait(self.selenium, self.waiting_time / 5).until(                  self.EC.visibility_of_element_located((self.By.XPATH, xpath))              )              found = True          except:              found = False -        self.selenium.implicitly_wait(20) +        self.selenium.implicitly_wait(self.waiting_time)          self.assertFalse(found)      def assertMap(self, dic_base, slug_pk, features_collecs=None): -        dic_base = {'type': 'FeatureCollection', 'features': [dic_base]} +        dic_base = {"type": "FeatureCollection", "features": [dic_base]}          mapid = None -        timeout = 20          t = time() -        while not mapid and time()-t < timeout: +        while not mapid and time() - t < self.waiting_time:              mapdivs = self.selenium.find_elements_by_class_name("window-map")              for mapdiv in mapdivs:                  if slug_pk in mapdiv.get_attribute("id"):                      mapid = mapdiv.get_attribute("id")                      break -        id = int(re.search(r'\d+$', mapid).group()) +        id = int(re.search(r"\d+$", mapid).group())          # TODO: use the map and not the map_features in the js function          if features_collecs: -            self.WebDriverWait(self.selenium, 2).until( -                self.EC.visibility_of_element_located((self.By.ID, "http-geo-items-ready-"+slug_pk)) +            self.WebDriverWait(self.selenium, self.waiting_time).until( +                self.EC.visibility_of_element_located( +                    (self.By.ID, "http-geo-items-ready-" + slug_pk) +                )              ) -        print('id : ', id) -        print('mapid : ', mapid) -        print('slug_pk : ', slug_pk) -        print(self.selenium.execute_script('return base_features_type(arguments[0])', mapid)) -        base_features, geo_items_feats = self.selenium.execute_script('return get_features_by_id(arguments[0])', mapid) -        base_features['features'][0]['properties'].pop('name') -        dic_base['features'][0]['properties'] = {'id': id} -        print('feat : ', base_features) -        print('dic : ', dic_base) +        base_features, geo_items_feats = self.selenium.execute_script( +            "return get_features_by_id(arguments[0])", mapid +        ) +        base_features["features"][0]["properties"].pop("name") +        base_features_type = self.selenium.execute_script( +            "return base_features_type(arguments[0])", mapid +        ) +        dic_base["features"][0]["properties"] = {"id": id} +        self.assertEqual( +            base_features_type, dic_base["features"][0]["geometry"]["type"] +        )          self.assertEqual(base_features, dic_base)          if features_collecs: -            print('feat : ', geo_items_feats) -            print('dic : ', features_collecs) -            try: -                self.assertEqual(geo_items_feats, features_collecs) -            except: -                self.selenium.implicitly_wait(10000) -                self.selenium.find_element_by_xpath('doesnet') +            self.assertEqual(geo_items_feats, features_collecs)  | 
