本文整理汇总了Python中aspen.testing.StubRequest类的典型用法代码示例。如果您正苦于以下问题:Python StubRequest类的具体用法?Python StubRequest怎么用?Python StubRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StubRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serve_request
def serve_request(path):
"""Given an URL path, return response.
"""
request = StubRequest(path)
request.website = test_website
response = test_website.handle_safely(request)
return response
示例2: serve_request
def serve_request(path, user=None):
"""Given an URL path, return response.
"""
request = StubRequest(path)
request.website = test_website
if user is not None:
user = User.from_id(user)
# Note that Cookie needs a bytestring.
request.headers.cookie[str('session')] = user.session_token
response = test_website.handle_safely(request)
return response
示例3: test_bad_fails
def test_bad_fails():
request = StubRequest()
# once to get a WWW-Authenticate header
hook = inbound_responder(_auth_func("username", "password"), realm="[email protected]")
response = assert_raises(Response, hook, request)
# do something with the header
auth_headers = _auth_headers(response)
request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "badpassword")
response = assert_raises(Response, hook, request)
assert response.code == 401, response
assert not request.auth.authorized()
示例4: test_methods_changing_changes
def test_methods_changing_changes():
request = StubRequest()
request.method = 'POST'
assert not request.OPTIONS
assert not request.GET
assert not request.HEAD
assert request.POST
assert not request.PUT
assert not request.DELETE
assert not request.TRACE
assert not request.CONNECT
示例5: test_good_works
def test_good_works():
request = StubRequest()
# once to get a WWW-Authenticate header
hook = inbound_responder(_auth_func("username", "password"), realm="[email protected]")
response = assert_raises(Response, hook, request)
# do something with the header
auth_headers = _auth_headers(response)
request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "password")
#print repr(request.headers['Authorization'])
response = hook(request)
success = request.auth.authorized()
assert success
assert request.auth.username() == "username", request.auth.username()
示例6: load_simplate
def load_simplate(path):
"""Given an URL path, return resource.
"""
request = StubRequest(path)
request.website = test_website
# XXX HACK - aspen.website should be refactored
from aspen import dispatcher, sockets
test_website.hooks.run('inbound_early', request)
dispatcher.dispatch(request) # sets request.fs
request.socket = sockets.get(request)
test_website.hooks.run('inbound_late', request)
return resources.get(request)
示例7: test_aspen_favicon_doesnt_get_clobbered_by_virtual_path
def test_aspen_favicon_doesnt_get_clobbered_by_virtual_path():
mk('%value.spt')
request = StubRequest.from_fs('/favicon.ico')
dispatcher.dispatch(request)
expected = {}
actual = request.line.uri.path
assert actual == expected, actual
示例8: test_aspen_favicon_doesnt_get_clobbered_by_virtual_path
def test_aspen_favicon_doesnt_get_clobbered_by_virtual_path():
mk('%value')
request = StubRequest.from_fs('/favicon.ico')
gauntlet.run_through(request, gauntlet.not_found)
expected = {}
actual = request.line.uri.path
assert actual == expected, actual
示例9: test_get_response_406_gives_list_of_acceptable_types
def test_get_response_406_gives_list_of_acceptable_types(mk):
mk(("index.spt", NEGOTIATED_RESOURCE))
request = StubRequest.from_fs("index.spt")
request.headers["Accept"] = "cheese/head"
actual = raises(Response, get_response, request, Response()).value.body
expected = "The following media types are available: text/plain, text/html."
assert actual == expected
示例10: test_handles_busted_accept
def test_handles_busted_accept(mk):
mk(("index.spt", NEGOTIATED_RESOURCE))
request = StubRequest.from_fs("index.spt")
# Set an invalid Accept header so it will return default (text/plain)
request.headers["Accept"] = "text/html;"
actual = get_response(request, Response()).body
assert actual == "Greetings, program!\n"
示例11: test_can_override_default_renderer_entirely
def test_can_override_default_renderer_entirely():
mk(('.aspen/configure-aspen.py', OVERRIDE_SIMPLATE),
('index.spt', NEGOTIATED_RESOURCE))
request = StubRequest.from_fs('index.spt')
request.headers['Accept'] = 'text/plain'
actual = get_response(request, Response()).body
assert actual == "glubber", actual
示例12: test_get_response_doesnt_reset_content_type_when_not_negotiating
def test_get_response_doesnt_reset_content_type_when_not_negotiating():
mk(('index', NEGOTIATED_RESOURCE))
request = StubRequest.from_fs('index')
response = Response()
response.headers['Content-Type'] = 'never/mind'
actual = get_response(request, response).headers['Content-Type']
assert actual == "never/mind", actual
示例13: test_get_response_doesnt_reset_content_type_when_not_negotiating
def test_get_response_doesnt_reset_content_type_when_not_negotiating(mk):
mk(("index.spt", NEGOTIATED_RESOURCE))
request = StubRequest.from_fs("index.spt")
response = Response()
response.headers["Content-Type"] = "never/mind"
actual = get_response(request, response).headers["Content-Type"]
assert actual == "never/mind"
示例14: test_get_response_406_gives_list_of_acceptable_types
def test_get_response_406_gives_list_of_acceptable_types():
mk(('index', NEGOTIATED_RESOURCE))
request = StubRequest.from_fs('index')
request.headers['Accept'] = 'cheese/head'
actual = assert_raises(Response, get_response, request, Response()).body
expected ="The following media types are available: text/plain, text/html."
assert actual == expected, actual
示例15: test_configuration_script_can_set_renderer_default
def test_configuration_script_can_set_renderer_default():
CONFIG = """
website.renderer_default="stdlib_format"
"""
SIMPLATE = """
name="program"
[----]
Greetings, {name}!
"""
mk(
('.aspen/configure-aspen.py', CONFIG),
('index.html.spt', SIMPLATE)
)
w = Website(['--www_root', FSFIX, '-p', fix('.aspen'), '--show_tracebacks=yes'])
request = StubRequest(b'/')
request.website = w
response = w.handle_safely(request)
actual = response.body.strip()
expected = 'Greetings, program!'
assert actual == expected, actual