summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-06-10 00:39:36 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-06-10 00:39:36 +0200
commit032fe5ede7cc937a84b4c7477dabe007a5050e9d (patch)
tree42ad8f4aa1684c5ae922260624496d613a5b9c0a
parentbb8e1fc4dc37703c604ac9d2f62fc2f8351ed8aa (diff)
parente2e7eac3654dc1a55c9b2265028ce0cc9975c2e6 (diff)
downloadIshtar-032fe5ede7cc937a84b4c7477dabe007a5050e9d.tar.bz2
Ishtar-032fe5ede7cc937a84b4c7477dabe007a5050e9d.zip
Merge branch 'stable'
Conflicts: Makefile.example
-rw-r--r--Makefile.example11
-rw-r--r--archaeological_operations/tests.py72
2 files changed, 69 insertions, 14 deletions
diff --git a/Makefile.example b/Makefile.example
index 55638f9dd..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,11 +95,12 @@ 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
+ $(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
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