Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle form GET without action. #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions robobrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def _build_url(self, url):
:return: Full URL

"""
if not url:
# hack to force query string removal
url = urlparse.urlparse(self.url).path

return urlparse.urljoin(
self.url,
url
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@

mock_forms = utils.mock_responses(
[
utils.ArgCatcher(
responses.GET, 'http://robobrowser.com/get_form/no_action',
body=b'''
<form id="bass" method="get">'
<input name="deacon" value="john" />
</form>
<form id="drums" method="post">'
<input name="deacon" value="john" />
</form>
'''
),
utils.ArgCatcher(
responses.GET, 'http://robobrowser.com/get_form/',
body=b'''
Expand Down
19 changes: 19 additions & 0 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ def test_submit_form_post(self):
'deacon=john'
)

@mock_forms
def test_submit_form_get_no_action(self):
self.browser.open('http://robobrowser.com/get_form/no_action')
form = self.browser.get_form()
self.browser.submit_form(form)
assert_equal(
self.browser.url,
'http://robobrowser.com/get_form/no_action?deacon=john'
)
assert_true(self.browser.state.response.request.body is None)

form = self.browser.get_form()
self.browser.submit_form(form)
assert_equal(
self.browser.url,
'http://robobrowser.com/get_form/no_action?deacon=john'
)
assert_true(self.browser.state.response.request.body is None)


class TestFormsInputNoName(unittest.TestCase):

Expand Down