def test_handles_multiple_inputs(self): form = ('<form action="/path/login/">' '<input name="username"/>' '<input name="password"/>' '</form>') html_input = '<html>%s</html>' % form parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == form
def test_strips_unneccesary_elements(self, basic_form): html_input = ('<html>' '<form action="/path/login/">' '<div>This will be ignored</div>' '<input name="spam" value="eggs"/>' '</form>' '</html>') parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == basic_form
def test_preserves_escaped_characters(self): html_input = ('<html>' '<form action="/path/login/">' '<input name="spam&" value="eggs"/>' '</form>' '</html>') expected_output = ('<form action="/path/login/">' '<input name="spam&" value="eggs"/>' '</form>') parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == expected_output
def test_raise_error(self): parser = FormParser() message = 'Why do we have to implement this?' with pytest.raises(FormParserError, match=message): parser.error(message)
def test_handles_multiple_forms(self, basic_form): html_input = '<html>%s%s</html>' % (basic_form, basic_form) parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == basic_form assert parser.extract_form(1) == basic_form
def test_ignores_input_outside_form(self, basic_form): html_input = '<html><input type="button" action="spam"/>%s</html>' html_input = html_input % basic_form parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == basic_form
def test_parse_form(self, basic_form): html_input = '<html>%s</html>' % basic_form parser = FormParser() parser.feed(html_input) assert parser.extract_form(0) == basic_form