summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/tests.py61
-rw-r--r--archaeological_finds/tests/importer-GIS-find.csv2
-rw-r--r--archaeological_finds/tests/importer-GIS-find.zipbin0 -> 9690 bytes
3 files changed, 63 insertions, 0 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index df891e57e..15c54fe0d 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -43,6 +43,7 @@ from ishtar_common.models import (
ProfileType,
ImporterModel,
DocumentTemplate,
+ GeoVectorData
)
from django.utils.text import slugify
from django.utils.translation import pgettext_lazy, gettext_lazy as _
@@ -632,6 +633,66 @@ class ImportFindTest(ImportTest, FindInit, TestCase):
super(ImportFindTest, self).setUp()
self.tmpdir = tempfile.TemporaryDirectory()
+ def test_geo_import_csv(self):
+ self._test_geo_import("importer-GIS-find", 1)
+
+ def _test_geo_import(self, data_name, new_nb):
+ root = settings.ROOT_PATH + "../archaeological_finds/tests/"
+ filename = root + data_name + ".zip"
+ self.restore_serialized(filename)
+ imp_type = ImporterType.objects.get(slug="topographie-mobilier")
+ imp_file = open(root + data_name + ".csv", "rb")
+ file_dict = {
+ "imported_file": SimpleUploadedFile(imp_file.name, imp_file.read())
+ }
+ post_dict = {
+ "importer_type": imp_type.pk,
+ "name": "find_geo_import",
+ "encoding": "utf-8",
+ "skip_lines": 1,
+ "csv_sep": ",",
+ }
+ 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 = GeoVectorData.objects.count()
+ ope, __ = Operation.objects.get_or_create(
+ code_patriarche="GOA",
+ operation_type=OperationType.objects.all()[0])
+ cr, __ = ContextRecord.objects.get_or_create(
+ operation=ope,
+ label="CR"
+ )
+ base_find, __ = models.BaseFind.objects.get_or_create(
+ context_record=cr,
+ label="GOA-528",
+ external_id="GOA-528",
+ auto_external_id=False
+ )
+ #base_find.external_id = "GOA-528"
+ #base_find.auto_external_id = False
+ #base_find.save()
+ base_find = models.BaseFind.objects.get(pk=base_find.pk)
+
+ impt.importation()
+ if impt.error_file:
+ self.assertIsNone(
+ impt.error_file,
+ msg="Error on import. Content of error file: "
+ + impt.error_file.read().decode("utf-8"))
+ self.assertEqual(GeoVectorData.objects.count() - nb, new_nb)
+ new = GeoVectorData.objects.order_by("-pk").all()[:new_nb]
+ for geo in new:
+ self.assertTrue(geo.x)
+ self.assertTrue(geo.y)
+ self.assertTrue(geo.z)
+ self.assertEqual(new[0].x, 352107.689)
+ base_find = models.BaseFind.objects.get(pk=base_find.pk)
+ self.assertEqual(base_find.main_geodata_id, new[0].pk)
+
def test_mcc_import_finds(self):
self.init_context_record()
diff --git a/archaeological_finds/tests/importer-GIS-find.csv b/archaeological_finds/tests/importer-GIS-find.csv
new file mode 100644
index 000000000..e7dd71766
--- /dev/null
+++ b/archaeological_finds/tests/importer-GIS-find.csv
@@ -0,0 +1,2 @@
+Mobilier,Titre,X,Y,Z
+GOA-528,Relevé topographique du mobilier 528,352107.689,6789962.961,200
diff --git a/archaeological_finds/tests/importer-GIS-find.zip b/archaeological_finds/tests/importer-GIS-find.zip
new file mode 100644
index 000000000..92d676c7d
--- /dev/null
+++ b/archaeological_finds/tests/importer-GIS-find.zip
Binary files differ