Skip to content

Commit

Permalink
Allow to set a string value instead of a list on Browser.displayValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 10, 2017
1 parent 16f8875 commit f949a8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ CHANGES

- Restore the ability to use parts of the actually displayed select box titles.

- Allow to set a string value instead of a list on `Browser.displayValue`.

- Fix setting empty values on a select control.


Expand Down
3 changes: 3 additions & 0 deletions src/zope/testbrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from contextlib import contextmanager

from six.moves import urllib_robotparser
from six import string_types

from zope.interface import implementer
from zope.cachedescriptors.property import Lazy
Expand Down Expand Up @@ -845,6 +846,8 @@ def displayValue(self, value):
if self._browser_counter != self.browser._counter:
raise interfaces.ExpiredError

if isinstance(value, string_types):
value = [value]
values = []
for key, titles in self._getOptions():
if any(v in t
Expand Down
5 changes: 5 additions & 0 deletions src/zope/testbrowser/tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def test_displayValue_partial_title(self):
self.control.displayValue = ['erna']
self.assertEqual(self.control.displayValue, ['Alternative'])

def test_displayValue_handles_set_of_string(self):
self.assertEqual(self.control.displayValue, ['Turn'])
self.control.displayValue = 'erna'
self.assertEqual(self.control.displayValue, ['Alternative'])


def test_relative_redirect(self):
"""
Expand Down

0 comments on commit f949a8c

Please sign in to comment.