Skip to content

Browser._findAllControls() has wrong behaviour with no-name inputs and checkboxes #92

@vernans

Description

@vernans

Checkboxes become multiple controls that are handled together
when they are collected by Browser._findAllControls(). Usually they all
have the same name. When there are other fields with the same
name – or in a more normal and case multiple inputs with no name – unexpected errors are possible.
Has anybody any idea how to fix this?
Those tests assert the expected behaviour but fail with the current implementation.

class TestsSameNameAndCheckboxes(unittest.TestCase):
    """Testing weird behaviour regarding checkboxes with the same name."""

    def test_checkbox_controls_with_same_name_1(self):
        """A checkbox without name doesn't interfere with
        throwing a LookupError. In this case, multiple input
        fields are handled together but the checkbox is not
        treated as that because the first input is a button.
        """
        app = QuietTestApp()
        browser = Browser(wsgi_app=app)
        app.set_next_response(b'''\
<html><body>
<form action="." method="post" enctype="multipart/form-data">

    <button type="button">Do Stuff</button>
    <button type="button">Do Other Stuff</button>
    <label for="checkbox">Label</label>
    <input type="checkbox" id="checkbox">
</form></body></html>
        ''')
        browser.open('http://localhost/')
        with self.assertRaises(LookupError):
            browser.getControl('Not There')

    def test_checkbox_controls_with_same_name_2(self):
        """A checkbox is regognized as an ItemControl."""
        app = QuietTestApp()
        browser = Browser(wsgi_app=app)
        app.set_next_response(b'''\
<html><body>
<form action="." method="post" enctype="multipart/form-data">

    <button name="any" type="button">Do Stuff</button>
    <button name="any" type="button">Do Other Stuff</button>
    <label for="checkbox">Label</label>
    <input name="any" type="checkbox" id="checkbox">
</form></body></html>
        ''')
        browser.open('http://localhost/')
        control = browser.getControl('Label')
        assert isinstance(control, ItemControl)

    def test_checkbox_controls_with_same_name_3(self):
        """A checkbox without name doesn't interfere with
        throwing a LookupError. This time it seems to interpret the buttons
        as options of the checkbox."""
        app = QuietTestApp()
        browser = Browser(wsgi_app=app)
        app.set_next_response(b'''\
<html><body>
<form action="." method="post" enctype="multipart/form-data">
    <label for="checkbox">Label</label>
    <input type="checkbox" id="checkbox">
    <button type="button">Do Stuff</button>
    <button type="button">Do Other Stuff</button>
</form></body></html>
        ''')
        browser.open('http://localhost/')
        with self.assertRaises(LookupError):
            browser.getControl('Not There')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions