diff options
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 50 |
1 files changed, 45 insertions, 5 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 |