def test_invalid_input_custom_callable_message(self): with app.test_client() as c: c.post("/", data=dict(field_1="aaa", field_2="aa")) form = MockFormCustomCallableMessage() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field_1.errors), 1) self.assertEqual(form.field_1.errors[0], R.string.test_message)
def test_invalid_by_min_length_with_default_message(self): with app.test_client() as c: c.post("/", data=dict()) form = MockFormMin1MaxNone() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual( form.field.errors[0], R.string.validators.field_min_length_singular % dict(min_length=1)) c.post("/", data=dict(field="")) form = MockFormMin1MaxNone() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual( form.field.errors[0], R.string.validators.field_min_length_singular % dict(min_length=1)) c.post("/", data=dict(field="aa")) form = MockFormMin3MaxNone() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual( form.field.errors[0], R.string.validators.field_min_length_plural % dict(min_length=3))
def test_invalid_length_min_defined_max_defined_with_custom_message(self): with app.test_client() as c: c.post("/", data=dict(field="aaaaaaa")) form = MockFormMin3Max6CustomMessage() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual(form.field.errors[0], R.string.test_message)
def test_valid_input(self): with app.test_client() as c: c.post("/", data=dict( field="a" )) form = MockForm() self.assertTrue(form.validate_on_submit())
def test_valid_lengths_min_defined_max_none(self): with app.test_client() as c: c.post("/", data=dict(field="aaa")) form = MockFormMin3MaxNone() self.assertTrue(form.validate_on_submit()) c.post("/", data=dict(field="aaaa")) form = MockFormMin3MaxNone() self.assertTrue(form.validate_on_submit())
def test_stop_false(self): with app.app_context(): with app.test_client() as c: c.post("/", data=dict( email=email )) form = MockFormStopFalse() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.email.errors), 2)
def test_invalid_length_min_defined_max_defined_with_default_message(self): with app.test_client() as c: c.post("/", data=dict(field="aa")) form = MockFormMin3Max6() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual( form.field.errors[0], R.string.validators.field_length_range % dict(min_length=3, max_length=6))
def test_invalid_input_other_field_missing(self): with app.test_client() as c: c.post("/", data=dict(field_1="aaa")) form = MockForm() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field_1.errors), 1) self.assertEqual( form.field_1.errors[0], R.string.validators.field_must_be_equal_to % dict(other_name="field_2"))
def test_fail_custom_callable_message(self): with app.app_context(): with app.test_client() as c: c.post("/", data=dict( email=email )) form = MockFormCustomCallableMessage() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.email.errors), 1) self.assertEqual(form.email.errors[0], R.string.validators.email_already_registered)
def test_fail_default_message(self): with app.app_context(): with app.test_client() as c: c.post("/", data=dict( email=email )) form = MockForm() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.email.errors), 1) self.assertEqual(form.email.errors[0], R.string.validators.unique_field)
def test_valid_emails(self): with app.test_client() as c: valid_emails = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "marco [email protected]" ] def assert_valid_email(valid_email): c.post("/", data=dict(email=valid_email)) form = MockForm() self.assertTrue(form.validate_on_submit()) for email in valid_emails: assert_valid_email(email)
def test_invalid_inputs(self): with app.test_client() as c: c.post("/") form = MockForm() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual(form.field.errors[0], R.string.validators.required_field) c.post("/", data=dict( field=None )) form = MockForm() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1) self.assertEqual(form.field.errors[0], R.string.validators.required_field)
def test_invalid_emails(self): with app.test_client() as c: invalid_emails = [ "marco@@", "@gmail.com", "@gmail.com.br", "@@@@", "....@...", "marco", "m.m", "marco.padasv21@b", "marco.psd231sv@b asd sd", "a@bbb" ] def assert_invalid_email(invalid_email): c.post("/", data=dict(email=invalid_email)) form = MockForm() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.email.errors), 1) self.assertEqual(form.email.errors[0], R.string.validators.invalid_email_format) for email in invalid_emails: assert_invalid_email(email)
def test_stop_false(self): with app.test_client() as c: c.post("/", data=dict(field_1="aaa", field_2="aa")) form = MockFormStopFalse() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field_1.errors), 2)
def test_stop_false(self): with app.test_client() as c: c.post("/", data=dict(email="marco@@")) email_mock_form = MockFormStopFalse() self.assertFalse(email_mock_form.validate_on_submit()) self.assertEqual(len(email_mock_form.email.errors), 2)
def test_invalid_field_name_declaration(self): with app.test_client() as c: c.post("/", data=dict(field_1="aaa", field_2="aa")) form = MockFormKeyError() with self.assertRaises(InvalidFieldError): form.validate_on_submit()
def test_stop_true(self): with app.test_client() as c: c.post("/", data=dict(field="aaaaaaa")) form = MockFormMin3Max6StopTrue() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1)
def test_stop_true(self): with app.test_client() as c: c.post("/") form = MockFormWithAlwaysError() self.assertFalse(form.validate_on_submit()) self.assertEqual(len(form.field.errors), 1)
def test(self): with app.app_context(): with app.test_client() as c: c.post("/", data=dict(email="*****@*****.**")) form = MockForm() self.assertTrue(form.validate_on_submit())