Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_issue180():
"""Test that a KeyError is not raised when Form.choose_submit is called
on a form where a submit element is missing its name-attribute."""
browser = mechanicalsoup.StatefulBrowser()
html = '''
<form>
<input value="Invalid" type="submit">
<input value="Valid" name="valid" type="submit">
</form>
'''
browser.open_fake_page(html)
form = browser.select_form()
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.choose_submit('not_found')
def test_form_not_found():
browser = mechanicalsoup.StatefulBrowser()
browser.open_fake_page(page_with_various_fields)
form = browser.select_form('form')
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.input({'foo': 'bar', 'nosuchname': 'nosuchval'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.check({'foo': 'bar', 'nosuchname': 'nosuchval'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.check({'entree': 'cheese'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.check({'topping': 'tofu'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.textarea({'bar': 'value', 'foo': 'nosuchval'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.set_radio({'size': 'tiny'})
with pytest.raises(mechanicalsoup.utils.LinkNotFoundError):
form.set_select({'entree': ('no_multiple', 'no_multiple')})
error("[{:10s}] Found captcha on page loading!".format(name))
return
try:
browser.select_form(form1)
browser[e_form] = email
except ms.utils.LinkNotFoundError:
error("[{:10s}] Something wrong in parsing, maybe it displayed captcha!".format(name))
return
try:
browser.submit_selected()
browser.select_form(form2)
browser[p_form] = pwd
browser.submit_selected()
except ms.utils.LinkNotFoundError:
browser.close()
error("[{:10s}] Email not registered!".format(name))
return
if is_there_captcha(browser.get_current_page().text):
error("[{:10s}] Found captcha after submitting login page!".format(name))
return
#Now let's check if it was success by trying to use the same form again and if I could use it then the login not success
try:
browser.select_form(form2)
browser.close()
error("[{:10s}] Login unsuccessful!".format(name))
except:
browser.close()
status("[{:10s}] Login successful!".format(name))
#That's a lot of exceptions :"D