summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/tests.py46
-rw-r--r--archaeological_context_records/tests/UE-test-gpkg.zipbin0 -> 5734 bytes
-rw-r--r--archaeological_context_records/tests/importer-GIS-UE.zipbin0 -> 18198 bytes
-rw-r--r--archaeological_operations/tests.py5
4 files changed, 44 insertions, 7 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 35d1c2478..5b839986e 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -26,6 +26,7 @@ from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import Permission
from django.core.exceptions import ValidationError, ImproperlyConfigured
+from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import tag
from django.test.client import Client
from django.urls import reverse
@@ -34,6 +35,7 @@ from django.utils.translation import pgettext_lazy
from ishtar_common.models import (
IshtarSiteProfile,
ImporterModel,
+ ImporterType,
UserProfile,
ProfileType,
Town,
@@ -41,6 +43,7 @@ from ishtar_common.models import (
get_current_profile,
)
+from ishtar_common import forms_common
from archaeological_operations.tests import OperationInitTest, ImportTest
from archaeological_operations import models as models_ope
from archaeological_context_records import models
@@ -65,7 +68,6 @@ from ishtar_common.tests import (
SeleniumTests,
)
-from archaeological_operations.models import Operation
from archaeological_operations.serializers import operation_serialization
from archaeological_context_records import views, serializers
@@ -76,6 +78,37 @@ if settings.SELENIUM_TEST:
class ImportContextRecordTest(ImportTest, TestCase):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES
+ def test_geo_import(self):
+ root = settings.ROOT_PATH + "../archaeological_context_records/tests/"
+ filename = root + "importer-GIS-UE.zip"
+ self.restore_serialized(filename)
+ imp_type = ImporterType.objects.get(name="GIS - UE")
+ imp_file = open(root + "UE-test-gpkg.zip", "rb")
+ file_dict = {
+ "imported_file": SimpleUploadedFile(imp_file.name, imp_file.read())
+ }
+ post_dict = {
+ "importer_type": imp_type.pk,
+ "name": "cr_geo_import",
+ }
+ form = forms_common.NewImportGISForm(
+ data=post_dict, files=file_dict, user=self.user
+ )
+ self.assertTrue(form.is_valid())
+ impt = form.save(self.ishtar_user)
+ impt.initialize()
+ nb = models.ContextRecord.objects.count()
+ models_ope.Operation.objects.get_or_create(
+ code_patriarche="184440",
+ operation_type=models_ope.OperationType.objects.all()[0])
+ impt.importation()
+ new_nb = 9
+ self.assertEqual(models.ContextRecord.objects.count() - nb, new_nb)
+ new = models.ContextRecord.objects.order_by("-pk").all()[:new_nb]
+ for cr in new:
+ self.assertTrue(cr.main_geodata.point_3d)
+
+
def test_mcc_import_contextrecords(self):
old_nb = models.ContextRecord.objects.count()
mcc, form = self.init_context_record_import()
@@ -199,7 +232,7 @@ class ContextRecordInit(OperationInitTest):
if (
force
or not data.get("operation")
- or not models.Operation.objects.filter(pk=data["operation"].pk).count()
+ or not models_ope.Operation.objects.filter(pk=data["operation"].pk).count()
):
data["operation"] = self.get_default_operation(force=force, user=user)
if (
@@ -214,7 +247,7 @@ class ContextRecordInit(OperationInitTest):
data["history_modifier"] = self.get_default_user()
default.update(data)
- data["operation"] = models.Operation.objects.get(pk=data["operation"].pk)
+ data["operation"] = models_ope.Operation.objects.get(pk=data["operation"].pk)
data["parcel"] = models.Parcel.objects.get(pk=data["parcel"].pk)
self.context_records.append(models.ContextRecord.objects.create(**default))
return self.context_records
@@ -261,7 +294,8 @@ class SerializationTest(GenericSerializationTest, ContextRecordInit, TestCase):
)
self.assertEqual(len(cr_json), 2)
- result_queryset = Operation.objects.filter(uuid=self.operations[0].uuid)
+ result_queryset = models_ope.Operation.objects.filter(
+ uuid=self.operations[0].uuid)
res = self.generic_serialization_test(
serializers.cr_serialization,
no_test=True,
@@ -598,7 +632,7 @@ class ContextRecordQATest(ContextRecordInit, TestCase):
unit = models.Unit.objects.get(label="Anomalie")
parcel = models.Parcel.objects.all().first()
- operation = models.Operation.objects.all()[0]
+ operation = models_ope.Operation.objects.all()[0]
parcel_2 = models.Parcel.objects.create(
operation=operation, town=Town.objects.all()[0],
@@ -633,7 +667,7 @@ class ContextRecordQATest(ContextRecordInit, TestCase):
self.create_context_record(data={"label": "CR 3"})
cr_3 = self.context_records[2]
- operation_2 = models.Operation.objects.all()[1]
+ operation_2 = models_ope.Operation.objects.all()[1]
cr_3.operation = operation_2
parcel_3 = models.Parcel.objects.create(
operation=operation_2, town=Town.objects.all()[0],
diff --git a/archaeological_context_records/tests/UE-test-gpkg.zip b/archaeological_context_records/tests/UE-test-gpkg.zip
new file mode 100644
index 000000000..a62d2d477
--- /dev/null
+++ b/archaeological_context_records/tests/UE-test-gpkg.zip
Binary files differ
diff --git a/archaeological_context_records/tests/importer-GIS-UE.zip b/archaeological_context_records/tests/importer-GIS-UE.zip
new file mode 100644
index 000000000..bd541051e
--- /dev/null
+++ b/archaeological_context_records/tests/importer-GIS-UE.zip
Binary files differ
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 5dd66dc4a..7e8442197 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -52,7 +52,7 @@ from ishtar_common import models_rest
from ishtar_common.admin import update_types_from_source
from ishtar_common.views import document_deletion_steps
from ishtar_common.views_item import get_item, adapt_distant_search
-from ishtar_common.serializers import document_serialization
+from ishtar_common.serializers import document_serialization, restore_serialized
from archaeological_operations import views, serializers
from ishtar_common.models import (
@@ -164,6 +164,9 @@ class ImportTest(object):
self.username, self.password, self.user = create_superuser()
self.ishtar_user = IshtarUser.objects.get(pk=self.user.pk)
+ def restore_serialized(self, filename):
+ restore_serialized(filename)
+
def set_target_key(self, target, key, value, imp=None):
keys = {"target__target": target, "key": key}
if imp: