diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-09 23:16:25 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-15 18:46:16 +0100 |
commit | 7d69b2b90a7c831477a2b1668bb9b7346120aaca (patch) | |
tree | 4f6466f8f11ef8e56b5030ea9576fe037500b47a /archaeological_operations/tests.py | |
parent | dc6eed246c7c71b3c63a9e7b83a44d9a601ae9f8 (diff) | |
download | Ishtar-7d69b2b90a7c831477a2b1668bb9b7346120aaca.tar.bz2 Ishtar-7d69b2b90a7c831477a2b1668bb9b7346120aaca.zip |
Item keys are now related to the current importer (refs #3451)
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 88 |
1 files changed, 54 insertions, 34 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 7c141af93..296236029 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -34,7 +34,7 @@ import models from archaeological_operations import views -from ishtar_common.models import OrganizationType, Organization, \ +from ishtar_common.models import OrganizationType, Organization, ItemKey, \ ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \ Town, ImporterColumn from archaeological_context_records.models import Unit @@ -74,26 +74,30 @@ class ImportTest(object): def init_ope_targetkey(self, imp): # doing manually connections - tg = TargetKey.objects.filter(target__target='operation_type' - ).order_by('-pk').all()[0] - tg.value = models.OperationType.objects.get( + target = TargetKey.objects.filter( + target__target='operation_type').order_by('-pk').all()[0] + target.value = models.OperationType.objects.get( txt_idx='prog_excavation').pk - tg.is_set = True - tg.save() - - target = TargetKey.objects.get(key='gallo-romain', - associated_import=imp) - gallo = models.Period.objects.get(txt_idx='gallo-roman') - target.value = gallo.pk target.is_set = True + target.associated_import = imp target.save() - target = TargetKey.objects.get(key='age-du-fer', - associated_import=imp) + target2 = TargetKey.objects.get(key='gallo-romain', + associated_import=imp) + gallo = models.Period.objects.get(txt_idx='gallo-roman') + target2.value = gallo.pk + target2.is_set = True + target2.associated_import = imp + target2.save() + + target3 = TargetKey.objects.get(key='age-du-fer', + associated_import=imp) iron = models.Period.objects.get(txt_idx='iron_age') - target.value = iron.pk - target.is_set = True - target.save() + target3.value = iron.pk + target3.is_set = True + target3.associated_import = imp + target3.save() + return [target, target2, target3] def init_ope(self): importer, form = self.init_ope_import() @@ -186,7 +190,7 @@ class ImportOperationTest(ImportTest, TestCase): 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)) + self.assertEqual(current_ope_nb, first_ope_nb + 1) # and well imported last_ope = models.Operation.objects.order_by('-pk').all()[0] self.assertEqual(last_ope.name, u"Oppìdum de Paris") @@ -200,9 +204,28 @@ class ImportOperationTest(ImportTest, TestCase): # a second importation will be not possible: no two same patriarche # code impt.importation() - models.Operation.objects.count() - self.assertTrue(last_ope == - models.Operation.objects.order_by('-pk').all()[0]) + self.assertEqual(last_ope, + models.Operation.objects.order_by('-pk').all()[0]) + + def test_keys_limitation(self): + # each key association is associated to the import + init_ope_number = models.Operation.objects.count() + importer, form = self.init_ope_import() + impt = form.save(self.ishtar_user) + impt.initialize() + self.init_ope_targetkey(imp=impt) + + importer, form = self.init_ope_import() + other_imp = form.save(self.ishtar_user) + # associate with another import + for ik in ItemKey.objects.filter(importer=impt).all(): + ik.importer = other_imp + ik.save() + + impt.importation() + current_ope_nb = models.Operation.objects.count() + # no new operation + self.assertEqual(current_ope_nb, init_ope_number) def test_bad_configuration(self): importer, form = self.init_ope_import() @@ -809,7 +832,6 @@ class OperationSearchTest(TestCase, OperationInitTest): self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content)['total'], 1) - def testOwnSearch(self): c = Client() response = c.get(reverse('get-operation'), {'year': '2010'}) @@ -911,12 +933,10 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): return super(OperationWizardCreationTest, self).pre_wizard() town = self.create_towns()[0] town_data = {'town': town.pk} - self.form_datas[0].form_datas['townsgeneral-operation_creation'].append( - town_data - ) - self.form_datas[1].form_datas['townsgeneral-operation_creation'].append( - town_data - ) + self.form_datas[0].form_datas[ + 'townsgeneral-operation_creation'].append(town_data) + self.form_datas[1].form_datas[ + 'townsgeneral-operation_creation'].append(town_data) parcel_data = { 'town': town.pk, 'year': 2017, 'section': 'S', 'parcel_number': '42'} @@ -997,7 +1017,8 @@ class OperationWizardClosingTest(OperationWizardCreationTest): self.assertFalse(ope.is_active()) self.assertEqual( ope.closing()['date'].strftime('%Y-%d-%m'), - self.form_datas[0].form_datas['date-operation_closing']['end_date']) + self.form_datas[0].form_datas['date-operation_closing']['end_date'] + ) class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest, @@ -1017,12 +1038,11 @@ class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest, FormData( "Admin act creation", form_datas={ - 'selec-operation_administrativeactop': { - }, - 'administrativeact-operation_administrativeactop': { - 'signature_date': str(datetime.date.today()) - } - }, + 'selec-operation_administrativeactop': {}, + 'administrativeact-operation_administrativeactop': { + 'signature_date': str(datetime.date.today()) + } + }, ) ] |