diff --git a/tests/html/form_inputs.html b/tests/html/form_inputs.html index e7ab368..0b7c53f 100644 --- a/tests/html/form_inputs.html +++ b/tests/html/form_inputs.html @@ -55,5 +55,11 @@ + +
+ +
+ + diff --git a/tests/test_forms.py b/tests/test_forms.py index 0348d0e..9bf0ae0 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -134,6 +134,9 @@ def test_button_submit_by_value_and_index(self): form.submit, "action", value="activate", index=0) + def test_outer_inputs(self): + form = self.callFUT(formid='outer_inputs_form') + self.assertEqual(('foo', 'bar', 'button'), tuple(form.fields)) class TestResponseFormAttribute(unittest.TestCase): @@ -285,26 +288,33 @@ def test_textarea_emptyfirstline(self): class TestFormLint(unittest.TestCase): def test_form_lint(self): - form = webtest.Form(None, '''
+ def _build_response(html): + return webtest.TestResponse('{}'.format(html)) + + html = ''' -
''') + ''' + form = webtest.Form(_build_response(html), html) self.assertRaises(AttributeError, form.lint) - form = webtest.Form(None, '''
+ html = ''' -
''') + ''' + form = webtest.Form(_build_response(html), html) self.assertRaises(AttributeError, form.lint) - form = webtest.Form(None, '''
+ html = ''' -
''') + ''' + form = webtest.Form(_build_response(html), html) form.lint() - form = webtest.Form(None, '''
+ html = ''' -
''') + ''' + form = webtest.Form(_build_response(html), html) form.lint() diff --git a/webtest/forms.py b/webtest/forms.py index 057247b..73d37f5 100644 --- a/webtest/forms.py +++ b/webtest/forms.py @@ -432,7 +432,12 @@ def _parse_fields(self): fields = OrderedDict() field_order = [] tags = ('input', 'select', 'textarea', 'button') - for pos, node in enumerate(self.html.find_all(tags)): + inner_elts = self.html.find_all(tags) + def _form_elt_filter(tag): + return tag in inner_elts or ( + tag.attrs.get('form') == self.id and tag.name in tags) + elements = self.response.html.find_all(_form_elt_filter) + for pos, node in enumerate(elements): attrs = dict(node.attrs) tag = node.name name = None