diff options
-rw-r--r-- | archaeological_operations/tests.py | 50 | ||||
-rw-r--r-- | archaeological_operations/tests/MCC-operations-example.csv | 2 | ||||
-rw-r--r-- | archaeological_operations/tests/MCC-parcelles-example.csv | 4 | ||||
-rw-r--r-- | ishtar_common/models.py | 1 |
4 files changed, 48 insertions, 9 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9807e1b87..2ec79279e 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -54,7 +54,7 @@ class ImportOperationTest(TestCase): self.username, self.password, self.user = create_superuser() self.ishtar_user = IshtarUser.objects.get(pk=self.user.pk) - def testMCCImports(self): + def testMCCImportOperation(self, test=True): # MCC opérations first_ope_nb = models.Operation.objects.count() MCC_OPERATION = ImporterType.objects.get(name=u"MCC - Opérations") @@ -66,19 +66,22 @@ class ImportOperationTest(TestCase): form = forms_common.NewImportForm(data=post_dict, files=file_dict, instance=None) form.is_valid() - self.assertTrue(form.is_valid()) + if test: + self.assertTrue(form.is_valid()) impt = form.save(self.ishtar_user) target_key_nb = TargetKey.objects.count() impt.initialize() # new key have to be set - self.assertTrue(TargetKey.objects.count() > target_key_nb) + if test: + self.assertTrue(TargetKey.objects.count() > target_key_nb) # first try to import impt.importation() 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) + if test: + self.assertTrue(current_ope_nb == first_ope_nb) # doing manualy connections tg = TargetKey.objects.filter(target__target='operation_type' @@ -100,12 +103,14 @@ class ImportOperationTest(TestCase): target.save() impt.importation() + if not test: + return # a new operation has now been imported current_ope_nb = models.Operation.objects.count() self.assertTrue(current_ope_nb == (first_ope_nb + 1)) # and well imported last_ope = models.Operation.objects.order_by('-pk').all()[0] - self.assertTrue(last_ope.code_patriarche == 4000) + self.assertTrue(last_ope.code_patriarche == 4200) self.assertTrue(last_ope.operation_type.txt_idx == 'prog_excavation') self.assertEqual(last_ope.periods.count(), 2) periods = last_ope.periods.all() @@ -118,6 +123,41 @@ class ImportOperationTest(TestCase): self.assertTrue(last_ope == models.Operation.objects.order_by('-pk').all()[0]) + def testMCCImportParcels(self, test=True): + self.testMCCImportOperation(test=False) + old_nb = models.Parcel.objects.count() + MCC_PARCEL = ImporterType.objects.get(name=u"MCC - Parcelles") + mcc_file = open(settings.ROOT_PATH + \ + '../archaeological_operations/tests/MCC-parcelles-example.csv', 'rb') + file_dict = {'imported_file': SimpleUploadedFile(mcc_file.name, + mcc_file.read())} + post_dict = {'importer_type':MCC_PARCEL.pk, 'skip_lines':1} + form = forms_common.NewImportForm(data=post_dict, files=file_dict, + instance=None) + form.is_valid() + if test: + self.assertTrue(form.is_valid()) + impt = form.save(self.ishtar_user) + impt.initialize() + impt.importation() + if not test: + return + # new parcels has now been imported + current_nb = models.Parcel.objects.count() + self.assertTrue(current_nb == (old_nb + 2)) + # and well imported + last_parcels = models.Parcel.objects.order_by('-pk').all()[0:2] + external_ids = sorted(['XXXX', 'YYYY']) + parcel_numbers = sorted(['42', '55']) + sections = sorted(['ZX', 'YY']) + self.assertEqual(external_ids, + sorted([p.external_id for p in last_parcels])) + self.assertEqual(parcel_numbers, + sorted([p.parcel_number for p in last_parcels])) + self.assertEqual(sections, + sorted([p.section for p in last_parcels])) + + def testParseParcels(self): # the database needs to be initialised before importing from archaeological_operations.import_from_csv import parse_parcels diff --git a/archaeological_operations/tests/MCC-operations-example.csv b/archaeological_operations/tests/MCC-operations-example.csv index fa701aacb..4962c0969 100644 --- a/archaeological_operations/tests/MCC-operations-example.csv +++ b/archaeological_operations/tests/MCC-operations-example.csv @@ -1,2 +1,2 @@ code OA,region,type operation,intitule operation,operateur,responsable operation,date debut terrain,date fin terrain,chronologie generale,identifiant document georeferencement,notice scientifique -4000,Bourgogne,Fouille programmée,Oppidum de Paris,L'opérateur,Jean Sui-Resp'on Sablé,2000/01/22,2002/12/31,Age du Fer & Gallo-Romain,, +4200,Bourgogne,Fouille programmée,Oppidum de Paris,L'opérateur,Jean Sui-Resp'on Sablé,2000/01/22,2002/12/31,Age du Fer & Gallo-Romain,, diff --git a/archaeological_operations/tests/MCC-parcelles-example.csv b/archaeological_operations/tests/MCC-parcelles-example.csv index 18b293ca0..1c8d74a2d 100644 --- a/archaeological_operations/tests/MCC-parcelles-example.csv +++ b/archaeological_operations/tests/MCC-parcelles-example.csv @@ -1,3 +1,3 @@ code OA,identifiant parcelle,numero parcelle,section cadastre,annee cadastre,nom commune,numero INSEE commune,nom departement,lieu dit adresse -4801,7,,,,Paris,75101,Ile-de-France,1 rue de l'Église -4801,9,,,,Lille,59350,Nord,Patis du tertre +4200,XXXX,42,ZX,,Paris,75101,Ile-de-France,1 rue de l'Église +4200,YYYY,55,YY,,Lille,59350,Nord,Patis du tertre diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 55b28d4f7..a23808c73 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1471,7 +1471,6 @@ class Import(models.Model): self.save() def get_all_imported(self): - print(dir(self._meta)) imported = [] for related, zorg in self._meta.get_all_related_m2m_objects_with_model(): accessor = related.get_accessor_name() |