예제 #1
0
def test_invalid_urls():
    with pytest.raises(http3.InvalidURL):
        http3.Request("GET", "example.org")

    with pytest.raises(http3.InvalidURL):
        http3.Request("GET", "invalid://example.org")

    with pytest.raises(http3.InvalidURL):
        http3.Request("GET", "http:///foo")
예제 #2
0
def test_url():
    url = "http://example.org"
    request = http3.Request("GET", url)
    assert request.url.scheme == "http"
    assert request.url.port == 80
    assert request.url.full_path == "/"

    url = "https://example.org/abc?foo=bar"
    request = http3.Request("GET", url)
    assert request.url.scheme == "https"
    assert request.url.port == 443
    assert request.url.full_path == "/abc?foo=bar"
예제 #3
0
def test_override_content_length_header():
    def streaming_body(data):
        yield data  # pragma: nocover

    data = streaming_body(b"test 123")
    headers = {"Content-Length": "8"}

    request = http3.Request("POST", "http://example.org", data=data, headers=headers)
    assert request.headers["Content-Length"] == "8"
예제 #4
0
def test_transfer_encoding_header():
    def streaming_body(data):
        yield data  # pragma: nocover

    data = streaming_body(b"test 123")

    request = http3.Request("POST", "http://example.org", data=data)
    assert "Content-Length" not in request.headers
    assert request.headers["Transfer-Encoding"] == "chunked"
예제 #5
0
def test_override_accept_encoding_header():
    headers = {"Accept-Encoding": "identity"}

    request = http3.Request("GET", "http://example.org", headers=headers)
    assert request.headers["Accept-Encoding"] == "identity"
예제 #6
0
def test_request_repr():
    request = http3.Request("GET", "http://example.org")
    assert repr(request) == "<Request('GET', 'http://example.org')>"
예제 #7
0
def test_override_host_header():
    headers = {"host": "1.2.3.4:80"}

    request = http3.Request("GET", "http://example.org", headers=headers)
    assert request.headers["Host"] == "1.2.3.4:80"
예제 #8
0
def test_content_length_header():
    request = http3.Request("POST", "http://example.org", data=b"test 123")
    assert request.headers["Content-Length"] == "8"
예제 #9
0
def test_no_content():
    request = http3.Request("GET", "http://example.org")
    assert "Content-Length" not in request.headers