diff --git a/dev-requirements.txt b/dev-requirements.txt
index 640df0d..dc2ee46 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,7 +1,7 @@
coverage
coveralls
docutils
-flake8
+flake8==2.6.2
mock
nose
sphinx
diff --git a/robobrowser/forms/fields.py b/robobrowser/forms/fields.py
index c6ddeb3..34c23bd 100644
--- a/robobrowser/forms/fields.py
+++ b/robobrowser/forms/fields.py
@@ -57,6 +57,9 @@ class Submit(Input):
pass
+class Button(Input):
+ pass
+
class FileInput(BaseField):
@BaseField.value.setter
diff --git a/robobrowser/forms/form.py b/robobrowser/forms/form.py
index 00b7222..cc3ce7c 100644
--- a/robobrowser/forms/form.py
+++ b/robobrowser/forms/form.py
@@ -13,7 +13,7 @@
from .. import exceptions
-_tags = ['input', 'textarea', 'select']
+_tags = ['input', 'button', 'textarea', 'select']
_tag_ptn = re.compile(
'|'.join(_tags),
re.I
@@ -53,6 +53,11 @@ def _parse_field(tag, tags):
checkboxes = _group_flat_tags(tag, tags)
return fields.Checkbox(checkboxes)
return fields.Input(tag)
+ if tag_type == 'button':
+ tag_type = tag.get('type', 'submit').lower()
+ if tag_type == 'submit':
+ return fields.Submit(tag)
+ return fields.Button(tag)
if tag_type == 'textarea':
return fields.Textarea(tag)
if tag_type == 'select':
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 51128a8..01e86b9 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -60,12 +60,14 @@ def setUp(self):
+
'''
self.form = Form(self.html)
def test_fields(self):
- keys = set(('vocals', 'guitar', 'drums', 'bass', 'multi', 'submit'))
+ keys = set(('vocals', 'guitar', 'drums', 'bass',
+ 'multi', 'submit', 'yes'))
assert_equal(set(self.form.fields.keys()), keys)
assert_equal(set(self.form.keys()), keys)
@@ -82,7 +84,8 @@ def test_repr(self):
assert_equal(
repr(self.form),
''
+ 'multi=multi1, multi=multi2, submit=submit, '
+ 'yes=yes>'
)
def test_repr_empty(self):
@@ -123,6 +126,8 @@ def setUp(self):
'''
self.form = Form(self.html)
@@ -145,6 +150,8 @@ def test_serialize_multi(self):
serialized = self.form.serialize(submit)
assert_equal(serialized.data['submit1'], 'value1')
assert_false('submit2' in serialized.data)
+ assert_false('submit3' in serialized.data)
+ assert_false('submit4' in serialized.data)
class TestParser(unittest.TestCase):
@@ -169,6 +176,12 @@ def test_parse_input(self):
assert_equal(len(_fields), 1)
assert_true(isinstance(_fields[0], fields.Input))
+ def test_parse_button(self):
+ html = ''
+ _fields = _parse_fields(BeautifulSoup(html))
+ assert_equal(len(_fields), 1)
+ assert_true(isinstance(_fields[0], fields.Button))
+
def test_parse_file_input(self):
html = ''
_fields = _parse_fields(BeautifulSoup(html))
@@ -300,6 +313,52 @@ def test_serialize(self):
)
+class TestButton(unittest.TestCase):
+
+ def setUp(self):
+ self.html = ''
+ self.input = fields.Input(BeautifulSoup(self.html).find('button'))
+
+ def test_name(self):
+ assert_equal(self.input.name, 'brian')
+
+ def test_initial(self):
+ assert_equal(self.input._value, 'may')
+ assert_equal(self.input.value, 'may')
+
+ def test_value(self):
+ self.input.value = 'red special'
+ assert_equal(self.input._value, 'red special')
+ assert_equal(self.input.value, 'red special')
+
+ def test_serialize(self):
+ assert_equal(
+ self.input.serialize(),
+ {'brian': 'may'}
+ )
+
+ def test_invalid_name(self):
+ html = ''
+ assert_raises(exceptions.InvalidNameError, lambda: fields.Button(html))
+
+
+class TestButtonBlank(unittest.TestCase):
+
+ def setUp(self):
+ self.html = ''
+ self.input = fields.Button(BeautifulSoup(self.html).find('button'))
+
+ def test_initial(self):
+ assert_equal(self.input._value, None)
+ assert_equal(self.input.value, '')
+
+ def test_serialize(self):
+ assert_equal(
+ self.input.serialize(),
+ {'blank': ''}
+ )
+
+
class TestTextarea(unittest.TestCase):
def setUp(self):
@@ -628,6 +687,16 @@ def test_input_disabled(self):
input = fields.Input(BeautifulSoup(html).find('input'))
assert_true(input.disabled)
+ def test_button_enabled(self):
+ html = ''
+ input = fields.Button(BeautifulSoup(html).find('button'))
+ assert_false(input.disabled)
+
+ def test_button_disabled(self):
+ html = ''
+ input = fields.Button(BeautifulSoup(html).find('button'))
+ assert_true(input.disabled)
+
def test_checkbox_enabled(self):
html = '''
vocals