diff options
-rw-r--r-- | archaeological_context_records/tests.py | 157 | ||||
-rw-r--r-- | archaeological_finds/tests.py | 145 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 342 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 2 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/action_list.html | 2 | ||||
-rw-r--r-- | ishtar_common/tests.py | 65 |
6 files changed, 367 insertions, 346 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index a71706e40..16bf6d303 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -26,6 +26,7 @@ from django.conf import settings from django.contrib.auth.models import Permission from django.core.exceptions import ValidationError, ImproperlyConfigured from django.core.urlresolvers import reverse +from django.test import tag from django.test.client import Client from django.utils.translation import pgettext_lazy @@ -1364,89 +1365,91 @@ class GraphGenerationTest(ContextRecordInit, TestCase): self.assertNotIn('"CR 2D"', content) +@tag('ui') class SeleniumTestsContextRecords(SeleniumTests): fixtures = CONTEXT_RECORD_FIXTURES + def _test_cr(self, i, dic_polygon, dic_point, geom_bf): + cr_label = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td[2]').text + if cr_label[3:5] == "Pt": + dic_base = dic_point + else: + dic_base = dic_polygon + cr = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') + self.scroll(cr) + cr.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) + + # context record specific + + # click on "Base finds" + self.selenium.execute_script('return initialize_test_map()') + self.scroll(disp) + disp.click() + self.selenium.find_element_by_xpath(select + '/option[@value="basefinds"]').click() + cr_geoms = [ + {'type': 'FeatureCollection', + 'features': [ + {'geometry': + {'coordinates': geom_bf[0], + 'type': 'MultiPolygon'}, + 'properties': {'label': 'Find 1 from ' + cr_label}, + 'type': 'Feature'}, + {'geometry': {'coordinates': geom_bf[0], + 'type': 'MultiPolygon'}, + 'properties': {'label': 'Find 2 from ' + cr_label}, + 'type': 'Feature'}] + } + ] + self.assertMap(dic_base, cr_geoms) + + select_get_poly = dd + '/select[@name="get-polygons"]' + get_poly = self.selenium.find_element_by_xpath(select_get_poly) + self.selenium.execute_script('return initialize_test_map()') + get_poly.click() + self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() + cr_geoms = [ + {'type': 'FeatureCollection', + 'features': [ + {'geometry': + {'coordinates': geom_bf[1], + 'type': 'Point'}, + 'properties': {'label': 'Find 1 from ' + cr_label}, + 'type': 'Feature'}, + {'geometry': {'coordinates': geom_bf[2], + 'type': 'Point'}, + 'properties': {'label': 'Find 2 from ' + cr_label}, + 'type': 'Feature'}] + } + ] + self.assertMap(dic_base, cr_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) + def test_geo_items(self): - def test_cr(i): - cr_label = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td[2]').text - if cr_label[3:5] == "Pt": - dic_base = dic_point - else: - dic_base = dic_polygon - cr = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') - self.scroll(cr) - cr.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) - - # context record specific - - # click on "Base finds" - self.selenium.execute_script('return initialize_test_map()') - self.scroll(disp) - disp.click() - self.selenium.find_element_by_xpath(select + '/option[@value="basefinds"]').click() - cr_geoms = [ - {'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': [[[[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]]]], - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 1 from ' + cr_label}, - 'type': 'Feature'}, - {'geometry': {'coordinates': [], - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 2 from ' + cr_label}, - 'type': 'Feature'}] - } - ] - self.assertMap(dic_base, cr_geoms) - - select_get_poly = dd + '/select[@name="get-polygons"]' - get_poly = self.selenium.find_element_by_xpath(select_get_poly) - self.selenium.execute_script('return initialize_test_map()') - get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() - cr_geoms = [ - {'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': [3.861, 3.028], - 'type': 'Point'}, - 'properties': {'label': 'Find 1 from ' + cr_label}, - 'type': 'Feature'}, - {'geometry': {'coordinates': [2, 43], - 'type': 'Point'}, - 'properties': {'label': 'Find 2 from ' + cr_label}, - 'type': 'Feature'}] - } - ] - self.assertMap(dic_base, cr_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.setUpDefaultGeoItems() + geo_elements = self.setUpDefaultGeoItems() + poly_cr, centr_cr, pt_cr = geo_elements[1] dic_polygon = { 'type': 'FeatureCollection', 'features': [ {'geometry': - {'coordinates': [[[[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]]]], - 'type': 'MultiPolygon'}, + {'coordinates': poly_cr, + 'type': 'MultiPolygon'}, 'properties': {}, 'type': 'Feature'} ]} @@ -1454,14 +1457,14 @@ class SeleniumTestsContextRecords(SeleniumTests): 'type': 'FeatureCollection', 'features': [ {'geometry': - {'coordinates': [2,43], + {'coordinates': pt_cr, 'type': 'Point'}, 'properties': {}, 'type': 'Feature'} ]} for i in range(1, 5): - dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]') + 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="/record_search/"]').click() - test_cr(i)
\ No newline at end of file + self._test_cr(i, dic_polygon, dic_point, geo_elements[2])
\ No newline at end of file diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index f02d0276e..a692cfc9f 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -2521,29 +2521,50 @@ class GeomaticTest(FindInit, TestCase): self.assertEqual(base_find.point_source, "P") @staticmethod - def create_cr_with_bfs(operat, geom_cr, list_geom_bf, label_cr, geom_params): - limit, geom, geom_2d, xy, wgs84 = geom_params + def create_cr_with_bfs(ope, geom_ope, geom_cr, list_geom_bf, label_cr): + 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)))") + 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)))") + 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)))") + 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 + + ope.multi_polygon = "SRID=4326;" + poly_ope + ope.multi_polygon_source = "P" + ope.multi_polygon_source_item = str(ope._meta.verbose_name) + ope.spatial_reference_system = wgs84 + if geom_ope == "Point": + ope.point = point_ope + ope.x, ope.y = xy_ope + ope.point_2d = point_2d_ope + ope.save() # needs 2 saves because point_2d is none for multi_polygon + ope = Operation.objects.get(pk=ope.pk) + ope.save() + ope = Operation.objects.get(pk=ope.pk) + default = { "label": label_cr, - "operation": operat, + "operation": ope, } cr = ContextRecord.objects.create(**default) + cr.multi_polygon = "SRID=4326;" + poly_cr + cr.multi_polygon_source = "P" + cr.multi_polygon_source_item = str(ContextRecord._meta.verbose_name) + cr.spatial_reference_system = wgs84 if geom_cr == "Point": - cr.point = geom - cr.multi_polygon = None - cr.multi_polygon_source = None - cr.multi_polygon_source_item = None - cr.x, cr.y = xy - cr.point_2d = geom_2d - cr.spatial_reference_system = wgs84 - else: - cr.point = None - cr.point_source = None - cr.point_2d = None - cr.point_source_item = None - cr.multi_polygon = "SRID=4326;" + limit - cr.multi_polygon_source = "P" - cr.multi_polygon_source_item = str(ContextRecord._meta.verbose_name) + cr.point = point_cr + cr.x, cr.y = xy_cr + cr.point_2d = point_2d_cr cr.save() cr = ContextRecord.objects.get(pk=cr.pk) @@ -2554,28 +2575,26 @@ class GeomaticTest(FindInit, TestCase): "context_record": cr, } bf = models.BaseFind.objects.create(**default) + bf.multi_polygon = "SRID=4326;" + poly_bf + bf.multi_polygon_source = "P" + bf.multi_polygon_source_item = str(bf._meta.verbose_name) + bf.spatial_reference_system = wgs84 if list_geom_bf[i] == "Point": - bf.point = geom - bf.multi_polygon = None - bf.multi_polygon_source = None - bf.multi_polygon_source_item = None - bf.x, bf.y = xy - bf.point_2d = geom_2d - bf.spatial_reference_system = wgs84 - else: - bf.multi_polygon = "SRID=4326;" + limit - bf.point_source = None - bf.point_2d = None - bf.point = None + bf.point = point_bf + bf.x, bf.y = xy_bf + bf.point_2d = point_2d_bf + bf.save() + bf = models.BaseFind.objects.get(pk=bf.pk) + bf.save() + bf = models.BaseFind.objects.get(pk=bf.pk) bf.save() bf = models.BaseFind.objects.get(pk=bf.pk) bfs.append(bf) - '''data = {} + data = {} find = models.Find.objects.create(**data) - print(bf.point_2d) find.base_finds.add(bf) - PROBLEM : point_2d is None''' + find.save() return cr, bfs def test_get_geo_items(self): @@ -2597,7 +2616,7 @@ class GeomaticTest(FindInit, TestCase): geom_params = [limit, geom, geom_2d, xy, wgs84] # with point - cr_pt_pt, bfs = self.create_cr_with_bfs(operation, "Point", ["Point"], "CR Pt Pt", geom_params) + cr_pt_pt, bfs = self.create_cr_with_bfs(operation, "Point", "Point", ["Point"], "CR Pt Pt", geom_params) base_find_pt = bfs[0] dic_pt_t = { @@ -3254,42 +3273,42 @@ class TemplateTest(FindInit, TestCase): if os.path.exists(tpl): os.remove(tpl) +@tag("ui") class SeleniumTestsBaseFinds(SeleniumTests): fixtures = FIND_FIXTURES - def test_geo_items(self): - def test_bf(i): - bf_label = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td[2]').text - print("BF LABEL : ", bf_label) - if bf_label[3:5] == "Pt": - dic_base = dic_point - else: - dic_base = dic_polygon - cr = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') - self.scroll(cr) - cr.click() + def _test_bf(self, i, dic_polygon, dic_point): + bf_label = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td[2]').text + if bf_label[3:5] == "Pt": + dic_base = dic_point + else: + dic_base = dic_polygon + bf = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') + self.scroll(bf) + bf.click() - self.assertMap(dic_base) + self.assertMap(dic_base) - title = self.selenium.find_elements_by_xpath( - '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]') - dd = '//dl[@class="col-12"]/dd' - label = self.selenium.find_elements_by_xpath(dd + '/label[text()="Display associated features: "]') - disp = self.selenium.find_elements_by_xpath(dd + '/select[@name="display-geo-items"]') + title = self.selenium.find_elements_by_xpath( + '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]') + dd = '//dl[@class="col-12"]/dd' + label = self.selenium.find_elements_by_xpath(dd + '/label[text()="Display associated features: "]') + disp = self.selenium.find_elements_by_xpath(dd + '/select[@name="display-geo-items"]') - self.assertLess(len(title), 1) - self.assertLess(len(label), 1) - self.assertLess(len(disp), 1) + self.assertLess(len(title), 1) + self.assertLess(len(label), 1) + self.assertLess(len(disp), 1) - self.setUpDefaultGeoItems() + def test_geo_items(self): + self.selenium.implicitly_wait(5) + geo_elements = self.setUpDefaultGeoItems() + poly_bf, centr_bf, pt_bf = geo_elements[2] dic_polygon = { 'type': 'FeatureCollection', 'features': [ {'geometry': - {'coordinates': [ - [[[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]]]], + {'coordinates': poly_bf, 'type': 'MultiPolygon'}, 'properties': {}, 'type': 'Feature'} @@ -3298,16 +3317,16 @@ class SeleniumTestsBaseFinds(SeleniumTests): 'type': 'FeatureCollection', 'features': [ {'geometry': - {'coordinates': [2, 43], + {'coordinates': pt_bf, 'type': 'Point'}, 'properties': {}, 'type': 'Feature'} ]} - print(models.Find.objects.all()) - #TODO: create finds from BaseFinds in setUpDefaultGeoItems for i in range(1, 9): - dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]') + 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="/find_search/"]').click() - test_bf(i)
\ No newline at end of file + self._test_bf(i, dic_polygon, dic_point) + + self.selenium.implicitly_wait(20) diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index d2814a21d..a5f1de328 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -33,6 +33,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from django.db.models import Q +from django.test import tag from django.test.client import Client from django.utils.text import slugify @@ -4184,181 +4185,188 @@ class DocumentQATest(OperationInitTest, TestCase): models.Document.objects.get(pk=document_1.pk).source_type, source_type ) - +@tag("ui") class SeleniumTestsOperations(SeleniumTests): fixtures = OPERATION_FIXTURES - def test_geo_items(self): - def test_operation_i(i): - #TODO: dic_base should be point or poly, here it's only poly - dic_base = { - 'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': [ - [[[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]]]], - 'type': 'MultiPolygon'}, - 'properties': {}, + def _test_operation(self, i, dic_base, geom_cr, geom_bf): + 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 + + # 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() + + 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'}]} + ] + self.assertMap(dic_base, 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'}]} + ] + 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()') + 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'} - ]} - 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 - - # 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() - cr_geoms = [ - {'type': 'FeatureCollection', - 'features': [ - {'geometry': - {'coordinates': [ - [[[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]]]], - 'type': 'MultiPolygon'}, + ]}, + {'type': 'FeatureCollection', + 'features': [ + {'geometry': { + 'coordinates': poly_cr, + 'type': 'MultiPolygon'}, 'properties': None, 'type': 'Feature'}, - {'geometry': - {'coordinates': [], 'type': 'MultiPolygon'}, - 'properties': None, 'type': 'Feature'}]} - ] - self.assertMap(dic_base, 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': [3.861, 3.028], 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': - {'coordinates': [2, 43], 'type': 'Point'}, - 'properties': None, 'type': 'Feature'}]} - ] - 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()') - get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="polygons"]').click() - every_geoms = [ - {'type': 'FeatureCollection', - 'features': [{ - 'geometry': { - 'coordinates': [[[[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]]]], - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': [], - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': [[[[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]]]], - 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, - {'geometry': { - 'coordinates': [], 'type': 'MultiPolygon'}, - 'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': [ - [[[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]]]], - 'type': 'MultiPolygon'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': [], - 'type': 'MultiPolygon'}, - 'properties': None, - 'type': 'Feature'} - ]}] - self.assertMap(dic_base, every_geoms) - - self.selenium.execute_script('return initialize_test_map()') - get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() - every_geoms = [ - {'type': 'FeatureCollection', - 'features': [{ - 'geometry': { - 'coordinates': [3.861, 3.028], - 'type': 'Point'}, - 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, + {'geometry': { + 'coordinates': poly_cr, + 'type': 'MultiPolygon'}, + 'properties': None, + 'type': 'Feature'} + ]}] + self.assertMap(dic_base, every_geoms) + + self.selenium.execute_script('return initialize_test_map()') + 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': [2, 43], - 'type': 'Point'}, - 'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': [3.861, 3.028], - 'type': 'Point'}, - 'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, - {'geometry': { - 'coordinates': [2, 43], 'type': 'Point'}, - 'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, - 'type': 'Feature'} - ]}, - {'type': 'FeatureCollection', - 'features': [ - {'geometry': { - 'coordinates': [3.861, 3.028], - 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'}, - {'geometry': { - 'coordinates': [2, 43], - 'type': 'Point'}, - 'properties': None, - 'type': 'Feature'} - ]}] - self.assertMap(dic_base, every_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.setUpDefaultGeoItems() - - self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]').click() + {'geometry': { + 'coordinates': pt_cr, + 'type': 'Point'}, + 'properties': None, + 'type': 'Feature'} + ]}] + self.assertMap(dic_base, every_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) + + def test_geo_items(self): + geo_elements = 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() - test_operation_i(1) # point based operation - dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]') + self._test_operation(1, dic_poly, geo_elements[1], geo_elements[2]) # polygon based operation + 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() - test_operation_i(2) # polygon based operation + self._test_operation(2, dic_pt, geo_elements[1], geo_elements[2]) # point based operation diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index d4eb7285d..56694772b 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -871,7 +871,7 @@ var get_map_by_id_test = function (id) { console.log(map_layers[id][0].getSource()) } -var get_map_by_id = function (id) { +var get_features_by_id = function (id) { if (vector_features[id] == null) { var base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 3}); } else { diff --git a/ishtar_common/templates/blocks/action_list.html b/ishtar_common/templates/blocks/action_list.html index 384082ad4..b2db52f84 100644 --- a/ishtar_common/templates/blocks/action_list.html +++ b/ishtar_common/templates/blocks/action_list.html @@ -1,7 +1,7 @@ <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" - aria-expanded="false">{{section_label|safe}}</a> + aria-expanded="false" id="dropdown-menu-main">{{section_label|safe}}</a> <div class="dropdown-menu"> {% for label, url, has_children in sections %} diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 73e3dda88..1ab718590 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -47,7 +47,7 @@ from django.core.urlresolvers import reverse from django.db.models.fields import BooleanField from django.db.models.fields.related import ForeignKey from django.template.defaultfilters import slugify -from django.test import TestCase as BaseTestCase +from django.test import tag, TestCase as BaseTestCase from django.test.client import Client from django.test.runner import DiscoverRunner @@ -3132,6 +3132,7 @@ class TemplateGenerationTest(TestCase): from django.contrib.staticfiles.testing import StaticLiveServerTestCase from selenium.webdriver.firefox.webdriver import WebDriver +@tag("ui") class SeleniumTests(StaticLiveServerTestCase): from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By @@ -3171,46 +3172,36 @@ class SeleniumTests(StaticLiveServerTestCase): self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click() def setUpDefaultGeoItems(self): - from django.contrib.gis.geos import GEOSGeometry - from ishtar_common.models_common import SpatialReferenceSystem - from archaeological_finds.tests import GeomaticTest from archaeological_operations.tests import create_operation + from archaeological_finds.tests import GeomaticTest as GeomaticFindsTest ope1 = create_operation(self.user) ope2 = create_operation(self.user) + GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Poly Pt") + GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Poly Poly Pt") + GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Pt Poly Pt") + GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly Pt") + + 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]]]], + [3.86111, 3.02778], + [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]]]], + [3.86111, 3.02778], #TODO: change it + [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]]]], + [4.42105, 2.73684], + [3.9, 2.9] + ] + return [geom_ope, geom_cr, geom_bf] - wgs84 = SpatialReferenceSystem.objects.get(srid=4326) - limit = ( - "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)))" - ) - geom = GEOSGeometry("POINT({} {} {})".format(2, 43, 1), srid=4326) - geom_2d = GEOSGeometry("POINT({} {})".format(2, 43), srid=4326) - xy = 2, 43 - geom_params = [limit, geom, geom_2d, xy, wgs84] - - ope1 = self.Operation.objects.get(pk=ope1.pk) - ope1.multi_polygon = limit - ope1.save() - ope1 = self.Operation.objects.get(pk=ope1.pk) - ope1.point = geom - ope1.x, ope2.y = xy - ope1.point_source = "P" - ope1.spatial_reference_system = wgs84 - ope1.point_source_item = "Operation" - ope1.save() - ope1 = self.Operation.objects.get(pk=ope1.pk) - ope2.multi_polygon = limit - ope2.save() - - cr_pt1, (bf_poly_pt1, bf_pt_pt1) = GeomaticTest.create_cr_with_bfs(ope1, "Point", ["Polygon", "Point"], - "CR Pt Poly Pt", geom_params) - cr_poly1, (bf_poly_poly1, bf_pt_poly1) = GeomaticTest.create_cr_with_bfs(ope1, "Polygon", ["Polygon", "Point"], - "CR Poly Poly Pt", geom_params) - cr_pt2, (bf_poly_pt2, bf_pt_pt2) = GeomaticTest.create_cr_with_bfs(ope2, "Point", ["Polygon", "Point"], - "CR Pt Poly Pt", geom_params) - cr_poly2, (bf_poly_poly2, bf_pt_poly2) = GeomaticTest.create_cr_with_bfs(ope2, "Polygon", ["Polygon", "Point"], - "CR Poly Poly Pt", geom_params) def scroll(self, element): self.selenium.execute_script( "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" @@ -3229,7 +3220,7 @@ class SeleniumTests(StaticLiveServerTestCase): ) print(id) print(self.selenium.execute_script('return print(arguments[0])', mapid)) - base_features, geo_items_feats = self.selenium.execute_script('return get_map_by_id(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) |