Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def method_not_allowed_app(req):
if req.method != "GET":
raise webob_exc.HTTPMethodNotAllowed()
return "hello!"
def test_origin_db_head(self):
prev_data = json.dumps({'account': 'acc', 'container': 'cont',
'ttl': 1234, 'logs_enabled': 'true', 'cdn_enabled': 'false'})
self.test_origin.app = FakeApp(iter([
('204 No Content', {}, prev_data)])) # call to _get_cdn_data
req = Request.blank('http://origin_db.com:8080/v1/acc/cont',
environ={'REQUEST_METHOD': 'HEAD'})
resp = req.get_response(self.test_origin)
self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers['x-ttl'], 1234)
self.sent += 1
return ' '
return ''
req = Request.blank('/a/c/o',
environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': SlowBody()},
headers={'Content-Length': '4', 'Content-Type': 'text/plain'})
self.app.update_request(req)
controller = proxy_server.ObjectController(self.app, 'account',
'container', 'object')
proxy_server.http_connect = \
fake_http_connect(200, 200, 201, 201, 201)
# acct cont obj obj obj
resp = controller.PUT(req)
self.assertEquals(resp.status_int, 201)
self.app.client_timeout = 0.1
req = Request.blank('/a/c/o',
environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': SlowBody()},
headers={'Content-Length': '4', 'Content-Type': 'text/plain'})
self.app.update_request(req)
proxy_server.http_connect = \
fake_http_connect(201, 201, 201)
# obj obj obj
resp = controller.PUT(req)
self.assertEquals(resp.status_int, 408)
def test_ignore_robotstxt():
"""Ignore the robots.txt resource on root resources."""
class Dummy(wsgiservice.Resource):
_path = '/{id}'
def GET(self, id):
return id
req = webob.Request.blank('/robots.txt')
res = webob.Response()
usr = Dummy(request=req, response=res, path_params={})
res = usr()
print(res)
assert res.status_int == 404
def test_auth_bad_path(self):
res = self.controller.handle_auth(
Request.blank('', environ={'REQUEST_METHOD': 'GET'}))
self.assertEquals(res.status_int, 400)
res = self.controller.handle_auth(Request.blank('/bad',
environ={'REQUEST_METHOD': 'GET'}))
self.assertEquals(res.status_int, 400)
def test_method(self):
r = route(POST, 'news', 'target')
req = Request.blank('/news', {'REQUEST_METHOD': 'POST'})
tr = r(req)
self.assertEqual(
(tr.args, tr.kwargs, tr.target),
((), {}, 'target'))
self.assertRaises(
MethodNotAllowed,
r, Request.blank('/news', {'REQUEST_METHOD': 'DELETE'}))
def test_get_action_success(self, m_repository):
contents = random_string()
cfg = {'return_value.read.return_value': contents}
m_repository.return_value.get_file.configure_mock(**cfg)
filename = random_string()
url = '/actions/%s' % filename
request = Request.blank(url)
resp = request.get_response(ztpserver.controller.Router())
m_repository.return_value.get_file.assert_called_with(url[1:])
self.assertEqual(resp.status_code, constants.HTTP_STATUS_OK)
self.assertEqual(resp.content_type, constants.CONTENT_TYPE_PYTHON)
self.assertEqual(resp.body, contents)
def test_webob_client_request_normalization(httpbin):
import webob
raw_request = webob.Request.blank(httpbin.url + '/get')
raw_request.query_string = 'key=val'
raw_request.method = 'GET'
raw_request.content_type = 'application/json'
request = normalize_request(raw_request)
assert request.path == '/get'
assert request.content_type == 'application/json'
assert request.url == httpbin.url + '/get?key=val'
assert request.method == 'get'
def simple_app(environ, start_response):
req = wo.Request(environ)
ct = 'text/html' if req.path == '/' else 'test/plain'
resp = wo.Response(request=req, content_type="%s; charset=UTF8" % ct)
inject_widget.display()
if six.PY3:
resp.text = html
else:
resp.body = html
return resp(environ, start_response)
def request(path, allow_post=False, **kwargs):
app = geodude.make_application(fake_geo_data, allow_post)
request = Request.blank(path, **kwargs)
return request.get_response(app)