def gen_forms(self, form_report, form_filter): form_report = ReportForm(form_report) form_filter = ReportFilterForm(form_filter) if form_report.is_valid() and form_filter.is_valid(): return form_report, form_filter print("FORM REPORT:", form_report.errors or "No errors") print("FOMR FILTER:", form_filter.errors or "No errors")
def test_form_validation_for_required_fields(self): ## dates today = datetime.date.today() data1 = {'data_inicial_a': '', 'data_final_a': today, 'data_inicial_a': today, 'data_final_b': today} data2 = {'data_inicial_a': today, 'data_final_a': '', 'data_inicial_a': today, 'data_final_b': today} data3 = {'data_inicial_a': today, 'data_final_a': today, 'data_inicial_a': '', 'data_final_b': today} data4 = {'data_inicial_a': today, 'data_final_a': today, 'data_inicial_a': today, 'data_final_b': ''} self.assertFalse(ReportForm(data=data1).is_valid()) self.assertFalse(ReportForm(data=data2).is_valid()) self.assertFalse(ReportForm(data=data3).is_valid()) self.assertFalse(ReportForm(data=data4).is_valid())
def test_form_renders_input_fields(self): form = ReportForm() self.assertIn('placeholder="dd/mm/aaaa"', form.as_p()) self.assertIn('name="data_inicial_a"', form.as_p()) self.assertIn('name="data_final_a"', form.as_p()) self.assertIn('name="data_inicial_b"', form.as_p()) self.assertIn('name="data_final_b"', form.as_p()) self.assertIn('name="opts"', form.as_p())