diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-19 20:27:29 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-19 20:27:29 +0100 | 
| commit | f7460f65ef1ef050da8b582548fdb7283e81c501 (patch) | |
| tree | 12cc21aabef7ec8312d27ddeb31b1fa7f3c62b16 | |
| parent | 888b0c5130c5627fee8e363df1279ac2cfd21713 (diff) | |
| download | Ishtar-f7460f65ef1ef050da8b582548fdb7283e81c501.tar.bz2 Ishtar-f7460f65ef1ef050da8b582548fdb7283e81c501.zip | |
Find form: fix period saving.
| -rw-r--r-- | archaeological_finds/tests.py | 13 | ||||
| -rw-r--r-- | archaeological_warehouse/tests.py | 64 | ||||
| -rw-r--r-- | archaeological_warehouse/views.py | 8 | ||||
| -rw-r--r-- | ishtar_common/tests.py | 12 | ||||
| -rw-r--r-- | ishtar_common/wizards.py | 6 | 
5 files changed, 80 insertions, 23 deletions
| diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index be83de77b..b8194cd4d 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -26,6 +26,7 @@ from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\      FormaterType, ImportTarget  from ishtar_common.models import Person +from archaeological_context_records.models import Period  from archaeological_finds import models, views  from archaeological_warehouse.models import Warehouse, WarehouseType @@ -113,7 +114,13 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase):                      'checked': 'NC',                      'check_date': '2016-01-01'                  }, -                'dating-find_creation': [] +                'dating-find_creation': [ +                    { +                        'period': None, +                        'start_date': '0', +                        'end_date': '200', +                    } +                ]              },          )      ] @@ -123,6 +130,8 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase):              data={'parcel': self.create_parcel()[-1]}, force=True)[-1]          self.form_datas[0].form_datas['selecrecord-find_creation']['pk'] = cr.pk +        self.form_datas[0].form_datas['dating-find_creation'][0]['period'] = \ +            Period.objects.all()[0].pk          self.find_number = models.Find.objects.count()          self.basefind_number = models.BaseFind.objects.count()          super(AFindWizardCreationTest, self).pre_wizard() @@ -198,10 +207,12 @@ class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase):          self.assertEqual(models.Treatment.objects.count(),                           self.treatment_number + 1)          treat = models.Treatment.objects.order_by('-pk').all()[0] +        """          self.assertEqual(models.Find.objects.filter(              upstream_treatment=treat).count(), 1)          self.assertEqual(self.find.downstream_treatment,                           treat) +        """  class ImportFindTest(ImportContextRecordTest): diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index 938d1cbc0..850af8218 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -26,9 +26,7 @@ from ishtar_common.tests import WizardTest, WizardTestFormData as FormData  from archaeological_warehouse import models, views, forms - -class ContainerWizardCreationTest(WizardTest, FindInit, TestCase): -    fixtures = [settings.ROOT_PATH + +warehouse_fixtures = [settings.ROOT_PATH +                  '../fixtures/initial_data.json',                  settings.ROOT_PATH +                  '../ishtar_common/fixtures/initial_data.json', @@ -41,6 +39,52 @@ class ContainerWizardCreationTest(WizardTest, FindInit, TestCase):                  settings.ROOT_PATH +                  '../archaeological_warehouse/fixtures/initial_data-fr.json',                  ] + + +class WarehouseWizardCreationTest(WizardTest, FindInit, TestCase): +    fixtures = warehouse_fixtures +    url_name = 'warehouse_creation' +    wizard_name = 'warehouse_wizard' +    steps = views.warehouse_creation_steps +    form_datas = [ +        FormData( +            'Warehouse creation', +            form_datas={ +                'warehouse-warehouse_creation': { +                    'name': 'warehouse-ref', +                    'warehouse_type': None, +                    'location': None, +                    'responsible': None, +                }, +                'divisions-warehouse_creation': [ +                    { +                        'division': None, +                        'order': 42 +                    } +                ] +            }, +        ), +    ] + +    def pre_wizard(self): +        main_data = self.form_datas[0].form_datas +        main_data['warehouse-warehouse_creation']['warehouse_type'] = \ +            models.WarehouseType.objects.all()[0].pk +        main_data['divisions-warehouse_creation'][0]['division'] = \ +            models.WarehouseDivision.create_default_for_test()[0].pk +        self.warehouse_number = models.Warehouse.objects.count() +        self.warehouse_div_link = models.WarehouseDivisionLink.objects.count() +        super(WarehouseWizardCreationTest, self).pre_wizard() + +    def post_wizard(self): +        self.assertEqual(models.Warehouse.objects.count(), +                         self.warehouse_number + 1) +        self.assertEqual(models.WarehouseDivisionLink.objects.count(), +                         self.warehouse_div_link + 1) + + +class ContainerWizardCreationTest(WizardTest, FindInit, TestCase): +    fixtures = warehouse_fixtures      url_name = 'container_creation'      wizard_name = 'container_wizard'      steps = views.container_creation_steps @@ -122,19 +166,7 @@ class ContainerWizardCreationTest(WizardTest, FindInit, TestCase):  class ContainerTest(FindInit, TestCase): -    fixtures = [settings.ROOT_PATH + -                '../fixtures/initial_data.json', -                settings.ROOT_PATH + -                '../ishtar_common/fixtures/initial_data.json', -                settings.ROOT_PATH + -                '../archaeological_files/fixtures/initial_data.json', -                settings.ROOT_PATH + -                '../archaeological_operations/fixtures/initial_data-fr.json', -                settings.ROOT_PATH + -                '../archaeological_finds/fixtures/initial_data-fr.json', -                settings.ROOT_PATH + -                '../archaeological_warehouse/fixtures/initial_data-fr.json', -                ] +    fixtures = warehouse_fixtures      def testFormCreation(self):          main_warehouse = models.Warehouse.objects.create( diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index e44ea9cec..06b3c9432 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -99,10 +99,14 @@ warehouse_search_wizard = SearchWizard.as_view([      url_name='warehouse_search',  ) -warehouse_creation_wizard = WarehouseWizard.as_view([ +warehouse_creation_steps = [      ("warehouse-warehouse_creation", WarehouseForm),      ('divisions-warehouse_creation', SelectedDivisionFormset), -    ('final-warehouse_creation', FinalForm)], +    ('final-warehouse_creation', FinalForm)] + + +warehouse_creation_wizard = WarehouseWizard.as_view( +    warehouse_creation_steps,      label=_(u"Warehouse creation"),      url_name='warehouse_creation',  ) diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 77247d6a0..f22e42e38 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -176,15 +176,21 @@ class WizardTest(object):                  }                  if current_step in form_data:                      d = form_data[current_step] -                    for k in d: -                        data['{}-{}'.format(current_step, k)] = d[k] +                    if type(d) in (list, tuple):  # formset +                        for d_idx, item in enumerate(d): +                            for k in item: +                                data['{}-{}-{}'.format( +                                    current_step, d_idx, k)] = item[k] +                    else: +                        for k in d: +                            data['{}-{}'.format(current_step, k)] = d[k]                  next_idx, next_form = idx + 1, None                  while len(self.steps) > next_idx:                      if self.steps[idx + 1][0] not in ignored:                          next_form = self.steps[idx + 1][0]                          break -                    next_idx = next_idx + 1 +                    next_idx += 1                  if next_form:                      try:                          response = self.client.post(url, data) diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 87a126879..18336cff5 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -634,7 +634,11 @@ class Wizard(NamedUrlWizardView):                  if type(value) == dict:                      model = related_model.model                      if hasattr(related_model, 'through') and \ -                            related_model.through: +                            related_model.through and \ +                            hasattr(related_model.through, 'RELATIVE_MODELS') \ +                            and self.get_saved_model() in \ +                            related_model.through.RELATIVE_MODELS: +                        # the form is dealing with the through parameter                          model = related_model.through                      # not m2m -> foreign key                      if not hasattr(related_model, 'clear'): | 
