summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-16 21:00:08 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-16 21:00:08 +0100
commit5921fedef065a34a97ecdd2ca4353aa72f25b116 (patch)
tree6b330beb6ef934dd76eb17cdd46f540c5c99c5e4 /archaeological_operations
parentcaf19dff2b465a6a43e48bd13cd1610ca4783bb1 (diff)
downloadIshtar-5921fedef065a34a97ecdd2ca4353aa72f25b116.tar.bz2
Ishtar-5921fedef065a34a97ecdd2ca4353aa72f25b116.zip
Imports: prevent creation of new items when data is empty
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/tests.py25
-rw-r--r--archaeological_operations/tests/MCC-operations-example.csv1
2 files changed, 15 insertions, 11 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 296236029..364cc4c8e 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -36,7 +36,7 @@ from archaeological_operations import views
from ishtar_common.models import OrganizationType, Organization, ItemKey, \
ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \
- Town, ImporterColumn
+ Town, ImporterColumn, Person
from archaeological_context_records.models import Unit
from ishtar_common import forms_common
@@ -171,6 +171,7 @@ class ImportOperationTest(ImportTest, TestCase):
def test_mcc_import_operation(self):
first_ope_nb = models.Operation.objects.count()
+ first_person_nb = Person.objects.count()
importer, form = self.init_ope_import()
self.assertTrue(form.is_valid())
impt = form.save(self.ishtar_user)
@@ -184,18 +185,20 @@ class ImportOperationTest(ImportTest, TestCase):
current_ope_nb = models.Operation.objects.count()
# no new operation imported because of a missing connection for
# operation_type value
- self.assertTrue(current_ope_nb == first_ope_nb)
+ self.assertEqual(current_ope_nb, first_ope_nb)
self.init_ope_targetkey(imp=impt)
impt.importation()
- # a new operation has now been imported
+ # new operations have now been imported
current_ope_nb = models.Operation.objects.count()
- self.assertEqual(current_ope_nb, first_ope_nb + 1)
+ self.assertEqual(current_ope_nb, first_ope_nb + 2)
+ current_person_nb = Person.objects.count()
+ self.assertEqual(current_person_nb, first_person_nb + 1)
# and well imported
last_ope = models.Operation.objects.order_by('-pk').all()[0]
self.assertEqual(last_ope.name, u"Oppìdum de Paris")
- self.assertTrue(last_ope.code_patriarche == 4200)
- self.assertTrue(last_ope.operation_type.txt_idx == 'prog_excavation')
+ self.assertEqual(last_ope.code_patriarche, 4200)
+ self.assertEqual(last_ope.operation_type.txt_idx, 'prog_excavation')
self.assertEqual(last_ope.periods.count(), 2)
periods = [period.txt_idx for period in last_ope.periods.all()]
self.assertIn('iron_age', periods)
@@ -239,7 +242,7 @@ class ImportOperationTest(ImportTest, TestCase):
impt.initialize()
self.init_ope_targetkey(imp=impt)
impt.importation()
- self.assertEqual(len(impt.errors), 1)
+ self.assertEqual(len(impt.errors), 2)
self.assertIn("Importer configuration error", impt.errors[0]['error'])
def test_model_limitation(self):
@@ -253,10 +256,10 @@ class ImportOperationTest(ImportTest, TestCase):
init_ope_number = models.Operation.objects.count()
impt.importation()
current_ope_nb = models.Operation.objects.count()
- self.assertEqual(current_ope_nb, init_ope_number + 1)
+ self.assertEqual(current_ope_nb, init_ope_number + 2)
- last_ope = models.Operation.objects.order_by('-pk').all()[0]
- last_ope.delete()
+ for ope in models.Operation.objects.order_by('-pk').all()[:2]:
+ ope.delete()
importer, form = self.init_ope_import()
# add an inadequate model to make created_models non empty
@@ -286,7 +289,7 @@ class ImportOperationTest(ImportTest, TestCase):
# import of operations
impt.importation()
current_ope_nb = models.Operation.objects.count()
- self.assertEqual(current_ope_nb, init_ope_number + 1)
+ self.assertEqual(current_ope_nb, init_ope_number + 2)
def test_mcc_import_parcels(self):
old_nb = models.Parcel.objects.count()
diff --git a/archaeological_operations/tests/MCC-operations-example.csv b/archaeological_operations/tests/MCC-operations-example.csv
index 432ceffca..3b9801c33 100644
--- a/archaeological_operations/tests/MCC-operations-example.csv
+++ b/archaeological_operations/tests/MCC-operations-example.csv
@@ -1,2 +1,3 @@
code OA,region,type operation,intitule operation,operateur,responsable operation,date debut terrain,date fin terrain,chronologie generale,identifiant document georeferencement,notice scientifique
+4201,Bourgogne,Fouille programmée,Oppìdum de Paris 2,L'opérateur,,2000/01/31,2002/12/31,Age du Fer,,
4200,Bourgogne,Fouille programmée,Oppìdum de Paris,L'opérateur,Jean Sui-Resp'on Sablé,2000/01/22,2002/12/31,Age du Fer & Gallo-Romain,,