summaryrefslogtreecommitdiff
path: root/archaeological_finds/tests.py
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-13 22:32:55 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-09-01 12:36:46 +0200
commitd9cc2608a98099a4fc9f0801fa0e8f14573da598 (patch)
tree6a505b12e82f7d02772c04cdd71de9f1d8310f92 /archaeological_finds/tests.py
parenteaee32ea5763a10b31f2e6daf59b3bed9a55cba9 (diff)
downloadIshtar-d9cc2608a98099a4fc9f0801fa0e8f14573da598.tar.bz2
Ishtar-d9cc2608a98099a4fc9f0801fa0e8f14573da598.zip
version before checkbutton
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r--archaeological_finds/tests.py145
1 files changed, 82 insertions, 63 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 0bff022fc..76692fb93 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -2503,29 +2503,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)
@@ -2536,28 +2557,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):
@@ -2579,7 +2598,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 = {
@@ -3236,42 +3255,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'}
@@ -3280,16 +3299,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)