summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-01 18:39:22 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-01 18:39:22 +0200
commit04bee0bb526a65798522a9993c4e5d879dfb86c7 (patch)
tree66e611e3035ee4a5fc84ef0b790fabfac3a47a9d /archaeological_operations
parent19776a723d63dd8b4acb41ea2e7294a6513eac15 (diff)
downloadIshtar-04bee0bb526a65798522a9993c4e5d879dfb86c7.tar.bz2
Ishtar-04bee0bb526a65798522a9993c4e5d879dfb86c7.zip
Imports: fix target dict initialization
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/tests.py64
-rw-r--r--archaeological_operations/tests/MCC-operations-example.csv2
2 files changed, 53 insertions, 13 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 4828564d0..777ffbf9c 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -36,7 +36,7 @@ from archaeological_operations import views
from ishtar_common.models import OrganizationType, Organization, ItemKey, \
ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \
Town, ImporterColumn, Person, Author, SourceType, AuthorType, \
- DocumentTemplate, PersonType
+ DocumentTemplate, PersonType, TargetKeyGroup
from archaeological_files.models import File, FileType
from archaeological_context_records.models import Unit
@@ -114,8 +114,10 @@ class ImportTest(object):
'rb')
file_dict = {'imported_file': SimpleUploadedFile(
mcc_operation_file.name, mcc_operation_file.read())}
+ group, c = TargetKeyGroup.objects.get_or_create(name="My group")
post_dict = {'importer_type': mcc_operation.pk, 'skip_lines': 1,
- "encoding": 'utf-8', "name": 'init_ope_import'}
+ "encoding": 'utf-8', "name": 'init_ope_import',
+ "associated_group": group.pk}
form = forms_common.NewImportForm(data=post_dict, files=file_dict,
user=self.user)
form.is_valid()
@@ -123,6 +125,8 @@ class ImportTest(object):
def init_ope_targetkey(self, imp):
# doing manually connections
+
+ # target for this import
target = TargetKey.objects.filter(
target__target='operation_type').order_by('-pk').all()[0]
target.value = models.OperationType.objects.get(
@@ -131,22 +135,44 @@ class ImportTest(object):
target.associated_import = imp
target.save()
- target2 = TargetKey.objects.get(key='gallo-romain',
- associated_import=imp)
+ # target for all users
+ target2 = TargetKey.objects.get(key='gallo-romain')
gallo = models.Period.objects.get(txt_idx='gallo-roman')
target2.value = gallo.pk
target2.is_set = True
- target2.associated_import = imp
+ target2.associated_import = None
target2.save()
- target3 = TargetKey.objects.get(key='age-du-fer',
- associated_import=imp)
+ # target for this user
+ target3 = TargetKey.objects.get(key='age-du-fer')
iron = models.Period.objects.get(txt_idx='iron_age')
target3.value = iron.pk
target3.is_set = True
- target3.associated_import = imp
+ target3.associated_import = None
+ target3.associated_user = self.ishtar_user
target3.save()
- return [target, target2, target3]
+
+ # target for another user
+ username, password, user = create_user()
+ another_user = IshtarUser.objects.get(pk=user.pk)
+ target4 = TargetKey.objects.get(key='neolithique')
+ neo = models.Period.objects.get(txt_idx='neolithic')
+ target4.value = neo.pk
+ target4.is_set = True
+ target4.associated_import = None
+ target4.associated_user = another_user
+ target4.save()
+
+ # target for the current group
+ target5 = TargetKey.objects.get(key='moderne')
+ modern = models.Period.objects.get(txt_idx='modern')
+ target5.value = modern.pk
+ target5.is_set = True
+ target5.associated_import = None
+ target5.associated_group = imp.associated_group
+ target5.save()
+
+ return [target, target2, target3, target4, target5]
def init_ope(self):
importer, form = self.init_ope_import()
@@ -212,8 +238,11 @@ class ImportOperationTest(ImportTest, TestCase):
fixtures = OPERATION_TOWNS_FIXTURES
def test_mcc_import_operation(self):
- first_ope_nb = models.Operation.objects.count()
+ create_user() # create it before import to have a relevant person
+ # number
first_person_nb = Person.objects.count()
+ first_ope_nb = models.Operation.objects.count()
+
importer, form = self.init_ope_import()
self.assertTrue(form.is_valid())
impt = form.save(self.ishtar_user)
@@ -241,10 +270,13 @@ class ImportOperationTest(ImportTest, TestCase):
self.assertEqual(last_ope.name, u"Oppìdum de Paris")
self.assertEqual(last_ope.code_patriarche, '4200')
self.assertEqual(last_ope.operation_type.txt_idx, 'prog_excavation')
- self.assertEqual(last_ope.periods.count(), 2)
+
+ self.assertEqual(last_ope.periods.count(), 3)
periods = [period.txt_idx for period in last_ope.periods.all()]
self.assertIn('iron_age', periods)
self.assertIn('gallo-roman', periods)
+ # target key set for another user
+ self.assertNotIn('neolithic', periods)
# a second importation will be not possible: no two same patriarche
# code
@@ -256,7 +288,7 @@ class ImportOperationTest(ImportTest, TestCase):
self.init_ope_import('MCC-operations-example-bad-encoding.csv')
def test_keys_limitation(self):
- # each key association is associated to the import
+ # each key association associated to the import
init_ope_number = models.Operation.objects.count()
importer, form = self.init_ope_import()
impt = form.save(self.ishtar_user)
@@ -270,11 +302,19 @@ class ImportOperationTest(ImportTest, TestCase):
ik.importer = other_imp
ik.save()
+ for tg in TargetKey.objects.filter(associated_import=impt).all():
+ tg.associated_import = other_imp
+ tg.save()
+
impt.importation()
current_ope_nb = models.Operation.objects.count()
# no new operation
self.assertEqual(current_ope_nb, init_ope_number)
+ for tg in TargetKey.objects.filter(associated_import=other_imp).all():
+ tg.associated_import = impt
+ tg.save()
+
def test_bad_configuration(self):
importer, form = self.init_ope_import()
col = ImporterColumn.objects.get(importer_type=importer, col_number=1)
diff --git a/archaeological_operations/tests/MCC-operations-example.csv b/archaeological_operations/tests/MCC-operations-example.csv
index 3b9801c33..16db46451 100644
--- a/archaeological_operations/tests/MCC-operations-example.csv
+++ b/archaeological_operations/tests/MCC-operations-example.csv
@@ -1,3 +1,3 @@
code OA,region,type operation,intitule operation,operateur,responsable operation,date debut terrain,date fin terrain,chronologie generale,identifiant document georeferencement,notice scientifique
4201,Bourgogne,Fouille programmée,Oppìdum de Paris 2,L'opérateur,,2000/01/31,2002/12/31,Age du Fer,,
-4200,Bourgogne,Fouille programmée,Oppìdum de Paris,L'opérateur,Jean Sui-Resp'on Sablé,2000/01/22,2002/12/31,Age du Fer & Gallo-Romain,,
+4200,Bourgogne,Fouille programmée,Oppìdum de Paris,L'opérateur,Jean Sui-Resp'on Sablé,2000/01/22,2002/12/31,Age du Fer & Gallo-Romain & Néolithique & Moderne,,