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:
Field
Field 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:
Field
Field 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:
object
Base 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:
Field
Field 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:
object
This 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
default
if no field is found. Throws an AssertionError if no field is found and nodefault
was 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
name
is given, then also select that button (usingindex
orvalue
to disambiguate)``.Any extra keyword arguments are passed to the
webtest.TestResponse.get()
orwebtest.TestResponse.post()
method.Returns a
webtest.TestResponse
object.
- class webtest.forms.Hidden(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
Text
Field 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:
Field
Field representing
<select multiple="multiple">
- class webtest.forms.Radio(*args, **attrs)[source]¶
Bases:
Select
Field 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:
Field
Field representing
<select />
form element.
- class webtest.forms.Submit(form, tag, name, pos, value=None, id=None, **attrs)[source]¶
Bases:
Field
Field 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:
Field
Field 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:
Text
Field 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:
object
A 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.