• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.StubRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中aspen.testing.StubRequest的典型用法代码示例。如果您正苦于以下问题:Python StubRequest类的具体用法?Python StubRequest怎么用?Python StubRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StubRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: test_can_override_default_renderer_entirely

def test_can_override_default_renderer_entirely():
    mk(('.aspen/configure-aspen.py', """\
from aspen.renderers import Renderer, Factory

class Glubber(Renderer):
    def render_content(self, context):
        return "glubber"

class GlubberFactory(Factory):
    Renderer = Glubber

website.renderer_factories['glubber'] = GlubberFactory(website)
website.default_renderers_by_media_type.default = 'glubber'

"""), ('index', NEGOTIATED_RESOURCE))
    request = StubRequest.from_fs('index')
    request.headers['Accept'] = 'text/plain'
    actual = get_response(request, Response()).body
    assert actual == "glubber", actual
开发者ID:jarpineh,项目名称:aspen,代码行数:19,代码来源:test_negotiated_resource.py


示例17: check_index

def check_index(path, *a):
    """Given a uripath, return a filesystem path per gauntlet.index.
    """
    request = StubRequest.from_fs(path, *a)
    gauntlet.run_through(request, gauntlet.index)
    return request
开发者ID:jarpineh,项目名称:aspen,代码行数:6,代码来源:test_gauntlet.py


示例18: check_indirect_negotiation

def check_indirect_negotiation(path):
    """Given an urlpath, return a filesystem path per gauntlet.virtual_paths.
    """
    request = StubRequest.from_fs(path)
    gauntlet.run_through(request, gauntlet.indirect_negotiation)
    return request
开发者ID:jarpineh,项目名称:aspen,代码行数:6,代码来源:test_gauntlet.py


示例19: test_get_response_sets_content_type_when_it_doesnt_negotiate

def test_get_response_sets_content_type_when_it_doesnt_negotiate():
    mk(('index.spt', NEGOTIATED_RESOURCE))
    request = StubRequest.from_fs('index.spt')
    actual = get_response(request, Response()).headers['Content-Type']
    assert actual == "text/plain; charset=UTF-8", actual
开发者ID:ArmstrongJ,项目名称:aspen-python,代码行数:5,代码来源:test_negotiated_resource.py


示例20: test_is_xhr_is_case_insensitive

def test_is_xhr_is_case_insensitive():
    request = StubRequest()
    request.headers['X-Requested-With'] = 'xMLhTTPrEQUEST'
    assert request.is_xhr()
开发者ID:jarpineh,项目名称:aspen,代码行数:4,代码来源:test_request.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.Client类代码示例发布时间:2022-05-24
下一篇:
Python testing.mk函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap