def test_instanciate_form(self):
     update_data = {'background': u'Esto es un antecedente'}
     file_data = {'image': self.image}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertTrue(form.is_valid())
     proposal = form.save()
     self.assertEquals(proposal.background, update_data['background'])
     self.assertTrue(proposal.image)
 def test_form_with_generated_at_form_invalid(self):
     not_a_comuna = Area.objects.create(name='Not a Comuna')
     update_data = {
         'background': u'Esto es un antecedente',
         'contact_details': u'Me puedes contactar en el teléfono 123456',
         'generated_at': not_a_comuna,
     }
     file_data = {'image': self.image, 'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertFalse(form.is_valid())
     self.assertTrue(form.errors['generated_at'])
 def test_form_with_generated_at_form_invalid(self):
     not_a_comuna = Area.objects.create(name='Not a Comuna')
     update_data = {'background': u'Esto es un antecedente',
                    'contact_details': u'Me puedes contactar en el teléfono 123456',
                    'generated_at': not_a_comuna,
                    }
     file_data = {'image': self.image,
                  'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertFalse(form.is_valid())
     self.assertTrue(form.errors['generated_at'])
 def test_instanciate_form(self):
     update_data = {'background': u'Esto es un antecedente',
                    'contact_details': u'Me puedes contactar en el teléfono 123456',
                    }
     file_data = {'image': self.image,
                  'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertTrue(form.is_valid(), form.errors)
     proposal = form.save()
     self.assertEquals(proposal.background, update_data['background'])
     self.assertTrue(proposal.image)
     self.assertTrue(proposal.document)
     self.assertEquals(proposal.contact_details, update_data['contact_details'])
 def test_instanciate_form(self):
     update_data = {
         'background': u'Esto es un antecedente',
         'contact_details': u'Me puedes contactar en el teléfono 123456',
     }
     file_data = {'image': self.image, 'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertTrue(form.is_valid(), form.errors)
     proposal = form.save()
     self.assertEquals(proposal.background, update_data['background'])
     self.assertTrue(proposal.image)
     self.assertTrue(proposal.document)
     self.assertEquals(proposal.contact_details,
                       update_data['contact_details'])
Exemplo n.º 6
0
    def done(self, form_list, **kwargs):
        data = {}
        [data.update(form.cleaned_data) for form in form_list]
        kwargs = {
            'proposer': self.request.user,
            'data': data,
            'area': self.determine_area(data)
        }

        temporary_data = self.model.objects.create(**kwargs)
        context = self.get_context_data(form=None)
        context.update({
            'popular_proposal': temporary_data,
            'area': kwargs['area']
        })
        if not settings.MODERATION_ENABLED:
            temporary_data.create_proposal()
            context['form_update'] = UpdateProposalForm(
                instance=temporary_data.created_proposal)
        else:
            temporary_data.notify_new()
        send_mails_to_staff({'temporary_data': temporary_data},
                            'notify_staff_new_proposal')
        return render(self.request, 'popular_proposal/wizard/done.html',
                      context)
 def test_form_with_generated_at_form_valid(self):
     comuna = Area.objects.filter(classification='Comuna').first()
     update_data = {'background': u'Esto es un antecedente',
                    'contact_details': u'Me puedes contactar en el teléfono 123456',
                    'generated_at': comuna.id,
                    }
     file_data = {'image': self.image,
                  'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertTrue(form.is_valid())
     proposal = form.save()
     self.assertEquals(proposal.generated_at, comuna)
     not_a_comuna = Area.objects.create(name='Not a Comuna')
     update_data['generated_at'] = not_a_comuna.id
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertFalse(form.is_valid())
 def test_form_with_generated_at_form_valid(self):
     comuna = Area.objects.filter(classification='Comuna').first()
     update_data = {
         'background': u'Esto es un antecedente',
         'contact_details': u'Me puedes contactar en el teléfono 123456',
         'generated_at': comuna.id,
     }
     file_data = {'image': self.image, 'document': self.get_document()}
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertTrue(form.is_valid())
     proposal = form.save()
     self.assertEquals(proposal.generated_at, comuna)
     not_a_comuna = Area.objects.create(name='Not a Comuna')
     update_data['generated_at'] = not_a_comuna.id
     form = UpdateProposalForm(data=update_data,
                               files=file_data,
                               instance=self.popular_proposal)
     self.assertFalse(form.is_valid())