diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-08-24 21:38:46 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-10-25 12:06:03 +0200 |
commit | 8b8460945f1cd39fe0c3a326c236a05c849b331d (patch) | |
tree | ce8f5a11950a4ea6b8d3f0b5716d1121a58f70bd /ishtar_common/tests.py | |
parent | 178f6bd49eaf1c2a04e3433784ebeb48b89cd2fa (diff) | |
download | Ishtar-8b8460945f1cd39fe0c3a326c236a05c849b331d.tar.bz2 Ishtar-8b8460945f1cd39fe0c3a326c236a05c849b331d.zip |
ui tests without base feature point working
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 227 |
1 files changed, 210 insertions, 17 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index e3314b58f..ca3b40303 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -16,9 +16,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # See the file COPYING for details. -import re - from bs4 import BeautifulSoup as Soup +import re import csv import datetime import importlib @@ -2852,23 +2851,23 @@ class GeomaticTest(TestCase): @staticmethod def pt_coords_from_label(label, geoms): if label[:2] == "Pt": - return geoms[0][2] + return geoms[0][2], True if label[:4] == "Poly": - return geoms[0][1] + return geoms[0][1], False if label[:2] == "CR": if label[-2:] == "Pt": - return geoms[1][2] + return geoms[1][2], True if label[3:5] == "Pt": - return geoms[0][2] - return geoms[1][1] + return geoms[0][2], True + return geoms[1][1], False if label[5:10] == "Point": - return geoms[2][2] + return geoms[2][2], True # label has shape Find Polygon from CR xxx xxx if label[-2:] == "Pt": - return geoms[1][2] + return geoms[1][2], True if label[21:23] == "Pt": - return geoms[0][2] - return geoms[2][1] + return geoms[0][2], True + return geoms[2][1], False def assertPt(self, item, geom): self.assertEqual(item.multi_polygon.coords, geom[0].coords) @@ -2917,6 +2916,177 @@ class GeomaticTest(TestCase): 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): + from archaeological_operations.models import Operation + from archaeological_context_records.models import ContextRecord + from archaeological_finds.models import BaseFind + import copy + + cache_dics_t, cache_dics_f = {}, {} + res = {} + + def finds_first(x): + if x[:2] == "CR": + return 0 + if x[:4] == "Find": + return -1 + else: + return 1 + + labels = list(pks.keys()) + labels.sort(key=finds_first) + for label in labels: + pk = pks[label] + pt_coords, precise = GeomaticTest.pt_coords_from_label(label, geoms) + if label[:4] == "Find": + dic_t = { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", "coordinates": geoms[2][0] + }, + "properties": {"label": label}, + } + dic_f = { + "type": "Feature", + "geometry": { + "type": "Point", "coordinates": pt_coords, + }, + "properties": {"label": label}, + } + cache_dics_t[label] = dic_t + 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) + get_pk = "?pk=" + else: + get_polys = dic_t + get_pts = dic_f + + elif label[:2] == "CR": + cache_key = lambda x: "Find " + x + " from " + label + dic_t = { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", "coordinates": geoms[1][0] + }, + "properties": { + "label": label, + "base-finds": { + '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, + }, + "properties": { + "label": label, + "base-finds": { + '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) + get_pk = "?context_record_pk=" + else: + get_polys = copy.deepcopy(dic_t) + 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")] + else: + real_label = "OA3" + cache_key_prefix = "CR " + label + " " + if label == "Pt": + real_label = "OA2" + dic_t = { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", "coordinates": geoms[0][0] + }, + "properties": { + "label": real_label, + "context-records": { + '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, + }, + "properties": { + "label": real_label, + "context-records": { + '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) + 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': [ + cache_key_prefix + "Poly", + cache_key_prefix + "Pt" + ], + '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': [ + cache_key_prefix + "Poly", + cache_key_prefix + "Pt" + ], + '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} + else: + res[label] = {'get_polys': get_polys, + 'get_pts': get_pts, + 'precise': precise} + return res class NewItems(TestCase): fixtures = COMMON_FIXTURES @@ -3366,6 +3536,11 @@ class SeleniumTests(StaticLiveServerTestCase): def setUpDefaultGeoItems(self): return GeomaticTest.setUpDefaultGeoItems(self.user) + def pks_and_geojson(self): + geoms, pks = self.setUpDefaultGeoItems() + geojsons = GeomaticTest.geojson_geo_items(geoms, pks) + return pks, geojsons + def scroll(self, element): self.selenium.execute_script( "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" @@ -3373,20 +3548,38 @@ class SeleniumTests(StaticLiveServerTestCase): + "window.scrollBy(0, elementTop-(viewPortHeight/2));", element) - def assertMap(self, dic_base, features_collecs=None): - mapdiv = self.selenium.find_element_by_id("window-map") - mapid = mapdiv.get_attribute("id") + def assertNotInDOM(self, xpath): + self.selenium.implicitly_wait(5) + try: + self.WebDriverWait(self.selenium, 2).until( + self.EC.visibility_of_element_located((self.By.XPATH, xpath)) + ) + found = True + except: + found = False + self.selenium.implicitly_wait(20) + self.assertFalse(found) + + def assertMap(self, dic_base, slug_pk, features_collecs=None): + dic_base = {'type': 'FeatureCollection', 'features': [dic_base]} + mapdivs = self.selenium.find_elements_by_class_name("window-map") + mapid = None + 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()) # 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")) + self.EC.visibility_of_element_located((self.By.ID, "http-geo-items-ready-"+slug_pk)) ) print(id) - print(self.selenium.execute_script('return print(arguments[0])', mapid)) + print('mapid : ', mapid) + 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 + dic_base['features'][0]['properties'] = {'id': id} print('feat : ', base_features) print('dic : ', dic_base) self.assertEqual(base_features, dic_base) |