diff options
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 |
commit | 311c3d5245f46681529d96652efeaa1c9f6a48bf (patch) | |
tree | 6b330beb6ef934dd76eb17cdd46f540c5c99c5e4 /archaeological_operations/tests.py | |
parent | d70b05475f754d0c496180fcd50406ad226b4261 (diff) | |
download | Ishtar-311c3d5245f46681529d96652efeaa1c9f6a48bf.tar.bz2 Ishtar-311c3d5245f46681529d96652efeaa1c9f6a48bf.zip |
Imports: prevent creation of new items when data is empty
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 25 |
1 files changed, 14 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() |