MCPcopy Create free account
hub / github.com/Pylons/webtest / __setitem__

Method __setitem__

webtest/forms.py:514–541  ·  view source on GitHub ↗

Set the value of the named field. If there is 0 or multiple fields by that name, it is an error. Multiple checkboxes of the same name are special-cased; a list may be assigned to them to check the checkboxes whose value is present in the list (and uncheck all others)

(self, name, value)

Source from the content-addressed store, hash-verified

512 self.fields = fields
513
514 def __setitem__(self, name, value):
515 """Set the value of the named field. If there is 0 or multiple fields
516 by that name, it is an error.
517
518 Multiple checkboxes of the same name are special-cased; a list may be
519 assigned to them to check the checkboxes whose value is present in the
520 list (and uncheck all others).
521
522 Setting the value of a ``<select>`` selects the given option (and
523 confirms it is an option). Setting radio fields does the same.
524 Checkboxes get boolean values. You cannot set hidden fields or buttons.
525
526 Use ``.set()`` if there is any ambiguity and you must provide an index.
527 """
528 fields = self.fields.get(name)
529 assert fields is not None, (
530 "No field by the name %r found (fields: %s)"
531 % (name, ', '.join(map(repr, self.fields.keys()))))
532 all_checkboxes = all(isinstance(f, Checkbox) for f in fields)
533 if all_checkboxes and isinstance(value, list):
534 values = {utils.stringify(v) for v in value}
535 for f in fields:
536 f.checked = f._value in values
537 else:
538 assert len(fields) == 1, (
539 "Multiple fields match %r: %s"
540 % (name, ', '.join(map(repr, fields))))
541 fields[0].value = value
542
543 def __getitem__(self, name):
544 """Get the named field object (ambiguity is an error)."""

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected