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 /archaeological_operations | |
parent | 178f6bd49eaf1c2a04e3433784ebeb48b89cd2fa (diff) | |
download | Ishtar-8b8460945f1cd39fe0c3a326c236a05c849b331d.tar.bz2 Ishtar-8b8460945f1cd39fe0c3a326c236a05c849b331d.zip |
ui tests without base feature point working
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/tests.py | 271 |
1 files changed, 117 insertions, 154 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index bbcf1ddd5..8a377d798 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -19,7 +19,6 @@ import json import datetime -import re from subprocess import Popen, PIPE from io import StringIO, BytesIO import tempfile @@ -4189,185 +4188,149 @@ class DocumentQATest(OperationInitTest, TestCase): class SeleniumTestsOperations(SeleniumTests): fixtures = OPERATION_FIXTURES - def _test_operation(self, i, dic_base, geom_cr, geom_bf): + def _test_operation(self, i, slug_pk, geojsons, label): + get_poly_id = "get-poly-for-" + slug_pk + disp_cr_id = "disp-cr-for-" + slug_pk + disp_bf_id = "disp-bf-for-" + slug_pk + + ope_polys = geojsons[label]['get_polys'] + cr_labels_polys = ope_polys['properties'].pop('context-records') + bf_labels_polys = ope_polys['properties'].pop('base-finds') + cr_polys = {'type': 'FeatureCollection', 'features': []} + for cr_label in cr_labels_polys: + geojsons[cr_label]['get_polys']['properties'] = None + cr_polys['features'].append(geojsons[cr_label]['get_polys']) + bf_polys = {'type': 'FeatureCollection', + 'features': [geojsons[bf_label]['get_polys'] for bf_label in bf_labels_polys] + } + + ope_pts = geojsons[label]['get_pts'] + cr_labels_pts = ope_pts['properties'].pop('context-records') + cr_pts = {'type': 'FeatureCollection', 'features': []} + for cr_label in cr_labels_pts: + geojsons[cr_label]['get_pts']['properties'] = None + cr_pts['features'].append(geojsons[cr_label]['get_pts']) + bf_labels_pts = ope_pts['properties'].pop('base-finds') + bf_pts = {'type': 'FeatureCollection', + 'features': [geojsons[bf_label]['get_pts'] for bf_label in bf_labels_pts] + } + + if False: # geojsons[label]['precise'] + ope_base = geojsons[label]['get_pts'] + else: + ope_base = geojsons[label]['get_polys'] + self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]').click() self.WebDriverWait(self.selenium, 2).until( lambda driver: driver.find_element_by_xpath( '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]')) - self.selenium.find_element_by_xpath( - '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]') dd = '//dl[@class="col-12"]/dd' - self.selenium.find_element_by_xpath(dd + '/label[text()="Display associated features: "]') - select = dd + '/select[@name="display-geo-items"]' - disp = self.selenium.find_element_by_xpath(select) - self.assertEqual(disp.get_attribute("value"), "") - self.assertMap(dic_base) - - # operation specific - poly_cr, centr_cr, pt_cr = geom_cr - poly_bf, centr_bf, pt_bf = geom_bf + self.selenium.find_element_by_xpath(dd + '/fieldset/label[text()="Display context records"]') + disp_cr = self.selenium.find_element_by_xpath(dd + '/fieldset/input[@id="' + disp_cr_id + '"]') + self.selenium.find_element_by_xpath(dd + '/fieldset/label[text()="Display context records"]') + disp_bf = self.selenium.find_element_by_xpath(dd + '/fieldset/input[@id="' + disp_bf_id + '"]') + self.assertFalse(disp_cr.is_selected()) + self.assertFalse(disp_bf.is_selected()) + select_get_poly = dd + '/select[@id="' + get_poly_id + '"]' + self.assertNotInDOM(select_get_poly) + self.assertMap(ope_base, slug_pk) # click on "Context records" - self.selenium.execute_script('return initialize_test_map()') - self.scroll(disp) - disp.click() - self.selenium.find_element_by_xpath(select + '/option[@value="contextrecords"]').click() + self.selenium.execute_script('return initialize_test_map(arguments[0])', slug_pk) + self.scroll(disp_cr) + disp_cr.click() cr_geoms = [ - {'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': poly_cr, - 'type': 'MultiPolygon'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': - {'coordinates': poly_cr, 'type': 'MultiPolygon'}, - 'properties': None, 'type': 'Feature'}]} + {'type': 'FeatureCollection', 'features': []}, + cr_polys ] - self.assertMap(dic_base, cr_geoms) + self.assertTrue(disp_cr.is_selected()) + self.assertFalse(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, cr_geoms) - select_get_poly = dd + '/select[@name="get-polygons"]' get_poly = self.selenium.find_element_by_xpath(select_get_poly) get_poly.click() self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() cr_geoms = [ - {'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': centr_cr, 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': - {'coordinates': pt_cr, 'type': 'Point'}, - 'properties': None, 'type': 'Feature'}]} + {'type': 'FeatureCollection', 'features': []}, + cr_pts ] - self.assertMap(dic_base, cr_geoms) - - # Click on "Everything" - disp.click() - self.selenium.find_element_by_xpath(select + '/option[@value="basefinds"]').click() - self.selenium.execute_script('return initialize_test_map()') + self.assertTrue(disp_cr.is_selected()) + self.assertFalse(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, cr_geoms) + + # Click on everything + self.selenium.execute_script('return initialize_test_map(arguments[0])', slug_pk) + disp_bf.click() + every_geoms = [bf_pts, cr_pts] + self.assertTrue(disp_cr.is_selected()) + self.assertTrue(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, every_geoms) + + self.selenium.execute_script('return initialize_test_map(arguments[0])', slug_pk) get_poly.click() self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="polygons"]').click() - every_geoms = [ - {'type': 'FeatureCollection', - 'features': [{ - 'geometry': { - 'coordinates': poly_bf, - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': poly_bf, - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': poly_bf, - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, - {'geometry': { - 'coordinates': poly_bf, 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': poly_cr, - 'type': 'MultiPolygon'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': poly_cr, - 'type': 'MultiPolygon'}, - 'properties': None, - 'type': 'Feature'} - ]}] - self.assertMap(dic_base, every_geoms) - - self.selenium.execute_script('return initialize_test_map()') + every_geoms = [bf_polys, cr_polys] + self.assertTrue(disp_cr.is_selected()) + self.assertTrue(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, every_geoms) + + # click on "Base finds" + self.selenium.execute_script('return initialize_test_map(arguments[0])', slug_pk) + self.scroll(disp_cr) + disp_cr.click() + + bf_geoms = [ + bf_polys, + {'type': 'FeatureCollection', 'features': []} + ] + self.assertFalse(disp_cr.is_selected()) + self.assertTrue(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, bf_geoms) + + select_get_poly = dd + '/select[@id="' + get_poly_id + '"]' + get_poly = self.selenium.find_element_by_xpath(select_get_poly) get_poly.click() self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() - every_geoms = [ - {'type': 'FeatureCollection', - 'features': [{ - 'geometry': { - 'coordinates': centr_bf, - 'type': 'Point'}, - 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': pt_bf, - 'type': 'Point'}, - 'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': centr_bf, - 'type': 'Point'}, - 'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, - {'geometry': { - 'coordinates': pt_bf, 'type': 'Point'}, - 'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': centr_cr, - 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': pt_cr, - 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'} - ]}] - self.assertMap(dic_base, every_geoms) + bf_geoms = [ + bf_pts, + {'type': 'FeatureCollection', 'features': []} + ] + self.assertFalse(disp_cr.is_selected()) + self.assertTrue(disp_bf.is_selected()) + self.assertMap(ope_base, slug_pk, bf_geoms) # Click on "None" - self.selenium.execute_script('return initialize_test_map()') - disp.click() - self.selenium.find_element_by_xpath(select + '/option[@value=""]').click() - self.assertMap(dic_base) + self.selenium.execute_script('return initialize_test_map(arguments[0])', slug_pk) + disp_bf.click() + self.assertFalse(disp_cr.is_selected()) + self.assertFalse(disp_bf.is_selected()) + self.assertNotInDOM(select_get_poly) + self.assertMap(ope_base, slug_pk) def test_geo_items(self): - geo_elements, ope_pks = self.setUpDefaultGeoItems() - poly_ope, centr_ope, pt_ope = geo_elements[0] - - dic_poly = { - 'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': poly_ope, - 'type': 'MultiPolygon'}, - 'properties': {}, - 'type': 'Feature'} - ]} - dic_pt = { - 'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': pt_ope, - 'type': 'MultiPolygon'}, - 'properties': {}, - 'type': 'Feature'} - ]} - - self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]').click() - self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]').click() - self._test_operation(1, dic_poly, geo_elements[1], geo_elements[2]) # polygon based operation + pks, geojsons = self.pks_and_geojson() + + self.WebDriverWait(self.selenium, 2).until( + lambda driver: driver.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]')) dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]') + dropdown.click() + self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]').click() + ope = models.Operation.objects.get(pk=pks['Poly']) + slug_pk_poly = str(ope.SLUG) + "-" + str(ope.pk) + self._test_operation(2, slug_pk_poly, geojsons, 'Poly') + + dropdown = self.selenium.find_element_by_xpath( + '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]') self.scroll(dropdown) dropdown.click() self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]').click() - self._test_operation(2, dic_pt, geo_elements[1], geo_elements[2]) # point based operation + ope = models.Operation.objects.get(pk=pks['Pt']) + print('\n') + print('OPERATION POINT') + print(ope) + print(ope.multi_polygon.coords) + print(ope.point_2d.coords) + slug_pk_pt = str(ope.SLUG) + "-" + str(ope.pk) + self._test_operation(1, slug_pk_pt, geojsons, 'Pt') |