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

Class TestResponse

webtest/response.py:15–547  ·  view source on GitHub ↗

Instances of this class are returned by :class:`~webtest.app.TestApp` methods.

Source from the content-addressed store, hash-verified

13
14
15class TestResponse(webob.Response):
16 """
17 Instances of this class are returned by
18 :class:`~webtest.app.TestApp` methods.
19 """
20
21 request = None
22 _forms_indexed = None
23 parser_features = 'html.parser'
24
25 # Tell pytest not to collect this class as tests
26 __test__ = False
27
28 @property
29 def forms(self):
30 """
31 Returns a dictionary containing all the forms in the pages as
32 :class:`~webtest.forms.Form` objects. Indexes are both in
33 order (from zero) and by form id (if the form is given an id).
34
35 See :doc:`forms` for more info on form objects.
36 """
37 if self._forms_indexed is None:
38 self._parse_forms()
39 return self._forms_indexed
40
41 @property
42 def form(self):
43 """
44 If there is only one form on the page, return it as a
45 :class:`~webtest.forms.Form` object; raise a TypeError is
46 there are no form or multiple forms.
47 """
48 forms_ = self.forms
49 if not forms_:
50 raise TypeError(
51 "You used response.form, but no forms exist")
52 if 1 in forms_:
53 # There is more than one form
54 raise TypeError(
55 "You used response.form, but more than one form exists")
56 return forms_[0]
57
58 @property
59 def testbody(self):
60 self.decode_content()
61 if self.charset:
62 try:
63 return self.text
64 except UnicodeDecodeError:
65 return self.body.decode(self.charset, 'replace')
66 return self.body.decode('ascii', 'replace')
67
68 _tag_re = re.compile(r'<(/?)([:a-z0-9_\-]*)(.*?)>', re.S | re.I)
69
70 def _parse_forms(self):
71 forms_ = self._forms_indexed = {}
72 form_texts = [str(f) for f in self.html('form')]

Callers

nothing calls this directly

Calls 1

to_bytesFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…