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

Add support for the HTML image input tag #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions robobrowser/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Submit(Input):
pass


class ImageSubmit(Submit):
def serialize(self):
return {self.name + '.x': '0', self.name + '.y': '0'}


class FileInput(BaseField):

@BaseField.value.setter
Expand Down
2 changes: 2 additions & 0 deletions robobrowser/forms/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def _parse_field(tag, tags):
tag_type = tag.get('type', '').lower()
if tag_type == 'submit':
return fields.Submit(tag)
if tag_type == 'image':
return fields.ImageSubmit(tag)
if tag_type == 'file':
return fields.FileInput(tag)
if tag_type == 'radio':
Expand Down
25 changes: 25 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ def test_parse_select_multi(self):
assert_equal(len(_fields), 1)
assert_true(isinstance(_fields[0], fields.MultiSelect))

def test_parse_image_submit(self):
html = '''
<input type="image" name="image_submit" />
'''
_fields = _parse_fields(BeautifulSoup(html))
assert_equal(len(_fields), 1)
assert_true(isinstance(_fields[0], fields.ImageSubmit))


class TestInput(unittest.TestCase):

Expand Down Expand Up @@ -616,6 +624,23 @@ def test_serialize(self):
)



class TestImageSubmit(unittest.TestCase):

def setUp(self):
self.html = '<input type="image" name="image_submit">'
self.input = fields.ImageSubmit(BeautifulSoup(self.html).find('input'))

def test_name(self):
assert_equal(self.input.name, 'image_submit')

def test_serialize(self):
assert_equal(
self.input.serialize(),
{'image_submit.x': '0', 'image_submit.y': '0'}
)


class TestDisabledValues(unittest.TestCase):

def test_input_enabled(self):
Expand Down