diff options
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 |
commit | 211a45787349264c616f2ec76bfefced8a20ea0d (patch) | |
tree | 66e611e3035ee4a5fc84ef0b790fabfac3a47a9d /archaeological_operations/tests.py | |
parent | ee0f3ef165db85cab69ca27f912d167afd00bf27 (diff) | |
download | Ishtar-211a45787349264c616f2ec76bfefced8a20ea0d.tar.bz2 Ishtar-211a45787349264c616f2ec76bfefced8a20ea0d.zip |
Imports: fix target dict initialization
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 64 |
1 files changed, 52 insertions, 12 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) |