Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_errors(self, res):
errors = res.errors
if errors:
raise AppError(
"Application had errors logged:\n%s", errors)
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)
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)
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"
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 >= 200 and < 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'
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 > 300 and status < 400):
self._check_errors(resp)
return resp
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