From 053c67a0f57b4ccb2963cb7d366a4276ac2fb371 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 9 Jun 2015 20:52:54 +0200 Subject: Update Makefile sample with updated fixtures --- Makefile.example | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile.example b/Makefile.example index c18917319..29ba7cb56 100644 --- a/Makefile.example +++ b/Makefile.example @@ -45,6 +45,8 @@ fresh_syncdb: '../ishtar_common/fixtures/initial_data-'$(default_data)'.json' 2> /dev/null cd $(project); $(PYTHON) ./manage.py loaddata \ '../ishtar_common/fixtures/initial_towns-'$(default_data)'.json' 2> /dev/null + cd $(project); $(PYTHON) ./manage.py loaddata \ + '../ishtar_common/fixtures/initial_importtypes-'$(default_data)'.json' 2> /dev/null if [[ '$(apps)' == *archaeological_operations* ]]; then cd $(project); $(PYTHON) ./manage.py loaddata \ '../archaeological_operations/fixtures/initial_data-'$(default_data)'.json' 2> /dev/null; fi if [[ '$(apps)' == *archaeological_files* ]]; then cd $(project); $(PYTHON) ./manage.py loaddata \ @@ -93,13 +95,18 @@ schemamigrations: generate_doc: cd $(project);\ - $(PYTHON) manage.py graph_models --pydot -I "ImporterType,ImporterDefault,ImporterDefaultValues,ImporterColumn,Regexp,ImportTarget,FormaterType,Import" ishtar_common > /tmp/ishtar.dot - dot -Tpng /tmp/ishtar.dot -o docs/source/_static/db-imports.png + $(PYTHON) manage.py graph_models --pydot -I "ImporterType,ImporterDefault,ImporterDefaultValues,ImporterColumn,Regexp,ImportTarget,FormaterType,Import" ishtar_common > /tmp/ishtar.dot ;\ + dot -Tpng /tmp/ishtar.dot -o ../docs/source/_static/db-imports.png + cd $(project);\ + for APP in $(apps); do \ + $(PYTHON) manage.py graph_models --pydot $$APP > /tmp/ishtar.dot; \ + dot -Tpng /tmp/ishtar.dot -o ../docs/source/_static/db-$$APP.png; \ + done rm /tmp/ishtar.dot fixtures: fixtures_common fixtures_operations fixtures_archaeological_context_records fixtures_archaeological_finds fixtures_archaeological_warehouse fixtures_archaeological_files -fixtures_common: fixtures_common_importers +fixtures_common: fixtures_common_importers fixtures_common_towns cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 \ ishtar_common.authortype \ ishtar_common.persontype \ @@ -118,13 +125,12 @@ fixtures_common_importers: ishtar_common.formatertype \ > '../ishtar_common/fixtures/initial_importtypes-'$(default_data)'.json' -fixtures_initial_data: +fixtures_common_towns: cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 \ - ishtar_common.authortype \ - ishtar_common.persontype \ - ishtar_common.organizationtype \ - ishtar_common.sourcetype \ - > '../ishtar_common/fixtures/initial_data-'$(default_data)'.json' + ishtar_common.state \ + ishtar_common.department \ + ishtar_common.town \ + > '../ishtar_common/fixtures/initial_towns-'$(default_data)'.json' fixtures_operations: cd $(project); $(PYTHON) ./manage.py dumpdata --indent 4 \ -- cgit v1.2.3 From 417ec036f3645ec7d9542405b6fa2777663d5aad Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 10 Jun 2015 00:33:43 +0200 Subject: Tests: new import mechanism - test MCC operation importer --- archaeological_operations/tests.py | 72 ++++++++++++++++++++++++++++++++------ 1 file 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 -- cgit v1.2.3