From 1d76b22bc0090580e4ccbfb43e2f5d88d86f2bc7 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 22 May 2017 12:02:09 +0100 Subject: [PATCH] Add extra tests to make sure that the form is safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous implementations of this functionality mutated the base form class, which broke a bunch of stuff. I want to make sure that getting this form for one placeholder doesn’t change other forms that have already been instantiated for other placeholders. Mutation is scary. --- tests/app/main/test_placeholder_form.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/app/main/test_placeholder_form.py diff --git a/tests/app/main/test_placeholder_form.py b/tests/app/main/test_placeholder_form.py new file mode 100644 index 000000000..07fac6675 --- /dev/null +++ b/tests/app/main/test_placeholder_form.py @@ -0,0 +1,18 @@ +from app.main.forms import get_placeholder_form_instance +from wtforms import Label + + +def test_form_class_not_mutated(app_): + + with app_.test_request_context( + method='POST', + data={'placeholder_value': ''} + ) as req: + form1 = get_placeholder_form_instance('name', {}, optional_placeholder=False) + form2 = get_placeholder_form_instance('city', {}, optional_placeholder=True) + + assert not form1.validate_on_submit() + assert form2.validate_on_submit() + + assert str(form1.placeholder_value.label) == '' + assert str(form2.placeholder_value.label) == ''