def test_generate_form(self): """The generated form should include only fields in the form config""" config = {"111": [{"name": "field1", "status": "editable"}, {"name": "field2", "status": "locked"}, {"name": "field3", "status": "hidden"}]} params = {"form_id": "111", "field2": "value2", "field4": "value4"} with self.settings(FORM_CONFIGS=config): response = views.generate_form(None, "AGE", "APP", params) self.assertContains(response, "agency_id") self.assertContains(response, "AGE") self.assertContains(response, "app_name") self.assertContains(response, "APP") self.assertContains(response, "field1") self.assertContains(response, "field2") self.assertContains(response, "field3") self.assertContains(response, "value2") self.assertNotContains(response, "field4") self.assertNotContains(response, "value4")
def test_generate_form_no_form(self): """The form is looked up; if it's not present, we get an error""" with self.settings(FORM_CONFIGS={"111": []}): response = views.generate_form(None, None, None, {"form_id": "2222"}) self.assertEqual(response.status_code, 400)