Ejemplo n.º 1
0
 def test_validation_missing_stage(self):
     """
     The form is invalid if the stage is not set.
     """
     form = PreviewConfirmationForm(data={'nonsense': ''})
     self.assertFalse(form.is_valid())
     eq_(form.non_field_errors(),
         ['Form data is missing or has been tampered.'])
Ejemplo n.º 2
0
 def test_validation_invalid_stage(self):
     """
     The form is invalid if the stage is not 'preview', 'confirm' or 'fill'.
     """
     form = PreviewConfirmationForm(data={'stage': 'hug_kitten'})
     self.assertFalse(form.is_valid())
     eq_(form.non_field_errors(),
         ['Form data is missing or has been tampered.'])
Ejemplo n.º 3
0
 def test_validation_missing_stage(self):
     """
     The form is invalid if the stage is not set.
     """
     form = PreviewConfirmationForm(data={'nonsense': ''})
     self.assertFalse(form.is_valid())
     eq_(form.non_field_errors(),
         ['Form data is missing or has been tampered.'])
Ejemplo n.º 4
0
 def test_validation_invalid_stage(self):
     """
     The form is invalid if the stage is not 'preview', 'confirm' or 'fill'.
     """
     form = PreviewConfirmationForm(data={'stage': 'hug_kitten'})
     self.assertFalse(form.is_valid())
     eq_(form.non_field_errors(),
         ['Form data is missing or has been tampered.'])
Ejemplo n.º 5
0
    def get_forms(self):
        kwargs = {'initial': None}
        if self.request.method == 'POST':
            kwargs['data'] = self.request.POST
        batch_form = TaskImportBatchForm(instance=None,
                                         prefix='batch',
                                         **kwargs)
        criterion_formset = TaskInvalidCriteriaFormSet(prefix='criterion',
                                                       **kwargs)
        kwargs['initial'] = {
            'end_date': date.today() + timedelta(days=30),
            'repeatable': False,
            'owner': self.request.user
        }

        task_form = TaskForm(instance=None, prefix='task', **kwargs)

        forms = {
            'criterion_formset': criterion_formset,
            'batch_form': batch_form,
            'task_form': task_form
        }

        # Create a hidden form for each possible PreviewConfirmationForm stage.
        # These forms are used to signal what the next stage should be.
        make_stage = lambda x: PreviewConfirmationForm(data={'stage': x})
        stages = PreviewConfirmationForm.submission_stages
        forms.update({'stage_form__' + s: make_stage(s) for s in stages})
        return forms
Ejemplo n.º 6
0
 def make_stage(stage):
     return PreviewConfirmationForm(data={'stage': stage})