Skip to content

Commit

Permalink
Restore raising of AttributeError when trying to set value of a read …
Browse files Browse the repository at this point in the history
…only control.
  • Loading branch information
fschulze committed Oct 10, 2017
1 parent 318d972 commit 4702f89
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CHANGES
5.2.2 (unreleased)
------------------

- Restore raising of AttributeError when trying to set value of a
read only control.

- Fix selecting radio and select control options by index
(https://github.com/zopefoundation/zope.testbrowser/issues/31).

Expand Down
21 changes: 21 additions & 0 deletions docs/narrative.rst
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,27 @@ Hidden Control
>>> ctrl.multiple
False

Read Only Control
~~~~~~~~~~~~~~~~~

.. doctest::

>>> ctrl = browser.getControl(name='readonly-value')
>>> ctrl
<Control name='readonly-value' type='text'>
>>> verifyObject(interfaces.IControl, ctrl)
True
>>> ctrl.value
'Read Only Text'
>>> ctrl.value = 'Overwrite'
Traceback (most recent call last):
...
AttributeError: Trying to set value of readonly control
>>> ctrl.readonly
True
>>> ctrl.multiple
False

Text Area Control
~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 6 additions & 0 deletions src/zope/testbrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ def __init__(self, control, form, elem, browser):
def disabled(self):
return 'disabled' in self._control.attrs

@property
def readonly(self):
return 'readonly' in self._control.attrs

@property
def type(self):
typeattr = self._control.attrs.get('type', None)
Expand Down Expand Up @@ -695,6 +699,8 @@ def value(self):
def value(self, value):
if self._browser_counter != self.browser._counter:
raise interfaces.ExpiredError
if self.readonly:
raise AttributeError("Trying to set value of readonly control")
if self.type == 'file':
self.add_file(value, content_type=None, filename=None)
else:
Expand Down
6 changes: 6 additions & 0 deletions src/zope/testbrowser/ftests/controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ <h1>Controls Tests</h1>
<input type="text" name="text-value" id="text-value" value="Some Text" />
</div>

<div>
<label for="text-value">Read Only Control</label>
<em>%(text-value)s</em>
<input type="text" name="readonly-value" id="readonly-value" readonly value="Read Only Text" />
</div>

<div>
<label for="password-value">Password Control</label>
<em>%(password-value)s</em>
Expand Down

0 comments on commit 4702f89

Please sign in to comment.