Took me a while to figure out how to provide data for an
AutoCompleteField using testutil.BrowsingSession.goto so that it also
passes validation. All the googling in the world didn't help me so
eventually I installed ethereal and checked for myself what was going
on. So, in case anyone else needs this or (even better) if you know
how to do this more easily, here goes:
user = testutil.BrowsingSession()
url = compose_url('address_check', postcode='33333', number='33',
extra='A')
# this was the mysterious part for me:
# autocomplete goes in the form of [field name].text&[field
name].hidden:
url += '&' + 'address.text=%s&address.hidden=%s' %
(urllib.quote('test'), urllib.quote(''))
#
# these are just for completeness (sorry about the long post):
#
def compose_url(method, **params):
""" create request url string to given method with given
parameters """
pairs = ['%s=%s' % (k, urllib.quote(params[k])) for k in params]
url = '/%s?' % method
url = url + '&'.join(pairs)
return url
class AddressFieldSchema(validators.Schema):
""" validates the autocomplete field of the address """ยด
def _to_python(self, value, state):
text = value['text']
value['text'] = validators.UnicodeString(
strip=True,
min=3,
max=60,
not_empty=True).to_python(text)
return value
class AddressFormSchema(validators.Schema):
""" address form validator """
address = AddressFieldSchema()
postcode = validators.UnicodeString(max=30, strip=True)
number = validators.UnicodeString(max=30, strip=True)
extra = validators.UnicodeString(max=30, strip=True)
class AddressFields(widgets.WidgetsList):
""" input fields for an address """
address = widgets.AutoCompleteField(
search_controller = "search_address",
search_param = "input",
result_name = "matches")
postcode = widgets.TextField()
number = widgets.TextField()
extra = widgets.TextField()
# address form instance
address_form = widgets.TableForm(
fields=AddressFields(),
validator=AddressFormSchema(),
action="address_check",
submit_text=_("Next"))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---