Ticket #371: ticket_371_webtest.patch

File ticket_371_webtest.patch, 3.7 KB (added by greut, 3 years ago)

patching webtest

  • tests/test_testing.py

    diff --git a/tests/test_testing.py b/tests/test_testing.py
    index 7947150..e88f493 100644
    a b  
    2121    assert res.status_int == 200 
    2222    assert res.headers['content-type'] == 'text/plain' 
    2323    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 == '' 
    2429    raises(Exception, app.get, '/?error=t') 
    2530    raises(webtest.AppError, app.get, '/?status=404%20Not%20Found') 
    2631    app.get('/?status=404%20Not%20Found', status=404) 
    2732    raises(webtest.AppError, app.get, '/', status=404) 
    2833    res = app.get('/?status=303%20Redirect&header-location=/foo') 
    2934    assert res.status_int == 303 
    30     print res.location 
    3135    assert res.location == 'http://localhost/foo' 
    3236    assert res.headers['location'] == '/foo' 
    3337    res = res.follow() 
  • webtest/__init__.py

    diff --git a/webtest/__init__.py b/webtest/__init__.py
    index 66c150a..189c5d2 100644
    a b  
    129129 
    130130        Returns a ``webob.Response`` object. 
    131131        """ 
     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): 
    132172        environ = self._make_environ(extra_environ) 
    133173        # Hide from py.test: 
    134174        __tracebackhide__ = True 
     
    145185            url, environ['QUERY_STRING'] = url.split('?', 1) 
    146186        else: 
    147187            environ['QUERY_STRING'] = '' 
     188        environ['REQUEST_METHOD'] = method 
    148189        url = self._remove_fragment(url) 
    149190        req = TestRequest.blank(url, environ) 
    150191        if headers: 
  • webtest/debugapp.py

    diff --git a/webtest/debugapp.py b/webtest/debugapp.py
    index 885f137..308ca0c 100644
    a b  
    2828        if name.startswith('header-'): 
    2929            header_name = name[len('header-'):] 
    3030            headers.append((header_name, value)) 
     31    print req.method 
     32    print headers 
    3133    start_response(status, headers) 
    32     return [body] 
     34    return [body] if req.method <> "HEAD" else [""] 
    3335 
    3436def make_debug_app(global_conf): 
    3537    """