diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-05 02:34:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-05 02:34:49 +0200 |
commit | 923b2533d62454f89b409628ab0203c3641e30ed (patch) | |
tree | 3d9ad77c1c38881bbe5344282b829090771468d4 /archaeological_operations | |
parent | 31cef7ca152ddc6a9f27b0f9db5932a08f7d7082 (diff) | |
download | Ishtar-923b2533d62454f89b409628ab0203c3641e30ed.tar.bz2 Ishtar-923b2533d62454f89b409628ab0203c3641e30ed.zip |
Town/Parcel form: fix modification (refs #3642, refs #3640)
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 14 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 100 |
2 files changed, 82 insertions, 32 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index acd0fb099..4a7d56024 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -1044,13 +1044,6 @@ class SelectedTownForm(forms.Form): towns = None if 'data' in kwargs and 'TOWNS' in kwargs['data']: towns = kwargs['data']['TOWNS'] - # clean data if not "real" data - prefix_value = kwargs['prefix'] + '-town' - if not [k for k in kwargs['data'].keys() - if k.startswith(prefix_value) and kwargs['data'][k]]: - kwargs['data'] = None - if 'files' in kwargs: - kwargs.pop('files') super(SelectedTownForm, self).__init__(*args, **kwargs) if towns and towns != -1: self.fields['town'].choices = [('', '--')] + towns @@ -1070,13 +1063,6 @@ class SelectedParcelForm(forms.Form): parcels = None if 'data' in kwargs and 'PARCELS' in kwargs['data']: parcels = kwargs['data']['PARCELS'] - # clean data if not "real" data - prefix_value = kwargs['prefix'] + '-parcel' - if not [k for k in kwargs['data'].keys() - if k.startswith(prefix_value) and kwargs['data'][k]]: - kwargs['data'] = None - if 'files' in kwargs: - kwargs.pop('files') super(SelectedParcelForm, self).__init__(*args, **kwargs) if parcels: self.fields['parcel'].choices = [('', '--')] + parcels diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 83672a9f9..2e6914b6c 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -35,7 +35,9 @@ 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 + Town, ImporterColumn, Person, Author, SourceType, AuthorType, \ + DocumentTemplate, PersonType +from archaeological_files.models import File, FileType from archaeological_context_records.models import Unit from ishtar_common import forms_common @@ -43,6 +45,41 @@ from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \ create_superuser, create_user, TestCase +class FileInit(object): + def login_as_superuser(self): + self.client.login(username='username', password='tralala') + + def create_file(self): + self.extra_models, self.model_list = {}, [] + self.user, created = User.objects.get_or_create(username='username', + is_superuser=True) + self.user.set_password('tralala') + self.user.save() + self.o_user, created = User.objects.get_or_create(username='ousername') + person_type, created = PersonType.objects.get_or_create( + label=u'Test ' u'person type', txt_idx='test_person', + available=True) + self.extra_models['person_type'] = person_type + self.model_list.append(person_type) + + person = models.Person(surname='Surname', name='Name', + history_modifier=self.o_user) + person.save() + self.extra_models['person'] = person + self.model_list.append(person) + + file_type, created = FileType.objects.get_or_create( + label=u'Test file type', txt_idx='test_file', available=True) + self.extra_models['file_type'] = file_type + self.model_list.append(file_type) + + dct = {'year': 2010, 'numeric_reference': 1000, 'file_type': file_type, + 'internal_reference': u'UNIT_testÉ ?', 'in_charge': person, + 'history_modifier': self.o_user, 'total_surface': 10000} + self.item = File(**dct) + self.item.save() + + class ImportTest(object): def setUp(self): self.username, self.password, self.user = create_superuser() @@ -1090,31 +1127,45 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): FormData( "Create a preventive diag", form_datas={ - 'filechoice-operation_creation': {}, - 'general-operation_creation': { + 'filechoice': {}, + 'general': { 'operation_type': 1, # preventive diag 'year': 2016}, - 'townsgeneral-operation_creation': [], - 'parcelsgeneral-operation_creation': [], + 'townsgeneral': [], + 'parcelsgeneral': [], }, ignored=('towns-operation_creation', 'parcels-operation_creation', - 'preventive-operation_creation',) + 'preventive-operation_creation') ), FormData( "Create another preventive diag with same parcel name", form_datas={ - 'filechoice-operation_creation': {}, - 'general-operation_creation': { + 'filechoice': {}, + 'general': { 'operation_type': 1, # preventive diag 'year': 2016}, - 'townsgeneral-operation_creation': [], - 'parcelsgeneral-operation_creation': [], + 'townsgeneral': [], + 'parcelsgeneral': [], }, ignored=('towns-operation_creation', 'parcels-operation_creation', - 'preventive-operation_creation',) - ) + 'preventive-operation_creation') + ), + FormData( + "Create an operation related to a file", + form_datas={ + 'filechoice': {}, + 'general': { + 'operation_type': 1, # preventive diag + 'year': 2016}, + 'towns': [], + 'parcels': [], + }, + ignored=('townsgeneral-operation_creation', + 'parcelsgeneral-operation_creation', + 'preventive-operation_creation') + ), ] def pre_wizard(self): @@ -1123,29 +1174,42 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): profile.files = True profile.save() - if 'townsgeneral-operation_creation' not in \ + if 'townsgeneral' not in \ self.form_datas[0].form_datas: 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) + 'townsgeneral'].append(town_data) self.form_datas[1].form_datas[ - 'townsgeneral-operation_creation'].append(town_data) + 'townsgeneral'].append(town_data) parcel_data = { 'town': town.pk, 'year': 2017, 'section': 'S', 'parcel_number': '42'} self.form_datas[0].form_datas[ - 'parcelsgeneral-operation_creation'].append(parcel_data) + 'parcelsgeneral'].append(parcel_data) self.form_datas[1].form_datas[ - 'parcelsgeneral-operation_creation'].append(parcel_data) + 'parcelsgeneral'].append(parcel_data) + + FI = FileInit() + FI.create_file() + file = FI.item + file.towns.add(town) + parcel = models.Parcel.objects.create( + town=town, year=2017, section='S', parcel_number='42' + ) + file.parcels.add(parcel) + self.form_datas[2].set('filechoice', 'pk', file.pk) + self.form_datas[2].append('towns', town_data) + self.form_datas[2].append('parcels', {'parcel': parcel.pk}) + self.operation_number = models.Operation.objects.count() self.parcel_number = models.Parcel.objects.count() super(OperationWizardCreationTest, self).pre_wizard() def post_wizard(self): self.assertEqual(models.Operation.objects.count(), - self.operation_number + 2) + self.operation_number + 3) self.assertEqual(models.Parcel.objects.count(), self.parcel_number + 2) |