Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_app_error(self):
resp = Response(to_bytes('blah'))
err = webtest.AppError('message %s', resp)
self.assertEqual(err.args, ('message blah',))
username = 'user'
password = 'pass'
wh = webhook.WebHookHandler(username, password, callback, None)
app = TestApp(wh.application)
resp = app.post_json('/', {'head_commit':{'commit':'id'}},
headers={'Authorization':make_auth_header(username,password)})
assert resp.status_int == 200
assert resp.normal_body == 'OK'
assert called.is_set()
called.clear()
with pytest.raises(AppError) as ex:
resp = app.post_json('/', {'head_commit':{'commit':'id'}})
assert not called.is_set()
def testGetConfigNoConfigFile(self):
restServerTestApp = self.setupRestWithTwoDevices()
with self.assertRaises(AppError) as e:
restServerTestApp.get('/pods/test1/devices/test1/config')
self.assertTrue('404 Not Found' in e.exception.message)
self.assertTrue('Device exists but no config found' in e.exception.message)
def test_unregistered(self):
try:
self.app.get('/templation/1234/')
except AppError as e:
self.assertTrue(e.message.startswith("Bad response: 401 Not Authorized"))
def test_app_error_misc(self):
resp = Response(six.u('\xe9').encode('utf8'))
resp.charset = ''
# dont check the output. just make sure it doesn't fail
webtest.AppError(to_bytes('message %s'), resp)
webtest.AppError(six.u('messag\xe9 %s'), six.b('\xe9'))
def test_create_cluster_value_error(self):
self._scheduler.set_exception(ValueError())
with pytest.raises(AppError) as e:
self._app.post('/clusters/test_cluster', {'num_nodes': 3, 'cluster_user': 'mysos'})
assert e.value.message.startswith('Bad response: 400')
def test_check_status_none(self):
self.assertEqual(self.check_status('200 Ok', None), None)
self.assertRaises(webtest.AppError, self.check_status, '400 Ok')
def get_assert_403(self, url, user):
try:
self.app.get(url, user=user, status=403)
except AppError as e:
self.fail('url "{}" failed with user "{}"'.format(url, user))
def test_exception(self):
self.assertRaises(Exception, self.app.get, '/?error=t')
self.assertRaises(webtest.AppError, self.app.get,
'/?status=404%20Not%20Found')