Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.s = http.StopableWSGIServer.create(debug_app)
self.s.wait()
self.application_url = self.s.application_url.rstrip('/')
def test_repr(self):
def _repr(v):
br = repr(v)
if len(br) > 18:
br = br[:10] + '...' + br[-5:]
br += '/%s' % len(v)
return br
app = webtest.TestApp(debug_app)
res = app.post('/')
self.assertEqual(
repr(res),
'<200 OK text/plain body=%s>' % _repr(res.body)
)
res.content_type = None
self.assertEqual(
repr(res),
'<200 OK body=%s>' % _repr(res.body)
)
res.location = 'http://pylons.org'
self.assertEqual(
repr(res),
'<200 OK location: http://pylons.org body=%s>' % _repr(res.body)
)
def test_mustcontains(self):
app = webtest.TestApp(debug_app)
res = app.post('/', params='foobar')
res.mustcontain('foobar')
self.assertRaises(IndexError, res.mustcontain, 'not found')
res.mustcontain('foobar', no='not found')
res.mustcontain('foobar', no=['not found', 'not found either'])
self.assertRaises(IndexError, res.mustcontain, no='foobar')
self.assertRaises(
TypeError,
res.mustcontain, invalid_param='foobar'
)
def test_url_without_fragments(self):
app = webtest.TestApp(debug_app)
res = app.get('http://localhost/')
self.assertEqual(res.status_int, 200)
def test_get_extra_environ(self):
app = webtest.TestApp(debug_app,
extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
'foo': 'bar'})
res = app.get('http://localhost/')
self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
self.assertIn("foo: 'bar'", res, res)
res = app.get('http://localhost/', extra_environ={'foo': 'baz'})
self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
self.assertIn("foo: 'baz'", res, res)
def test_url_with_fragments(self):
app = webtest.TestApp(debug_app)
res = app.get('http://localhost/#ananchor')
self.assertEqual(res.status_int, 200)
def test_post_extra_environ(self):
app = webtest.TestApp(debug_app,
extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
'foo': 'bar'})
res = app.post('http://localhost/')
self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
self.assertIn("foo: 'bar'", res, res)
res = app.post('http://localhost/', extra_environ={'foo': 'baz'})
self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
self.assertIn("foo: 'baz'", res, res)