コード例 #1
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_cannot_use_unknown_scheme():
    resource = Resource("xxxx://www.example.com/")
    try:
        resource.get()
    except ValueError:
        assert True
    else:
        assert False
コード例 #2
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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"
コード例 #3
0
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
コード例 #4
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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
コード例 #5
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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)
コード例 #6
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_infinity_is_detected():
    resource = Resource("http://localhost:8080/infinity")
    try:
        resource.get()
    except RedirectionError:
        assert True
    else:
        assert False
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
ファイル: http_test.py プロジェクト: frankier/httpstream
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)
コード例 #10
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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
コード例 #11
0
def test_infinity_is_detected():
    resource = Resource("http://localhost:8080/infinity")
    try:
        resource.get()
    except RedirectionError:
        assert True
    else:
        assert False
コード例 #12
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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)
コード例 #13
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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)
コード例 #14
0
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)
コード例 #15
0
ファイル: http_test.py プロジェクト: frankier/httpstream
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
コード例 #16
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
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
コード例 #17
0
def test_can_set_product_in_user_agent():
    test_product = ("FooBar", "1.2.3")
    resource = Resource("http://localhost:8080/user_agent")
    headers = {"User-Agent": "/".join(test_product)}
    with resource.get(headers=headers) as response:
        assert isinstance(response, TextResponse)
        bits = response.content.split()
        received_product = tuple(bits[0].split("/"))
        assert received_product == test_product
コード例 #18
0
def test_can_get_simple_text_resource_with_caching():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get(cache=True)
    assert response.content_type.startswith("text/")
    assert isinstance(response, TextResponse)
    assert not response.consumed
    assert response.content == "hello, world"
    assert response.consumed
    assert response.content == "hello, world"
コード例 #19
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
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
コード例 #20
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_delete_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.delete()
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "goodbye, cruel world"
コード例 #21
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_put_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.put("fred")
    assert isinstance(response, TextResponse)
    content = response.read().decode("utf-8")
    assert content == "hello, fred"
コード例 #22
0
def test_can_get_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get()
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "hello, world"
コード例 #23
0
def test_can_get_simple_html_resource():
    resource = Resource("http://localhost:8080/document")
    response = resource.get()
    assert isinstance(response, HTMLResponse)
コード例 #24
0
def test_can_delete_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.delete()
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "goodbye, cruel world"
コード例 #25
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
def test_can_get_simple_uri():
    resource = Resource("http://localhost:8080/person/")
    rs = resource.get()
    assert rs.status_code == 200
コード例 #26
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
def test_can_create_resource_from_string():
    resource = Resource("http://example.com/foo")
    assert resource.uri == URI("http://example.com/foo")
    assert bool(resource)
    assert str(resource) == "<http://example.com/foo>"
コード例 #27
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
def test_can_create_resource_from_uri():
    uri = URI("http://example.com/foo")
    resource = Resource(uri)
    assert resource.uri == uri
    assert bool(resource)
    assert str(resource) == "<http://example.com/foo>"
コード例 #28
0
def test_can_put_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.put("fred")
    assert isinstance(response, TextResponse)
    content = response.read().decode("utf-8")
    assert content == "hello, fred"
コード例 #29
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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
コード例 #30
0
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
コード例 #31
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_send_header():
    resource = Resource("http://localhost:8080/hello")
    response = resource.put("fred", headers={"X-Upper-Case": True})
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "HELLO, FRED"
コード例 #32
0
ファイル: resource_test.py プロジェクト: jayvdb/httpstream
def test_can_create_none_resource():
    resource = Resource(None)
    assert resource.uri == URI(None)
    assert not bool(resource)
    assert str(resource) == "<>"
コード例 #33
0
def test_auto_populate_uri_scheme():
    resource = Resource("nigelsmall.com")
    response = resource.get()
    assert response.uri == "http://nigelsmall.com"
コード例 #34
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_get_multi_object_json_resource():
    resource = Resource("http://localhost:8080/person/")
    with resource.get() as response:
        assert isinstance(response, JSONResponse)
        for (name,), person in grouped(response):
            assert assembled(person) == PEOPLE[name]
コード例 #35
0
def test_can_send_header():
    resource = Resource("http://localhost:8080/hello")
    response = resource.put("fred", headers={"X-Upper-Case": True})
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "HELLO, FRED"
コード例 #36
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
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"
コード例 #37
0
ファイル: http_test.py プロジェクト: frankier/httpstream
def test_can_get_block_json_resource():
    resource = Resource("http://localhost:8080/object")
    with resource.get() as response:
        assert response.is_json
        assert response.json == OBJECT
コード例 #38
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_get_block_json_resource():
    resource = Resource("http://localhost:8080/object")
    with resource.get() as response:
        assert isinstance(response, JSONResponse)
        assert response.content == OBJECT
コード例 #39
0
def test_can_get_multi_object_json_resource():
    resource = Resource("http://localhost:8080/person/")
    with resource.get() as response:
        assert isinstance(response, JSONResponse)
        for (name,), person in grouped(response):
            assert assembled(person) == PEOPLE[name]
コード例 #40
0
ファイル: http_test.py プロジェクト: zbyufei/httpstream
def test_can_get_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.get()
    assert isinstance(response, TextResponse)
    content = response.read().decode(response.encoding)
    assert content == "hello, world"
コード例 #41
0
ファイル: resource_test.py プロジェクト: frankier/httpstream
def test_can_get_substituted_uri():
    ddg = Resource("https://api.duckduckgo.com/?q={q}&format=json")
    rs = ddg.get(q="neo4j")
    for key, value in rs:
        print(key, value)
    assert rs.status_code == 200
コード例 #42
0
def test_can_get_block_json_resource():
    resource = Resource("http://localhost:8080/object")
    with resource.get() as response:
        assert isinstance(response, JSONResponse)
        assert response.content == OBJECT
コード例 #43
0
ファイル: http_test.py プロジェクト: frankier/httpstream
def test_can_post_simple_text_resource():
    resource = Resource("http://localhost:8080/hello")
    response = resource.post("fred")
    assert response.is_text
    content = response.read().decode(response.encoding)
    assert content == "hello, world and fred"
コード例 #44
0
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"
コード例 #45
0
ファイル: resource_test.py プロジェクト: frankier/httpstream
def test_can_get_simple_uri():
    ddg = Resource("http://duckduckgo.com")
    rs = ddg.get()
    assert rs.status_code == 200