def test_form_noaction(): browser, url = setup_mock_browser() browser.open_fake_page(submit_form_noaction) form = browser.select_form('#choose-submit-form') with pytest.raises(ValueError, message="no URL to submit to"): res = browser.submit_selected() browser.close()
def test_form_noname(): browser, url = setup_mock_browser(expected_post=[]) browser.open_fake_page(submit_form_noname, url=url) browser.select_form('#choose-submit-form') response = browser.submit_selected() assert(response.status_code == 200 and response.text == 'Success!') browser.close()
def test_request_forward(): browser, url = setup_mock_browser(expected_post=[('var1', 'val1'), ('var2', 'val2')]) r = browser.request('POST', url + '/post', data={'var1': 'val1', 'var2': 'val2'}) assert r.text == 'Success!' browser.close()
def test_form_multiple(): browser, url = setup_mock_browser(expected_post=[('foo', 'tempeh'), ('foo', 'tofu')]) browser.open_fake_page(submit_form_multiple, url=url) browser.select_form('#choose-submit-form') response = browser.submit_selected() assert(response.status_code == 200 and response.text == 'Success!') browser.close()
def test_submit_btnName(expected_post): '''Tests that the btnName argument chooses the submit button.''' browser, url = setup_mock_browser(expected_post=expected_post) browser.open(url) form = browser.select_form('#choose-submit-form') browser['text'] = expected_post[2][1] browser['comment'] = expected_post[0][1] res = browser.submit_selected(btnName = expected_post[1][0]) assert(res.status_code == 200 and res.text == 'Success!')
def test_verbose(capsys): '''Tests that the btnName argument chooses the submit button.''' browser, url = setup_mock_browser() browser.open(url) out, err = capsys.readouterr() assert out == "" assert err == "" assert browser.get_verbose() == 0 browser.set_verbose(1) browser.open(url) out, err = capsys.readouterr() assert out == "." assert err == "" assert browser.get_verbose() == 1 browser.set_verbose(2) browser.open(url) out, err = capsys.readouterr() assert out == "mock://form.com\n" assert err == "" assert browser.get_verbose() == 2 browser.close()
def test_form_multiple(): browser, url = setup_mock_browser(expected_post=[('foo', 'tempeh'), ('foo', 'tofu')]) browser.open_fake_page(submit_form_multiple, url=url) browser.select_form('#choose-submit-form') response = browser.submit_selected() browser.close()
def test_form_noname(): browser, url = setup_mock_browser(expected_post=[]) browser.open_fake_page(submit_form_noname, url=url) browser.select_form('#choose-submit-form') response = browser.submit_selected() browser.close()