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 /archaeological_context_records/tests.py | |
parent | 4c56faeaeda75e952b410465aefb0534549dfc95 (diff) | |
download | Ishtar-029eba4c18446c92636ccc1c36ef524a48cbbedf.tar.bz2 Ishtar-029eba4c18446c92636ccc1c36ef524a48cbbedf.zip |
Import: add test for MCC context record import
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 50 |
1 files changed, 49 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): |