diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-06-25 02:23:23 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-06-25 02:23:23 +0200 |
commit | 029eba4c18446c92636ccc1c36ef524a48cbbedf (patch) | |
tree | cf77faf5e29c684fd9510911823b27df70d30540 | |
parent | 4c56faeaeda75e952b410465aefb0534549dfc95 (diff) | |
download | Ishtar-029eba4c18446c92636ccc1c36ef524a48cbbedf.tar.bz2 Ishtar-029eba4c18446c92636ccc1c36ef524a48cbbedf.zip |
Import: add test for MCC context record import
-rw-r--r-- | archaeological_context_records/tests.py | 50 | ||||
-rw-r--r-- | archaeological_context_records/tests/MCC-context-records-example.csv | 5 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 5 |
3 files changed, 59 insertions, 1 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index dd3d76d7c..72144b528 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -24,11 +24,59 @@ import json from django.conf import settings from django.core.exceptions import ValidationError +from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase -from archaeological_operations.tests import OperationInitTest +from ishtar_common.models import ImporterType, TargetKey +from archaeological_operations.tests import OperationInitTest, ImportOperationTest from archaeological_operations.models import Parcel from archaeological_context_records import models +from ishtar_common import forms_common + +class ImportContextRecordTest(ImportOperationTest): + test_operations = False + + fixtures = ImportOperationTest.fixtures + [ + settings.ROOT_PATH + + '../archaeological_context_records/fixtures/initial_data-fr.json', + ] + + def testMCCImportContextRecords(self, test=True): + self.testMCCImportOperation(test=False) + self.testMCCImportParcels(test=False) + + old_nb = models.ContextRecord.objects.count() + MCC = ImporterType.objects.get(name=u"MCC - UE") + mcc_file = open(settings.ROOT_PATH + \ + '../archaeological_context_records/tests/MCC-context-records-example.csv', 'rb') + file_dict = {'imported_file': SimpleUploadedFile(mcc_file.name, + mcc_file.read())} + post_dict = {'importer_type':MCC.pk, 'skip_lines':1, + "encoding":'utf-8'} + 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() + + # doing manualy connections + hc = models.Unit.objects.get(txt_idx='not_in_context').pk + #for tg in TargetKey.objects.all(): + # print(tg.target, tg.key) + tg = TargetKey.objects.get(target__target='unit', key='Hors contexte') + tg.value = hc + tg.is_set = True + tg.save() + + impt.importation() + if not test: + return + + # new ues has now been imported + current_nb = models.ContextRecord.objects.count() + self.assertTrue(current_nb == (old_nb + 4)) class ContextRecordInit(OperationInitTest): diff --git a/archaeological_context_records/tests/MCC-context-records-example.csv b/archaeological_context_records/tests/MCC-context-records-example.csv new file mode 100644 index 000000000..fe954ee43 --- /dev/null +++ b/archaeological_context_records/tests/MCC-context-records-example.csv @@ -0,0 +1,5 @@ +code OA,identifiant UE,type,description,interpretation,date ouverture,date fermeture,identifiant parcelle,identifiant document georeferencement,commentaire,nature,chronologie +4200,HC,Hors contexte,UE globale pour cette parcelle,Non-applicable,,,XXXX,,UE virtuelle,, +4200,H.-C.,HC,UE globale pour cette parcelle,NA,,,XXXX,,UE virtuelle,, +4200,XXXXXX,HC,UE globale pour cette parcelle,,,,YY55,,UE virtuelle,, +4200,US17,couche,couche de cendre,comblement,,,YY55,,présence de charbons,,indéterminé diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9abc62bd4..527e10295 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -49,6 +49,7 @@ class ImportOperationTest(TestCase): '../ishtar_common/fixtures/initial_importtypes-fr.json', settings.ROOT_PATH + '../archaeological_operations/fixtures/initial_data-fr.json'] + test_operations = True def setUp(self): self.username, self.password, self.user = create_superuser() @@ -56,6 +57,8 @@ class ImportOperationTest(TestCase): def testMCCImportOperation(self, test=True): # MCC opérations + if self.test_operations == False: + test = False first_ope_nb = models.Operation.objects.count() MCC_OPERATION = ImporterType.objects.get(name=u"MCC - Opérations") mcc_operation_file = open(settings.ROOT_PATH + \ @@ -127,6 +130,8 @@ class ImportOperationTest(TestCase): models.Operation.objects.order_by('-pk').all()[0]) def testMCCImportParcels(self, test=True): + if self.test_operations == False: + test = False self.testMCCImportOperation(test=False) old_nb = models.Parcel.objects.count() MCC_PARCEL = ImporterType.objects.get(name=u"MCC - Parcelles") |