summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-07 01:23:16 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-09-01 12:36:46 +0200
commiteaee32ea5763a10b31f2e6daf59b3bed9a55cba9 (patch)
treedc821f50994ea4ae807c1e509155fd56a32d356a /archaeological_finds
parentdccb0b5be17050731b352e8a7e422f31426cf884 (diff)
downloadIshtar-eaee32ea5763a10b31f2e6daf59b3bed9a55cba9.tar.bz2
Ishtar-eaee32ea5763a10b31f2e6daf59b3bed9a55cba9.zip
PR for peer review
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/tests.py181
1 files changed, 125 insertions, 56 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 9a7cf851c..0bff022fc 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -90,7 +90,7 @@ from ishtar_common.tests import (
WAREHOUSE_FIXTURES,
COMMON_FIXTURES,
GenericSerializationTest,
- SearchText,
+ SearchText, SeleniumTests,
)
from archaeological_operations.tests import ImportTest, create_operation
from archaeological_context_records.tests import ContextRecordInit
@@ -2502,6 +2502,64 @@ class GeomaticTest(FindInit, TestCase):
self.assertEqual(base_find.point_2d.ewkt, "SRID=4326;POINT (42 3)")
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
+ default = {
+ "label": label_cr,
+ "operation": operat,
+ }
+ cr = ContextRecord.objects.create(**default)
+ 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.save()
+ cr = ContextRecord.objects.get(pk=cr.pk)
+
+ bfs = []
+ for i in range(len(list_geom_bf)):
+ default = {
+ "label": "Find " + str(i + 1) + " from " + label_cr,
+ "context_record": cr,
+ }
+ bf = models.BaseFind.objects.create(**default)
+ 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.save()
+ bf = models.BaseFind.objects.get(pk=bf.pk)
+ bfs.append(bf)
+
+ '''data = {}
+ find = models.Find.objects.create(**data)
+ print(bf.point_2d)
+ find.base_finds.add(bf)
+ PROBLEM : point_2d is None'''
+ return cr, bfs
+
def test_get_geo_items(self):
wgs84 = SpatialReferenceSystem.objects.get(srid=4326)
profile = get_current_profile()
@@ -2518,57 +2576,10 @@ class GeomaticTest(FindInit, TestCase):
geom = GEOSGeometry("POINT({} {} {})".format(2, 43, 1), srid=4326)
geom_2d = GEOSGeometry("POINT({} {})".format(2, 43), srid=4326)
xy = 2, 43
-
- def create_cr_with_bfs(operat, geom_cr, list_geom_bf, label_cr):
- default = {
- "label": label_cr,
- "history_modifier": context_record.history_modifier,
- "operation": operat,
- }
- cr = ContextRecord.objects.create(**default)
- 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.multi_polygon = "SRID=4326;" + limit
- cr.multi_polygon_source = "P"
- cr.multi_polygon_source_item = str(ContextRecord._meta.verbose_name)
- cr.save()
- cr = ContextRecord.objects.get(pk=cr.pk)
-
- bfs = []
- for i in range(len(list_geom_bf)):
- default = {
- "label": "Find " + str(i + 1) + " from " + label_cr,
- "history_modifier": base_find.history_modifier,
- "context_record": cr,
- }
- bf = models.BaseFind.objects.create(**default)
- 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.save()
- bf = models.BaseFind.objects.get(pk=bf.pk)
- bfs.append(bf)
- return cr, bfs
+ geom_params = [limit, geom, geom_2d, xy, wgs84]
# with point
- cr_pt_pt, bfs = create_cr_with_bfs(operation, "Point", ["Point"], "CR Pt Pt")
+ cr_pt_pt, bfs = self.create_cr_with_bfs(operation, "Point", ["Point"], "CR Pt Pt", geom_params)
base_find_pt = bfs[0]
dic_pt_t = {
@@ -2629,8 +2640,8 @@ class GeomaticTest(FindInit, TestCase):
self.assertIn(json.dumps(dic_pt_pt_t).encode("utf-8"), response.content)
# the context record is a multi-polygon
- cr_poly_pt, bfs = create_cr_with_bfs(
- operation, "Polygon", ["Point"], "CR Poly Pt"
+ cr_poly_pt, bfs = self.create_cr_with_bfs(
+ operation, "Polygon", ["Point"], "CR Poly Pt", geom_params
)
base_find_pt = bfs[0]
dic_poly_t = {
@@ -2693,8 +2704,8 @@ class GeomaticTest(FindInit, TestCase):
self.assertIn(json.dumps(dic_poly_pt_t).encode("utf-8"), response.content)
# we add a base find which is a multi-polygon
- cr_poly_poly_and_pt, bfs = create_cr_with_bfs(
- ope, "Polygon", ["Polygon", "Point"], "CR Poly Poly Pt"
+ cr_poly_poly_and_pt, bfs = self.create_cr_with_bfs(
+ ope, "Polygon", ["Polygon", "Point"], "CR Poly Poly Pt", geom_params
)
base_find_poly, base_find_pt = bfs
@@ -2780,8 +2791,8 @@ class GeomaticTest(FindInit, TestCase):
self.assertEqual(dic_poly_poly_and_pt_t, json.loads(response.content))
# context record is a point, base find 1 a polygon and base find 2 a point
- cr_pt_poly_and_pt, bfs = create_cr_with_bfs(
- ope, "Point", ["Polygon", "Point"], "CR Pt Poly Pt"
+ cr_pt_poly_and_pt, bfs = self.create_cr_with_bfs(
+ ope, "Point", ["Polygon", "Point"], "CR Pt Poly Pt", geom_params
)
base_find_poly, base_find_pt = bfs
@@ -3224,3 +3235,61 @@ class TemplateTest(FindInit, TestCase):
for tpl in self.templates:
if os.path.exists(tpl):
os.remove(tpl)
+
+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()
+
+ 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"]')
+
+ self.assertLess(len(title), 1)
+ self.assertLess(len(label), 1)
+ self.assertLess(len(disp), 1)
+
+ self.setUpDefaultGeoItems()
+
+ 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'},
+ 'properties': {},
+ 'type': 'Feature'}
+ ]}
+ dic_point = {
+ 'type': 'FeatureCollection',
+ 'features': [
+ {'geometry':
+ {'coordinates': [2, 43],
+ '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"]')
+ 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