Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def test_preserves_escaped_characters(self):
     html_input = ('<html>'
                   '<form action="/path/login/">'
                   '<input name="spam&amp;" value="eggs"/>'
                   '</form>'
                   '</html>')
     expected_output = ('<form action="/path/login/">'
                        '<input name="spam&amp;" value="eggs"/>'
                        '</form>')
     parser = FormParser()
     parser.feed(html_input)
     assert parser.extract_form(0) == expected_output
Ejemplo n.º 4
0
 def test_raise_error(self):
     parser = FormParser()
     message = 'Why do we have to implement this?'
     with pytest.raises(FormParserError, match=message):
         parser.error(message)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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