summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-08-31 16:54:34 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-10-25 12:06:03 +0200
commit2b60ed096578912270e393c1c4e8d7516dea70a7 (patch)
tree74c2c2e97a26b960ed7803db499f2da205bbe718
parent24a7285d40b4268d53bcf4adcdeb88a5186efb2c (diff)
downloadIshtar-2b60ed096578912270e393c1c4e8d7516dea70a7.tar.bz2
Ishtar-2b60ed096578912270e393c1c4e8d7516dea70a7.zip
Tests: clean imports
-rw-r--r--INSTALL.md14
-rw-r--r--Makefile.example19
-rw-r--r--archaeological_context_records/tests.py12
-rw-r--r--archaeological_finds/tests.py5
-rw-r--r--archaeological_operations/tests.py32
-rw-r--r--example_project/settings.py1
-rw-r--r--ishtar_common/tests.py195
7 files changed, 176 insertions, 102 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 0c087a671..0f65978ec 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -49,3 +49,17 @@ cd /srv/ishtar/my_ishtar_instance
./manage.py loaddata /srv/data/towns_norel-fr.json
./manage.py loaddata /srv/data/towns-fr.json
```
+
+Test environment for UI
+-----------------------
+
+```
+pip3 install selenium # eventually from a venv if used
+mkdir -p $HOME/bin/
+cd $HOME/bin/
+wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux32.tar.gz
+tar -xvzf geckodriver-v0.24.0-linux32.tar.gz
+rm geckodriver-v0.24.0-linux32.tar.gz
+chmod +x geckodriver
+export PATH=$PATH:$HOME/bin/geckodriver
+```
diff --git a/Makefile.example b/Makefile.example
index 093ed7406..8bbc4a6af 100644
--- a/Makefile.example
+++ b/Makefile.example
@@ -4,6 +4,7 @@ NB_PROCESS=8
# if a virtualenv is used put the full python path
# e.g.: PYTHON=$$HOME/.virtualenvs/ishtar/bin/python
PYTHON=python3
+PATH=$$PATH:$$HOME/bin/geckodriver
# put name of your current project
project=example_project
# list used apps
@@ -79,8 +80,8 @@ test: clean ## launch tests
cd $(project); $(PYTHON) manage.py test $(apps)
soft_test: clean ## launch tests without database regeneration
- cd $(project); $(PYTHON) manage.py test -k --tag gis $(apps)
- cd $(project); $(PYTHON) manage.py test -k --exclude-tag gis $(apps)
+ cd $(project); $(PYTHON) manage.py test -k --tag gis --exclude-tag ui $(apps)
+ cd $(project); $(PYTHON) manage.py test -k --exclude-tag gis --exclude-tag ui $(apps)
soft_test_multi: clean ## launch multi-process tests without database regeneration
cd $(project); $(PYTHON) manage.py test -k --parallel $(NB_PROCESS) --tag gis $(apps)
@@ -89,12 +90,22 @@ soft_test_multi: clean ## launch multi-process tests without database regenerat
soft_test_verbose: clean ## launch tests without database regeneration - verbose
cd $(project); $(PYTHON) manage.py test -k --verbosity 2 $(apps)
+soft_test_multi: clean ## launch multi-process tests without database regeneration
+ cd $(project); $(PYTHON) manage.py test -k --parallel $(NB_PROCESS) --exclude-tag ui --tag gis $(apps)
+ cd $(project); $(PYTHON) manage.py test -k --parallel $(NB_PROCESS) --exclude-tag ui --exclude-tag gis $(apps)
+
+test_ui: clean ## launch tests for UI
+ cd $(project); $(PYTHON) manage.py test --tag ui $(apps)
+
+soft_test_ui: clean ## launch soft tests for UI
+ cd $(project); $(PYTHON) manage.py test -k --tag ui $(apps)
+
build_gitlab: clean collectstatic ## specific build for gitlab
cd $(project); $(PYTHON) ./manage.py migrate
test_gitlab: build_gitlab ##
- cd $(project); $(PYTHON) manage.py test --tag gis $(apps)
- cd $(project); $(PYTHON) manage.py test --exclude-tag gis $(apps)
+ cd $(project); $(PYTHON) manage.py test --tag gis --exclude-tag ui $(apps)
+ cd $(project); $(PYTHON) manage.py test --exclude-tag gis --exclude-tag ui $(apps)
soft_test_gitlab: build_gitlab
cd $(project); $(PYTHON) manage.py -k test $(apps)
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 85011a7bf..c9171f828 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -22,6 +22,7 @@ import json
from io import StringIO
import locale
+from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import Permission
from django.core.exceptions import ValidationError, ImproperlyConfigured
@@ -68,6 +69,9 @@ from archaeological_operations.models import Operation
from archaeological_operations.serializers import operation_serialization
from archaeological_context_records import views, serializers
+if settings.SELENIUM_TEST:
+ from selenium.webdriver.support.wait import WebDriverWait
+
class ImportContextRecordTest(ImportTest, TestCase):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES
@@ -436,7 +440,9 @@ class ContextRecordTest(ContextRecordInit, TestCase):
def test_downstream_cache_update(self):
cr = self.create_context_record()[0]
- from archaeological_finds.models import Find, BaseFind, MaterialType
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
+ Find = apps.get_model("archaeological_finds", "Find")
+ MaterialType = apps.get_model("archaeological_finds", "MaterialType")
data = {
"label": "Find me a reason",
@@ -1406,7 +1412,7 @@ class SeleniumTestsContextRecords(SeleniumTests):
"features": [geojsons[bf_label]["get_pts"] for bf_label in bf_labels_pts],
}
- self.WebDriverWait(self.selenium, self.waiting_time).until(
+ WebDriverWait(self.selenium, self.waiting_time).until(
lambda driver: driver.find_element_by_xpath(
'//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]'
)
@@ -1466,6 +1472,8 @@ class SeleniumTestsContextRecords(SeleniumTests):
self.assertMap(base, slug_pk)
def test_geo_items(self):
+ if not settings.SELENIUM_TEST:
+ return
geojsons = self.default_geojson()
# from operation
self.access_from_dropdown("operation")
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 1311a72ba..813153318 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -79,6 +79,7 @@ from archaeological_operations.models import Operation, OperationType
from ishtar_common import forms_common
from ishtar_common.tests import (
+ GeomaticTest as BaseGeomaticTest,
WizardTest,
WizardTestFormData as FormData,
TestCase,
@@ -2523,8 +2524,6 @@ class GeomaticTest(FindInit, TestCase):
self.assertEqual(base_find.point_source, "P")
def test_get_geo_items(self):
- from ishtar_common.tests import GeomaticTest as BaseGeomaticTest
-
# profile = models.get_current_profile()
profile = get_current_profile()
profile.mapping = True
@@ -2873,6 +2872,8 @@ class SeleniumTestsBaseFinds(SeleniumTests):
self.assertNotInDOM(get_poly)
def test_geo_items(self):
+ if not settings.SELENIUM_TEST:
+ return
geojsons = self.default_geojson()
# from operation
self.access_from_dropdown("operation")
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 4112fc91b..b9326fa22 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -79,7 +79,6 @@ from ishtar_common.models import (
Regexp,
)
from archaeological_files.models import File, FileType
-from archaeological_context_records.models import Unit, ContextRecord
from ishtar_common import forms_common
from ishtar_common.tests import (
@@ -101,6 +100,9 @@ from ishtar_common.tests import (
)
from ishtar_common.serializers import restore_serialized
+if settings.SELENIUM_TEST:
+ from selenium.webdriver.support.wait import WebDriverWait
+
class FileInit(object):
def login_as_superuser(self):
@@ -322,6 +324,7 @@ class ImportTest(object):
return mcc, form
def init_cr_targetkey(self, imp):
+ Unit = apps.get_model("archaeological_context_records", "Unit")
hc = Unit.objects.get(txt_idx="not_in_context").pk
self.set_target_key("unit", "hc", hc, imp=imp)
self.set_target_key("unit", "hors-contexte", hc, imp=imp)
@@ -1759,6 +1762,9 @@ class OperationTest(TestCase, OperationInitTest):
self.operations += self.create_operation(self.alt_user, self.orgas[0])
self.item = self.operations[0]
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
for idx in range(15):
ContextRecord.objects.create(label="CR-{}".format(idx), operation=self.item)
@@ -1929,17 +1935,20 @@ class OperationTest(TestCase, OperationInitTest):
init_parcel = self.create_parcel()[0]
operation.parcels.add(init_parcel)
- from archaeological_context_records.models import ContextRecord
-
cr_data = {
"label": "Context record",
"operation": operation,
"parcel": init_parcel,
"history_modifier": self.get_default_user(),
}
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
cr = ContextRecord.objects.create(**cr_data)
- from archaeological_finds.models import BaseFind, Find, MaterialType
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
+ Find = apps.get_model("archaeological_finds", "Find")
+ MaterialType = apps.get_model("archaeological_finds", "MaterialType")
bf_data = {
"label": "Base find",
@@ -2234,6 +2243,10 @@ class OperationTest(TestCase, OperationInitTest):
WarehouseType = apps.get_model("archaeological_warehouse", "WarehouseType")
Container = apps.get_model("archaeological_warehouse", "Container")
ContainerType = apps.get_model("archaeological_warehouse", "ContainerType")
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
+ Unit = apps.get_model("archaeological_context_records", "Unit")
operation = self.operations[0]
hc, __ = Unit.objects.get_or_create(txt_idx="not-in-context", order=10)
cr = ContextRecord.objects.create(operation=operation, unit=hc)
@@ -3456,7 +3469,9 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase):
operation2.operation_code = 42
operation2.save()
- from archaeological_context_records.models import ContextRecord
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
cr_data = {
"label": "Context record",
@@ -3555,6 +3570,9 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase):
operation.parcels.count(), test_object.parcel_number + 1
)
# update the external id on update
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
cr = ContextRecord.objects.get(pk=self.cr.pk)
test_object.assertEqual(cr.external_id, "codeope42-12345-A1-Context record")
@@ -4230,7 +4248,7 @@ class SeleniumTestsOperations(SeleniumTests):
ope_base = geojsons[label]["get_polys"]
- self.WebDriverWait(self.selenium, self.waiting_time).until(
+ WebDriverWait(self.selenium, self.waiting_time).until(
lambda driver: driver.find_element_by_xpath(
'//dl[@class="col-12"]/dt[@id="display-geo-items-for-' + slug_pk + '"]'
)
@@ -4331,6 +4349,8 @@ class SeleniumTestsOperations(SeleniumTests):
self.assertMap(ope_base, slug_pk)
def test_geo_items(self):
+ if not settings.SELENIUM_TEST:
+ return
geojsons = self.default_geojson()
slug = "operation"
self.access_from_dropdown(slug)
diff --git a/example_project/settings.py b/example_project/settings.py
index b288992a4..34ea5f6c7 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -295,6 +295,7 @@ MAX_UPLOAD_SIZE = 100 # in Mo
DOT_BINARY = "/usr/bin/dot"
TEST_RUNNER = "ishtar_common.tests.ManagedModelTestRunner"
+SELENIUM_TEST = False
CELERY_BROKER_URL = ""
SENTRY_ID = None
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 08b28d8de..50ccf1738 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -19,12 +19,14 @@
from bs4 import BeautifulSoup as Soup
import re
import csv
+import copy
import datetime
import importlib
import io
import json
import os
import shutil
+import sys
import tempfile
from time import time
import zipfile
@@ -37,6 +39,7 @@ from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
+from django.contrib.gis.geos import GEOSGeometry
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.files import File as DjangoFile
@@ -85,7 +88,12 @@ from ishtar_common.tasks import launch_export
from ishtar_common import utils_secretary
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
-from selenium.webdriver.firefox.webdriver import WebDriver
+
+if settings.SELENIUM_TEST:
+ from selenium.webdriver.firefox.webdriver import WebDriver
+ from selenium.webdriver.support.wait import WebDriverWait
+ from selenium.webdriver.common.by import By
+ from selenium.webdriver.support import expected_conditions as EC
COMMON_FIXTURES = [
@@ -245,8 +253,7 @@ class CommandsTestCase(TestCase):
"""
Clean ishtar db
"""
- from archaeological_operations.models import Parcel
-
+ Parcel = apps.get_model("archaeological_operations", "Parcel")
p = Parcel.objects.create(
town=models.Town.objects.create(name="test", numero_insee="25000"),
)
@@ -454,8 +461,6 @@ class ManagedModelTestRunner(DiscoverRunner):
test_runner = TimedTextTestRunner
def setup_test_environment(self, *args, **kwargs):
- from django.apps import apps
-
self.unmanaged_models = [m for m in apps.get_models() if not m._meta.managed]
for m in self.unmanaged_models:
m._meta.managed = True
@@ -793,28 +798,18 @@ class SerializationTest(GenericSerializationTest, TestCase):
fixtures = COMMON_FIXTURES + WAREHOUSE_FIXTURES
def create_types(self):
- from archaeological_finds.models import (
- MaterialTypeQualityType,
- ObjectTypeQualityType,
- AlterationType,
- AlterationCauseType,
- TreatmentEmergencyType,
- CommunicabilityType,
- FunctionalArea,
- )
- from archaeological_operations.models import CulturalAttributionType
-
- for model in (
- models.LicenseType,
- MaterialTypeQualityType,
- ObjectTypeQualityType,
- AlterationType,
- AlterationCauseType,
- TreatmentEmergencyType,
- CommunicabilityType,
- CulturalAttributionType,
- FunctionalArea,
+ for app, model_name in (
+ ("ishtar_common", "LicenseType"),
+ ("archaeological_finds", "MaterialTypeQualityType"),
+ ("archaeological_finds", "ObjectTypeQualityType"),
+ ("archaeological_finds", "AlterationType"),
+ ("archaeological_finds", "AlterationCauseType"),
+ ("archaeological_finds", "TreatmentEmergencyType"),
+ ("archaeological_finds", "CommunicabilityType"),
+ ("archaeological_operations", "CulturalAttributionType"),
+ ("archaeological_finds", "FunctionalArea"),
):
+ model = apps.get_model(app, model_name)
model.objects.create(txt_idx="test", label="Test")
def test_type_serialization(self):
@@ -902,24 +897,30 @@ class SerializationTest(GenericSerializationTest, TestCase):
def create_document_default(self):
super(SerializationTest, self).create_document_default()
- from archaeological_operations.models import (
- Operation,
- ArchaeologicalSite,
- OperationType,
- )
- from archaeological_context_records.models import ContextRecord
- from archaeological_finds.models import Find, BaseFind
- from archaeological_warehouse.models import (
- Warehouse,
- Container,
- ContainerLocalisation,
- WarehouseDivision,
- WarehouseDivisionLink,
- WarehouseType,
- ContainerType,
- )
-
- operation_type = OperationType.objects.all()[0]
+ Operation = apps.get_model("archaeological_operations", "Operation")
+ ArchaeologicalSite = apps.get_model(
+ "archaeological_operations", "ArchaeologicalSite"
+ )
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
+ Find = apps.get_model("archaeological_finds", "Find")
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
+ Warehouse = apps.get_model("archaeological_warehouse", "Warehouse")
+ WarehouseDivision = apps.get_model(
+ "archaeological_warehouse", "WarehouseDivision"
+ )
+ WarehouseDivisionLink = apps.get_model(
+ "archaeological_warehouse", "WarehouseDivisionLink"
+ )
+ WarehouseType = apps.get_model("archaeological_warehouse", "WarehouseType")
+ ContainerType = apps.get_model("archaeological_warehouse", "ContainerType")
+ Container = apps.get_model("archaeological_warehouse", "Container")
+ ContainerLocalisation = apps.get_model(
+ "archaeological_warehouse", "ContainerLocalisation"
+ )
+
+ operation_type = models.OperationType.objects.all()[0]
dct = {
"year": 2010,
"operation_type_id": operation_type.pk,
@@ -1019,7 +1020,10 @@ class SerializationTest(GenericSerializationTest, TestCase):
docs = json.loads(res[("documents", "ishtar_common__Document")])
self.assertEqual(len(docs), 12)
- from archaeological_operations.models import Operation, ArchaeologicalSite
+ Operation = apps.get_model("archaeological_operations", "Operation")
+ ArchaeologicalSite = apps.get_model(
+ "archaeological_operations", "ArchaeologicalSite"
+ )
result_queryset = Operation.objects.filter(code_patriarche="66666")
res = self.generic_serialization_test(
@@ -1041,7 +1045,9 @@ class SerializationTest(GenericSerializationTest, TestCase):
docs = json.loads(res[("documents", "ishtar_common__Document")])
self.assertEqual(len(docs), 6)
- from archaeological_context_records.models import ContextRecord
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
result_queryset = ContextRecord.objects.filter(
id=ContextRecord.objects.all()[0].id
@@ -1054,7 +1060,7 @@ class SerializationTest(GenericSerializationTest, TestCase):
docs = json.loads(res[("documents", "ishtar_common__Document")])
self.assertEqual(len(docs), 6)
- from archaeological_finds.models import Find
+ Find = apps.get_model("archaeological_finds", "Find")
result_queryset = Find.objects.filter(id=Find.objects.all()[0].id)
res = self.generic_serialization_test(
@@ -1065,7 +1071,7 @@ class SerializationTest(GenericSerializationTest, TestCase):
docs = json.loads(res[("documents", "ishtar_common__Document")])
self.assertEqual(len(docs), 6)
- from archaeological_warehouse.models import Warehouse
+ Warehouse = apps.get_model("archaeological_warehouse", "Warehouse")
result_queryset = Warehouse.objects.filter(id=Warehouse.objects.all()[0].id)
res = self.generic_serialization_test(
@@ -1100,8 +1106,8 @@ class SerializationTest(GenericSerializationTest, TestCase):
restore_serialized(zip_filename)
def test_type_restore(self):
- from archaeological_context_records.models import RelationType as CRRT
- from archaeological_operations.models import RelationType as OperationRT
+ CRRT = apps.get_model("archaeological_context_records", "RelationType")
+ OperationRT = apps.get_model("archaeological_operations", "RelationType")
cr_rel_type_nb = CRRT.objects.count()
ope_rel_type_nb = OperationRT.objects.count()
@@ -1992,9 +1998,9 @@ class ShortMenuTest(TestCase):
def _create_ope(self, user=None):
if not user:
user = self.other_user
- from archaeological_operations.models import Operation, OperationType
+ Operation = apps.get_model("archaeological_operations", "Operation")
- ope_type, created = OperationType.objects.get_or_create(label="test")
+ ope_type, created = models.OperationType.objects.get_or_create(label="test")
idx = 1
while Operation.objects.filter(code_patriarche=str(idx)).count():
idx += 1
@@ -2075,7 +2081,8 @@ class ShortMenuTest(TestCase):
self.assertTrue(str(ope.cached_label) in response.content.decode())
def testFile(self):
- from archaeological_files.models import File, FileType
+ File = apps.get_model("archaeological_files", "File")
+ FileType = apps.get_model("archaeological_files", "FileType")
c = Client()
c.login(username=self.username, password=self.password)
@@ -2113,8 +2120,10 @@ class ShortMenuTest(TestCase):
self.assertFalse(str(fle.cached_label) in response.content.decode())
def _create_cr(self):
- from archaeological_context_records.models import ContextRecord
- from archaeological_operations.models import Parcel
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
+ Parcel = apps.get_model("archaeological_operations", "Parcel")
ope = self._create_ope()
town = models.Town.objects.create()
@@ -2164,7 +2173,8 @@ class ShortMenuTest(TestCase):
self.assertTrue(str(cr.cached_label) in response.content.decode())
def _create_find(self):
- from archaeological_finds.models import BaseFind, Find
+ Find = apps.get_model("archaeological_finds", "Find")
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
cr = self._create_cr()
base_find = BaseFind.objects.create(context_record=cr)
@@ -2211,7 +2221,7 @@ class ShortMenuTest(TestCase):
def testBasket(self):
c = Client()
c.login(username=self.username, password=self.password)
- from archaeological_finds.models import FindBasket
+ FindBasket = apps.get_model("archaeological_finds", "FindBasket")
basket = FindBasket.objects.create(
label="My basket",
@@ -2232,7 +2242,8 @@ class ShortMenuTest(TestCase):
def test_treatment_file(self):
c = Client()
c.login(username=self.username, password=self.password)
- from archaeological_finds.models import TreatmentFile, TreatmentFileType
+ TreatmentFile = apps.get_model("archaeological_finds", "TreatmentFile")
+ TreatmentFileType = apps.get_model("archaeological_finds", "TreatmentFileType")
tf = TreatmentFile.objects.create(
type=TreatmentFileType.objects.create(), year=2050
@@ -2267,7 +2278,8 @@ class ShortMenuTest(TestCase):
self.assertFalse(str(tf.cached_label) in response.content.decode())
def _create_treatment(self):
- from archaeological_finds.models import Treatment, TreatmentState
+ Treatment = apps.get_model("archaeological_finds", "Treatment")
+ TreatmentState = apps.get_model("archaeological_finds", "TreatmentState")
completed, created = TreatmentState.objects.get_or_create(
txt_idx="completed", defaults={"executed": True, "label": "Done"}
@@ -2367,7 +2379,7 @@ class ShortMenuTest(TestCase):
def test_basket_is_current_item(self):
c = Client()
c.login(username=self.username, password=self.password)
- from archaeological_finds.models import FindBasket
+ FindBasket = apps.get_model("archaeological_finds", "FindBasket")
basket = FindBasket.objects.create(label="My basket", user=self.user.ishtaruser)
session = c.session
@@ -2720,8 +2732,8 @@ class GeomaticTest(TestCase):
def save(self, *args, **kwargs):
pass
- srs = models.SpatialReferenceSystem.objects.create(
- label="WGS84", txt_idx="wgs84", srid=4326
+ srs, __ = models.SpatialReferenceSystem.objects.get_or_create(
+ srid=4326, defaults={"label": "WGS84", "txt_idx": "wgs84"}
)
obj = FakeGeomaticObject(x=2, y=3, z=4, spatial_reference_system=srs)
self.assertIsNone(obj.point_2d)
@@ -2731,13 +2743,14 @@ class GeomaticTest(TestCase):
@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
+ Operation = apps.get_model("archaeological_operations", "Operation")
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
+ Find = apps.get_model("archaeological_finds", "Find")
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
- wgs84 = SpatialReferenceSystem.objects.get(srid=4326)
+ wgs84 = models_common.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)))"
@@ -2921,8 +2934,7 @@ class GeomaticTest(TestCase):
self.assertEqual((round(item.x, 5), round(item.y, 5)), geom[1].coords)
def test_setUpDefaultGeoItems(self):
- from django.contrib.gis.geos import GEOSGeometry
- from archaeological_operations.models import Operation
+ Operation = apps.get_model("archaeological_operations", "Operation")
username, password, user = create_superuser()
base_geoms, pks = self.setUpDefaultGeoItems(user)
@@ -2983,10 +2995,11 @@ class GeomaticTest(TestCase):
@staticmethod
def geojson_geo_items(geoms, pks, test_get_geo_items=False):
- from archaeological_operations.models import Operation
- from archaeological_context_records.models import ContextRecord
- from archaeological_finds.models import BaseFind
- import copy
+ Operation = apps.get_model("archaeological_operations", "Operation")
+ ContextRecord = apps.get_model(
+ "archaeological_context_records", "ContextRecord"
+ )
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
cache_dics_t, cache_dics_f = {}, {}
res = {}
@@ -3578,12 +3591,11 @@ class TemplateGenerationTest(TestCase):
@tag("ui")
class SeleniumTests(StaticLiveServerTestCase):
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support import expected_conditions as EC
-
@classmethod
def setUpClass(cls):
+ if not settings.SELENIUM_TEST:
+ sys.stdout.write("UI test not activated. Set SELENIUM_TEST to True.")
+ return
super().setUpClass()
cls.waiting_time = 20
cls.selenium = WebDriver()
@@ -3591,10 +3603,15 @@ class SeleniumTests(StaticLiveServerTestCase):
@classmethod
def tearDownClass(cls):
+ if not settings.SELENIUM_TEST:
+ return
cls.selenium.quit()
super().tearDownClass()
def setUp(self):
+ if not settings.SELENIUM_TEST:
+ return
+
# profile
profile = models.get_current_profile()
profile.mapping = True
@@ -3607,7 +3624,7 @@ class SeleniumTests(StaticLiveServerTestCase):
# login
self.username, self.password, self.user = create_superuser()
self.selenium.get("%s%s" % (self.live_server_url, "/accounts/login/"))
- self.WebDriverWait(self.selenium, self.waiting_time).until(
+ WebDriverWait(self.selenium, self.waiting_time).until(
lambda driver: driver.find_element_by_name("username")
)
username_input = self.selenium.find_element_by_name("username")
@@ -3619,6 +3636,8 @@ class SeleniumTests(StaticLiveServerTestCase):
).click()
def setUpDefaultGeoItems(self):
+ if not settings.SELENIUM_TEST:
+ return
return GeomaticTest.setUpDefaultGeoItems(self.user)
def default_geojson(self):
@@ -3634,8 +3653,8 @@ class SeleniumTests(StaticLiveServerTestCase):
)
def wait_and_click(self, xpath):
- self.WebDriverWait(self.selenium, self.waiting_time).until(
- self.EC.visibility_of_element_located((self.By.XPATH, xpath))
+ WebDriverWait(self.selenium, self.waiting_time).until(
+ EC.visibility_of_element_located((By.XPATH, xpath))
)
el = self.selenium.find_element_by_xpath(xpath)
self.scroll(el)
@@ -3681,8 +3700,8 @@ class SeleniumTests(StaticLiveServerTestCase):
else:
xpath += slug_pk[4:] + '")]'
xpath += '/p/small[@title="ID interne" or @title="Internal ID"]'
- self.WebDriverWait(self.selenium, self.waiting_time).until(
- self.EC.visibility_of_element_located((self.By.XPATH, xpath))
+ WebDriverWait(self.selenium, self.waiting_time).until(
+ EC.visibility_of_element_located((By.XPATH, xpath))
)
label = self.selenium.find_element_by_xpath(xpath).text
if slug_pk[:3] == "ope":
@@ -3700,8 +3719,8 @@ class SeleniumTests(StaticLiveServerTestCase):
def assertNotInDOM(self, xpath):
self.selenium.implicitly_wait(self.waiting_time / 10)
try:
- self.WebDriverWait(self.selenium, self.waiting_time / 10).until(
- self.EC.visibility_of_element_located((self.By.XPATH, xpath))
+ WebDriverWait(self.selenium, self.waiting_time / 10).until(
+ EC.visibility_of_element_located((By.XPATH, xpath))
)
found = True
except:
@@ -3723,9 +3742,9 @@ class SeleniumTests(StaticLiveServerTestCase):
id = int(re.search(r"\d+$", mapid).group())
# TODO: use the map and not the map_features in the js function
if features_collecs:
- self.WebDriverWait(self.selenium, self.waiting_time).until(
- self.EC.visibility_of_element_located(
- (self.By.ID, "http-geo-items-ready-" + slug_pk)
+ WebDriverWait(self.selenium, self.waiting_time).until(
+ EC.visibility_of_element_located(
+ (By.ID, "http-geo-items-ready-" + slug_pk)
)
)
base_features, geo_items_feats = self.selenium.execute_script(