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


Python httpstream.Resource类代码示例

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


在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cannot_use_unknown_scheme

def test_cannot_use_unknown_scheme():
    resource = Resource("xxxx://www.example.com/")
    try:
        resource.get()
    except ValueError:
        assert True
    else:
        assert False
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例2: test_can_get_simple_text_resource_with_caching

def test_can_get_simple_text_resource_with_caching():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get(cache=True)
    assert isinstance(response, TextResponse)
    assert not response.consumed
    assert response.content == "hello, world"
    assert response.consumed
    assert response.content == "hello, world"
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例3: test_can_get_simple_json_resource_with_caching

def test_can_get_simple_json_resource_with_caching():
    resource = Resource("http://localhost:8080/object")
    with resource.get(cache=True) as response:
        assert isinstance(response, JSONResponse)
        assert not response.consumed
        assert response.content == OBJECT
        assert response.consumed
        assert response.content == OBJECT
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例4: test_infinity_is_detected

def test_infinity_is_detected():
    resource = Resource("http://localhost:8080/infinity")
    try:
        resource.get()
    except RedirectionError:
        assert True
    else:
        assert False
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例5: test_can_get_multi_line_hebrew_text_resource

def test_can_get_multi_line_hebrew_text_resource():
    resource = Resource("http://localhost:8080/genesis")
    expected_lines = GENESIS.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例6: test_can_get_big_resource_with_small_chunk_size

def test_can_get_big_resource_with_small_chunk_size():
    resource = Resource("http://localhost:8080/lorem_ipsum")
    expected_lines = LOREM_IPSUM.splitlines()
    with resource.get() as response:
        response.chunk_size = 10
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例7: test_can_get_multi_line_text_resource

def test_can_get_multi_line_text_resource():
    resource = Resource("http://localhost:8080/lorem_ipsum")
    expected_lines = LOREM_IPSUM.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert response.is_text
        for line in response:
            assert line == expected_lines.pop(0)
开发者ID:frankier,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例8: test_can_get_multi_line_cyrillic_text_resource

def test_can_get_multi_line_cyrillic_text_resource():
    resource = Resource("http://localhost:8080/war_and_peace")
    expected_lines = WAR_AND_PEACE.splitlines()
    with resource.get() as response:
        response.chunk_size = 37
        assert isinstance(response, TextResponse)
        for line in response:
            assert line == expected_lines.pop(0)
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例9: test_can_set_product_in_user_agent

def test_can_set_product_in_user_agent():
    test_product = ("FooBar", "1.2.3")
    resource = Resource("http://localhost:8080/user_agent")
    with resource.get(product=test_product) as response:
        assert response.is_text
        bits = response.read().decode(response.encoding).split()
        received_product = tuple(bits[0].split("/"))
        assert received_product == test_product
开发者ID:frankier,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例10: test_can_set_product_in_user_agent

def test_can_set_product_in_user_agent():
    test_product = ("FooBar", "1.2.3")
    resource = Resource("http://localhost:8080/user_agent")
    with resource.get(product=test_product) as response:
        assert isinstance(response, TextResponse)
        bits = response.content.split()
        received_product = tuple(bits[0].split("/"))
        assert received_product == test_product
开发者ID:zbyufei,项目名称:httpstream,代码行数:8,代码来源:http_test.py

示例11: test_bad_hostname_will_fail

def test_bad_hostname_will_fail():
    resource = Resource("http://localtoast:6789")
    try:
        resource.get()
    except NetworkAddressError as err:
        assert True
        assert err.host_port == "localtoast:6789"
    else:
        assert False
开发者ID:jayvdb,项目名称:httpstream,代码行数:9,代码来源:resource_test.py

示例12: test_bad_port_will_fail

def test_bad_port_will_fail():
    resource = Resource("http://localhost:6789")
    try:
        resource.get()
    except SocketError as err:
        assert True
        assert err.code == 111
        assert err.host_port == "localhost:6789"
    else:
        assert False
开发者ID:jayvdb,项目名称:httpstream,代码行数:10,代码来源:resource_test.py

示例13: test_can_get_simple_html_resource

def test_can_get_simple_html_resource():
    resource = Resource("http://localhost:8080/document")
    response = resource.get()
    assert isinstance(response, HTMLResponse)
开发者ID:jayvdb,项目名称:httpstream,代码行数:4,代码来源:http_test.py

示例14: test_can_get_simple_json_resource

def test_can_get_simple_json_resource():
    resource = Resource("http://localhost:8080/object")
    with resource.get() as response:
        assert isinstance(response, JSONResponse)
        assert assembled(response) == OBJECT
开发者ID:zbyufei,项目名称:httpstream,代码行数:5,代码来源:http_test.py

示例15: test_can_follow_simple_redirect

def test_can_follow_simple_redirect():
    resource = Resource("http://localhost:8080/old")
    with resource.get() as response:
        assert response.status_code == OK
        assert response.uri == "http://localhost:8080/new"
开发者ID:zbyufei,项目名称:httpstream,代码行数:5,代码来源:http_test.py


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