From 73d59d1d535e8ea779ac8e908ee6ffd4f08635cc Mon Sep 17 00:00:00 2001 From: QuentinAndre Date: Thu, 19 Aug 2021 09:43:52 +0200 Subject: test_geo_items works and manual tests work for ui --- ishtar_common/tests.py | 177 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 145 insertions(+), 32 deletions(-) (limited to 'ishtar_common/tests.py') diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index c8bbf4342..348166069 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -2691,6 +2691,8 @@ class IshtarBasicTest(TestCase): class GeomaticTest(TestCase): + fixtures = FIND_FIXTURES + def test_post_save_point(self): class FakeGeomaticObject(object): _meta = models.GeoItem._meta @@ -2724,6 +2726,148 @@ class GeomaticTest(TestCase): self.assertIsNotNone(obj.point_2d) self.assertIsNotNone(obj.point) + @staticmethod + def create_cr_with_bfs(ope, geom_ope, geom_cr, list_geom_bf, label_cr): + from archaeological_operations.models import Operation + from archaeological_context_records.models import ContextRecord + from archaeological_finds.models import BaseFind, Find + from django.contrib.gis.geos import GEOSGeometry + from ishtar_common.models_common import SpatialReferenceSystem + + 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 + + pks = {} + + 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.point_source = "P" + ope.point_source_item = str(ope._meta.verbose_name) + 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": ope, + } + cr = ContextRecord.objects.create(**default) + cr = ContextRecord.objects.get(pk=cr.pk) + cr.multi_polygon = "SRID=4326;" + poly_cr + cr.multi_polygon_source = "P" + cr.multi_polygon_source_item = str(cr._meta.verbose_name) + cr.spatial_reference_system = wgs84 + if geom_cr == "Point": + cr.point = point_cr + cr.point_source = "P" + cr.point_source_item = str(cr._meta.verbose_name) + cr.x, cr.y = xy_cr + cr.point_2d = point_2d_cr + cr.save() + cr = ContextRecord.objects.get(pk=cr.pk) + pks[label_cr] = cr.pk + + bfs = [] + for bf_geom in list_geom_bf: + default = { + "label": "Find " + bf_geom + " from " + label_cr, + "context_record": cr, + } + bf = 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 bf_geom == "Point": + bf.point = point_bf + bf.point_source = "P" + bf.point_source_item = str(bf._meta.verbose_name) + bf.x, bf.y = xy_bf + bf.point_2d = point_2d_bf + bf.save() + bf = BaseFind.objects.get(pk=bf.pk) + bfs.append(bf) + pks[default['label']] = bf.pk + + find = Find.objects.create() + find.base_finds.add(bf) + find.save() + return pks + + @staticmethod + def setUpDefaultGeoItems(user): + from archaeological_operations.tests import create_operation + + ope1 = create_operation(user) + ope2 = create_operation(user) + pks = {'Pt': ope1.pk, 'Poly': ope2.pk} + + pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt")) + pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly")) + pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt")) + pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly")) + + 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]]]], + [4.17708, 3.11458], + [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], pks + + @staticmethod + def pt_coords_from_label(label, geoms): + if label[:2] == "Pt": + return geoms[0][2] + if label[:4] == "Poly": + return geoms[0][1] + if label[:2] == "CR": + if label[-2:] == "Pt": + return geoms[1][2] + if label[3:5] == "Pt": + return geoms[0][2] + return geoms[1][1] + if label[5:10] == "Point": + return geoms[2][2] + # label has shape Find Polygon from CR xxx xxx + if label[-2:] == "Pt": + return geoms[1][2] + if label[21:23] == "Pt": + return geoms[0][2] + return geoms[2][1] class NewItems(TestCase): fixtures = COMMON_FIXTURES @@ -3171,38 +3315,7 @@ class SeleniumTests(StaticLiveServerTestCase): self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click() def setUpDefaultGeoItems(self): - 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) - pks = {'Pt': ope1.pk, 'Poly': ope2.pk} - - pks.update(GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt")) - pks.update(GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly")) - pks.update(GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt")) - pks.update(GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly")) - - 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]]]], - [4.17708, 3.11458], - [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], pks - + return GeomaticTest.setUpDefaultGeoItems(self.user) def scroll(self, element): self.selenium.execute_script( -- cgit v1.2.3