Ticket #371: ticket_371_webtest.patch
| File ticket_371_webtest.patch, 3.7 KB (added by greut, 3 years ago) |
|---|
-
tests/test_testing.py
diff --git a/tests/test_testing.py b/tests/test_testing.py index 7947150..e88f493 100644
a b 21 21 assert res.status_int == 200 22 22 assert res.headers['content-type'] == 'text/plain' 23 23 assert res.content_type == 'text/plain' 24 res = app.head('/') 25 assert res.status_int == 200 26 assert res.headers['content-type'] == 'text/plain' 27 assert res.headers['content-length'] <> '0' 28 assert res.body == '' 24 29 raises(Exception, app.get, '/?error=t') 25 30 raises(webtest.AppError, app.get, '/?status=404%20Not%20Found') 26 31 app.get('/?status=404%20Not%20Found', status=404) 27 32 raises(webtest.AppError, app.get, '/', status=404) 28 33 res = app.get('/?status=303%20Redirect&header-location=/foo') 29 34 assert res.status_int == 303 30 print res.location31 35 assert res.location == 'http://localhost/foo' 32 36 assert res.headers['location'] == '/foo' 33 37 res = res.follow() -
webtest/__init__.py
diff --git a/webtest/__init__.py b/webtest/__init__.py index 66c150a..189c5d2 100644
a b 129 129 130 130 Returns a ``webob.Response`` object. 131 131 """ 132 133 return self._get("GET", url, params, headers, extra_environ, status, 134 expect_errors) 135 136 def head(self, url, params=None, headers=None, extra_environ=None, 137 status=None, expect_errors=False): 138 """ 139 Head on the given url (well, actually a path like 140 ``'/page.html'``). 141 142 ``params``: 143 A query string, or a dictionary that will be encoded 144 into a query string. You may also include a query 145 string on the ``url``. 146 147 ``headers``: 148 A dictionary of extra headers to send. 149 150 ``extra_environ``: 151 A dictionary of environmental variables that should 152 be added to the request. 153 154 ``status``: 155 The integer status code you expect (if not 200 or 3xx). 156 If you expect a 404 response, for instance, you must give 157 ``status=404`` or it will be an error. You can also give 158 a wildcard, like ``'3*'`` or ``'*'``. 159 160 ``expect_errors``: 161 If this is not true, then if anything is written to 162 ``wsgi.errors`` it will be an error. If it is true, then 163 non-200/3xx responses are also okay. 164 165 Returns a ``webob.Response`` object. 166 """ 167 return self._get("HEAD", url, params, headers, extra_environ, status, 168 expect_errors) 169 170 def _get(self, method, url, params=None, headers=None, extra_environ=None, 171 status=None, expect_errors=False): 132 172 environ = self._make_environ(extra_environ) 133 173 # Hide from py.test: 134 174 __tracebackhide__ = True … … 145 185 url, environ['QUERY_STRING'] = url.split('?', 1) 146 186 else: 147 187 environ['QUERY_STRING'] = '' 188 environ['REQUEST_METHOD'] = method 148 189 url = self._remove_fragment(url) 149 190 req = TestRequest.blank(url, environ) 150 191 if headers: -
webtest/debugapp.py
diff --git a/webtest/debugapp.py b/webtest/debugapp.py index 885f137..308ca0c 100644
a b 28 28 if name.startswith('header-'): 29 29 header_name = name[len('header-'):] 30 30 headers.append((header_name, value)) 31 print req.method 32 print headers 31 33 start_response(status, headers) 32 return [body] 34 return [body] if req.method <> "HEAD" else [""] 33 35 34 36 def make_debug_app(global_conf): 35 37 """
