diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-08-07 01:23:16 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-11-16 17:04:41 +0100 |
commit | 1c44b037a372b76262472a7fda1748754fcabc5b (patch) | |
tree | cdccb81282faf9e98bb0c87f2e589977ee08ece4 /archaeological_operations/tests.py | |
parent | 4fd4a7ede4aecc9b77cfeb80b91bb4593c2ba026 (diff) | |
download | Ishtar-1c44b037a372b76262472a7fda1748754fcabc5b.tar.bz2 Ishtar-1c44b037a372b76262472a7fda1748754fcabc5b.zip |
PR for peer review
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 225 |
1 files changed, 203 insertions, 22 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 39fa730f0..d2814a21d 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -19,6 +19,7 @@ import json import datetime +import re from subprocess import Popen, PIPE from io import StringIO, BytesIO import tempfile @@ -37,6 +38,7 @@ from django.utils.text import slugify from django.contrib.auth.models import User, Permission from django.utils.translation import ugettext_lazy as _, pgettext, pgettext_lazy + from . import models from ishtar_common.views import document_deletion_steps @@ -94,7 +96,7 @@ from ishtar_common.tests import ( COMMON_FIXTURES, GenericSerializationTest, WAREHOUSE_FIXTURES, - SearchText, + SearchText, SeleniumTests, ) from ishtar_common.serializers import restore_serialized @@ -193,8 +195,8 @@ class ImportTest(object): # target for this import target = ( TargetKey.objects.filter(target__target="operation_type") - .order_by("-pk") - .all()[0] + .order_by("-pk") + .all()[0] ) target.value = models.OperationType.objects.get(txt_idx="prog_excavation").pk target.is_set = True @@ -299,7 +301,7 @@ class ImportTest(object): mcc = ImporterType.objects.get(name="MCC - UE") mcc_file = open( settings.ROOT_PATH + "../archaeological_context_records/tests/" - "MCC-context-records-example.csv", + "MCC-context-records-example.csv", "rb", ) file_dict = { @@ -1577,12 +1579,12 @@ class ParcelTest(ImportTest, TestCase): self.assertTrue( (values["section"], values["parcel_number"]) in result[year], msg='Section - Parcel number: "%s - %s" is not ' - 'in "%s"' - % ( - values["section"], - values["parcel_number"], - str(result[year]), - ), + 'in "%s"' + % ( + values["section"], + values["parcel_number"], + str(result[year]), + ), ) parcels.pop(parcels.index(values)) result[year].pop( @@ -1593,14 +1595,14 @@ class ParcelTest(ImportTest, TestCase): parcels, [], msg='Parcel(s): "%s" haven\'t be ' - 'recognized in "%s"' % (str(parcels), value), + 'recognized in "%s"' % (str(parcels), value), ) not_imported = [data for data in result.values() if data] self.assertEqual( not_imported, [], msg='Parcel(s): "%s" haven\'t be ' - 'recognized in "%s"' % (str(not_imported), value), + 'recognized in "%s"' % (str(not_imported), value), ) @@ -1910,14 +1912,14 @@ class OperationTest(TestCase, OperationInitTest): operation.save() self.assertIsNotNone(operation.search_vector) for key in ( - "old", - "dirty", - "daisy", - "'2010'", - "zardoz", - "huiaaa5", - "{}42huiaaa5".format(profile.operation_prefix.lower()), - "42huiaaa5", + "old", + "dirty", + "daisy", + "'2010'", + "zardoz", + "huiaaa5", + "{}42huiaaa5".format(profile.operation_prefix.lower()), + "42huiaaa5", ): self.assertIn(key, operation.search_vector) @@ -2080,8 +2082,8 @@ class OperationTest(TestCase, OperationInitTest): f = BytesIO(response.content) filetype = ( Popen("/usr/bin/file -b --mime -", shell=True, stdout=PIPE, stdin=PIPE) - .communicate(f.read(1024))[0] - .strip() + .communicate(f.read(1024))[0] + .strip() ) self.assertTrue(filetype.startswith(b"application/pdf")) @@ -4181,3 +4183,182 @@ class DocumentQATest(OperationInitTest, TestCase): self.assertEqual( models.Document.objects.get(pk=document_1.pk).source_type, source_type ) + + +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': {}, + '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'}, + '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'}, + '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() + 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.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 |