当前位置: 首页>>代码示例>>Python>>正文


Python testing.StubRequest类代码示例

本文整理汇总了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
开发者ID:gvenkataraman,项目名称:www.gittip.com,代码行数:7,代码来源:testing.py

示例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
开发者ID:berryp,项目名称:www.gittip.com,代码行数:11,代码来源:__init__.py

示例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()
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:11,代码来源:test_httpdigest.py

示例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
开发者ID:buchuki,项目名称:aspen,代码行数:11,代码来源:test_request.py

示例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()
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:13,代码来源:test_httpdigest.py

示例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)
开发者ID:berryp,项目名称:www.gittip.com,代码行数:14,代码来源:__init__.py

示例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
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:7,代码来源:test_dispatcher.py

示例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
开发者ID:rayleyva,项目名称:aspen,代码行数:7,代码来源:test_gauntlet.py

示例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
开发者ID:ric03uecS,项目名称:aspen-python,代码行数:7,代码来源:test_negotiated_resource.py

示例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"
开发者ID:ric03uecS,项目名称:aspen-python,代码行数:7,代码来源:test_negotiated_resource.py

示例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
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:7,代码来源:test_negotiated_resource.py

示例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
开发者ID:jarpineh,项目名称:aspen,代码行数:7,代码来源:test_negotiated_resource.py

示例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"
开发者ID:ric03uecS,项目名称:aspen-python,代码行数:7,代码来源:test_negotiated_resource.py

示例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
开发者ID:jarpineh,项目名称:aspen,代码行数:7,代码来源:test_negotiated_resource.py

示例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
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:20,代码来源:test_configuration.py


注:本文中的aspen.testing.StubRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。