diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-06-10 00:33:43 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-06-10 00:33:43 +0200 |
commit | e2e7eac3654dc1a55c9b2265028ce0cc9975c2e6 (patch) | |
tree | 88ff86b77dfa512f4e12f33d26543587c7765cb3 /archaeological_operations/tests.py | |
parent | da51c492266db2357ca1a57ac6608c2ee41bcd61 (diff) | |
download | Ishtar-e2e7eac3654dc1a55c9b2265028ce0cc9975c2e6.tar.bz2 Ishtar-e2e7eac3654dc1a55c9b2265028ce0cc9975c2e6.zip |
Tests: new import mechanism - test MCC operation importer
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index e854c8763..a8d8e6415 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -23,6 +23,7 @@ Unit tests import json, os, datetime from django.conf import settings +from django.core.files.uploadedfile import SimpleUploadedFile from django.core.management import call_command from django.core.urlresolvers import reverse from django.test import TestCase @@ -32,18 +33,26 @@ from django.contrib.auth.models import User, Permission import models from ishtar_common.models import OrganizationType, Organization, Town, \ - PersonType + PersonType, ImporterType, IshtarUser, TargetKey + +from ishtar_common import forms_common class ImportOperationTest(TestCase): - fixtures = [settings.ROOT_PATH + - '../ishtar_common/fixtures/initial_data.json', + fixtures = [ settings.ROOT_PATH + - '../archaeological_files/fixtures/initial_data.json', + '../fixtures/initial_data-auth-fr.json', + settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data-fr.json', + settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_towns-fr.json', + settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_importtypes-fr.json', settings.ROOT_PATH + '../archaeological_operations/fixtures/initial_data-fr.json'] def setUp(self): self.username, self.password, self.user = create_superuser() + self.ishtar_user = IshtarUser.objects.get(pk=self.user.pk) #def testImportDbfOperation(self): # """ @@ -52,12 +61,55 @@ class ImportOperationTest(TestCase): # call_command('import_operations', os.sep.join([os.getcwd(), '..', # 'archaeological_operations', 'tests', 'sample.dbf'])) - def testImportCsvOperation(self): - """ - Test operation import - """ - call_command('import_operations', os.sep.join([os.getcwd(), '..', - 'archaeological_operations', 'tests', 'sample.csv'])) + #def testImportCsvOperation(self): + # """ + # Test operation import + # """ + # call_command('import_operations', os.sep.join([os.getcwd(), '..', + # 'archaeological_operations', 'tests', 'sample.csv'])) + + def testMCCImports(self): + # MCC opérations + first_ope_nb = models.Operation.objects.count() + MCC_OPERATION = ImporterType.objects.get(name=u"MCC - Opérations") + mcc_operation_file = open(settings.ROOT_PATH + \ + '../archaeological_operations/tests/MCC-operations-example.csv', 'rb') + file_dict = {'imported_file': SimpleUploadedFile(mcc_operation_file.name, + mcc_operation_file.read())} + post_dict = {'importer_type':MCC_OPERATION.pk, 'skip_lines':1} + form = forms_common.NewImportForm(data=post_dict, files=file_dict, + instance=None) + form.is_valid() + 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) + + # 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) + + # doing manualy the connection assuming that the last 'operation_type' + # target is the one we need + tg = TargetKey.objects.filter(target__target='operation_type' + ).order_by('-pk').all()[0] + tg.value = models.OperationType.objects.get(txt_idx='prog_excavation').pk + tg.is_set = True + tg.save() + + impt.importation() + # 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.operation_type.txt_idx == 'prog_excavation') def testParseParcels(self): # the database needs to be initialised before importing |