How to use the webtest.app.AppError function in WebTest

To help you get started, we’ve selected a few WebTest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Pylons / webtest / webtest / app.py View on Github external
def _check_errors(self, res):
        errors = res.errors
        if errors:
            raise AppError(
                "Application had errors logged:\n%s", errors)
github Pylons / webtest / webtest / app.py View on Github external
if re.match(fnmatch.translate(status), res_status, re.I):
                return
        if isinstance(status, string_types):
            if status == res_status:
                return
        if isinstance(status, (list, tuple)):
            if res.status_int not in status:
                raise AppError(
                    "Bad response: %s (not one of %s for %s)\n%s",
                    res_status, ', '.join(map(str, status)),
                    res.request.url, res)
            return
        if status is None:
            if res.status_int >= 200 and res.status_int < 400:
                return
            raise AppError(
                "Bad response: %s (not 200 OK or 3xx redirect for %s)\n%s",
                res_status, res.request.url,
                res)
        if status != res.status_int:
            raise AppError(
                "Bad response: %s (not %s)\n%s", res_status, status, res)
github sloria / webtest-plus / tests / test_webtest_plus.py View on Github external
def test_clickbutton_with_auth(self):
        res = self.app.get("/")
        assert_raises(AppError, lambda: res.clickbutton("Click me"))
        res = self.app.get('/')
        res = res.clickbutton("Click me", auth=self.auth)
github Pylons / webtest / tests / test_debugapp.py View on Github external
def test_errors(self):
        try:
            self.app.get('/?errorlog=somelogs')
            assert(False, "An AppError should be raised")
        except AppError:
            e = sys.exc_info()[1]
            assert six.text_type(e) \
                == "Application had errors logged:\nsomelogs"
github offu / WeRoBot / tests / test_contrib.py View on Github external
response = test_app.get(endpoint, expect_errors=True)

        assert response.status_code == 403
        assert response.body.decode('utf-8') == u'喵'

        xml = """
                
                    
                    
                    1348831860
                    
                    <content></content>
                    1234567890123456
                
                """
        with pytest.raises(AppError):
            # WebTest will raise an AppError
            # if the status_code is not &gt;= 200 and &lt; 400.
            test_app.post(endpoint, xml, content_type="text/xml")

        response = test_app.post(
            endpoint + params, xml, content_type="text/xml"
        )

        assert response.status_code == 200
        response = process_message(parse_xml(response.body))
        assert response.content == 'hello'
github Pylons / webtest / webtest / sel.py View on Github external
def do_request(self, req, status, expect_errors):
        if req.method != 'GET':
            raise testapp.AppError('Only GET are allowed')
        if self.app:
            req.host = '%s:%s' % (self.server.adj.host, self.server.adj.port)
        self.browser.captureNetworkTraffic('json')
        for h, v in req.headers.items():
            if h.lower() not in ('host',):
                self.browser.addCustomRequestHeader(h, v)
        self.browser.open(req.url)
        resp = self._get_response()
        if not expect_errors:
            self._check_status(status, resp)
            if not status:
                status = resp.status_int
                if not (status &gt; 300 and status &lt; 400):
                    self._check_errors(resp)
        return resp
github thisismyrobot / dnstwister / tests / test_atom.py View on Github external
def test_unicode_atom(webapp):
    """Unicode should just work too, this is just a sanity check."""
    unicode_domain = 'xn--plnt-1na.com'.decode('idna')  # 'plànt.com'
    get_path = tools.encode_domain(unicode_domain)
    with pytest.raises(webtest.app.AppError) as err:
        webapp.get('/atom/{}'.format(get_path))
    assert '404 NOT FOUND' in err.value.message
    assert 'New RSS feed generation currently disabled.' in err.value.message