def test_error(self): request = RequestFactory().post("/dslform/form/") response = dslform(request, "form", "dslforms/", save_method) self.assertEqual(response.status_code, 200) form = response.context_data["form"] self.assertEqual(form.errors["name"][0], "Please enter your name")
def test_get(self): request = RequestFactory().get("/dslform/form/") response = dslform(request, "form", "dslforms/", save_method) self.assertEqual(response.status_code, 200) form = response.context_data["form"] self.assertEqual(form.fields["name"].max_length, 100)
def test_missing_display_block(self): request = RequestFactory().get("/dslform/missing-display/") with self.assertRaises(Exception): dslform(request, "missing-display", "dslforms/", save_method)
def test_404(self): request = RequestFactory().get("/dslform/form404/") with self.assertRaises(Http404): dslform(request, "form404", "dslforms/", save_method)
def test_post(self): request = RequestFactory().post("/dslform/form/", dict(name="Name")) response = dslform(request, "form", "dslforms/", save_method) self.assertEqual(response.status_code, 302) self.assertTrue("form" in response.context_data) self.assertEqual(response.context_data["result"], "Saved")