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 | ba63aedc862c1877a53cac172463269c62e46d74 (patch) | |
| tree | 3d9ad77c1c38881bbe5344282b829090771468d4 /archaeological_operations/tests.py | |
| parent | 1db592248963926948e6306d4288411e7bc7fbb4 (diff) | |
| download | Ishtar-ba63aedc862c1877a53cac172463269c62e46d74.tar.bz2 Ishtar-ba63aedc862c1877a53cac172463269c62e46d74.zip | |
Town/Parcel form: fix modification (refs #3642, refs #3640)
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 100 | 
1 files changed, 82 insertions, 18 deletions
| 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) | 
