diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-04-22 18:20:06 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:00 +0100 |
commit | 390c17123f51a2face7eac47c974b6083e9b0664 (patch) | |
tree | e5fbc3fe8285972296d0a173704e9f5ed5ee868e /archaeological_context_records/tests.py | |
parent | 810cf25c85cd44fe1610db4792693983a81c8818 (diff) | |
download | Ishtar-390c17123f51a2face7eac47c974b6083e9b0664.tar.bz2 Ishtar-390c17123f51a2face7eac47c974b6083e9b0664.zip |
Geodata: test gpkg import
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 46 |
1 files changed, 40 insertions, 6 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], |