webtest API¶
webtest.app.TestApp¶
webtest.app.TestRequest¶
webtest.response.TestResponse¶
webtest.forms¶
Helpers to fill and submit forms.
- class webtest.forms.Checkbox(*args, **attrs)[source]¶
Bases:
FieldField representing
<input type="checkbox">- checked¶
Returns True if checkbox is checked.
- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Email(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
FieldField representing
<input type="email">- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Field(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
objectBase class for all Field objects.
- classes¶
Dictionary of field types (select, radio, etc)
- value¶
Set/get value of the field.
- class webtest.forms.File(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
FieldField representing
<input type="file">- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Form(response, text, parser_features='html.parser')[source]¶
Bases:
objectThis object represents a form that has been found in a page.
- Parameters:
response -- webob.response.TestResponse instance
text -- Unparsed html of the form
- text¶
the full HTML of the form.
- action¶
the relative URI of the action.
- method¶
the HTTP method (e.g.,
'GET').
- id¶
the id, or None if not given.
- enctype¶
encoding of the form submission
- fields¶
a dictionary of fields, each value is a list of fields by that name.
<input type="radio">and<select>are both represented as single fields with multiple options.
- field_order¶
Ordered list of field names as found in the html.
- get(name, index=None, default=<NoDefault>)[source]¶
Get the named/indexed field object, or
defaultif no field is found. Throws an AssertionError if no field is found and nodefaultwas given.
- lint()[source]¶
Check that the html is valid:
each field must have an id
each field must have a label
- select(name, value=None, text=None, index=None)[source]¶
Like
.set(), except also confirms the target is a<select>and allows selecting options by text.
- select_multiple(name, value=None, texts=None, index=None)[source]¶
Like
.set(), except also confirms the target is a<select multiple>and allows selecting options by text.
- submit(name=None, index=None, value=None, **args)[source]¶
Submits the form. If
nameis given, then also select that button (usingindexorvalueto disambiguate)``.Any extra keyword arguments are passed to the
webtest.TestResponse.get()orwebtest.TestResponse.post()method.Returns a
webtest.TestResponseobject.
- class webtest.forms.Hidden(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
TextField representing
<input type="hidden">- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.MultipleSelect(*args, **attrs)[source]¶
Bases:
FieldField representing
<select multiple="multiple">
- class webtest.forms.Radio(*args, **attrs)[source]¶
Bases:
SelectField representing
<input type="radio">- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Select(*args, **attrs)[source]¶
Bases:
FieldField representing
<select />form element.
- class webtest.forms.Submit(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
FieldField representing
<input type="submit">and<button>- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Text(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
FieldField representing
<input type="text">- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Textarea(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
TextField representing
<textarea>- force_value(value)¶
Like setting a value, except forces it (even for, say, hidden fields).
- class webtest.forms.Upload(filename, content=None, content_type=None)[source]¶
Bases:
objectA file to upload:
>>> Upload('filename.txt', 'data', 'application/octet-stream') <Upload "filename.txt"> >>> Upload('filename.txt', 'data') <Upload "filename.txt"> >>> Upload("README.txt") <Upload "README.txt">
- Parameters:
filename -- Name of the file to upload.
content -- Contents of the file.
content_type -- MIME type of the file.