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.

force_value(value)[source]

Like setting a value, except forces it (even for, say, hidden fields).

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.

FieldClass

alias of Field

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 no default 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.

set(name, value, index=None)[source]

Set the given name, using index to disambiguate.

submit(name=None, index=None, value=None, **args)[source]

Submits the form. If name is given, then also select that button (using index or value to disambiguate)``.

Any extra keyword arguments are passed to the webtest.TestResponse.get() or webtest.TestResponse.post() method.

Returns a webtest.TestResponse object.

submit_fields(name=None, index=None, submit_value=None)[source]

Return a list of [(name, value), ...] for the current state of the form.

Parameters:
upload_fields()[source]

Return a list of file field tuples of the form:

(field name, file name)

or:

(field name, file name, file contents).
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">

force_value(values)[source]

Like setting a value, except forces it (even for, say, hidden fields).

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.

force_value(value)[source]

Like setting a value, except forces it (even for, say, hidden fields).

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.

webtest.http

webtest.lint

webtest.debugapp