summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
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>2022-07-08 09:58:48 +0200
commit313aefcf470df2fe3ad660e568aa8cac308dfcae (patch)
tree2e0ba9944cdc7d9d243cc65c513f772ffe7d937a /archaeological_operations/tests.py
parent6a8dc71f4381c5b6b78dc23105ec5cdc3dc64dfb (diff)
downloadIshtar-313aefcf470df2fe3ad660e568aa8cac308dfcae.tar.bz2
Ishtar-313aefcf470df2fe3ad660e568aa8cac308dfcae.zip
PR for peer review
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py225
1 files changed, 203 insertions, 22 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index d579b2b6c..88044b4f2 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
@@ -95,7 +97,7 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
GenericSerializationTest,
WAREHOUSE_FIXTURES,
- SearchText,
+ SearchText, SeleniumTests,
)
from ishtar_common.serializers import restore_serialized
@@ -194,8 +196,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
@@ -300,7 +302,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 = {
@@ -1600,12 +1602,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(
@@ -1616,14 +1618,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),
)
@@ -1933,14 +1935,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)
@@ -2103,8 +2105,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"))
@@ -4236,3 +4238,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