Example #1
0
 def test_can_use_get_method_with_unicode_args(self):
     http = HTTP(u"httq.io:8080")
     http.get(u"/hello").response()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     http.close()
Example #2
0
 def test_can_use_get_method_long_hand(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.readable()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     http.close()
Example #3
0
 def test_can_pipeline_multiple_get_requests(self):
     count = 3
     turns = range(1, count + 1)
     http = HTTP(b"httq.io:8080")
     for i in turns:
         http.get("/echo?%d" % i)
         assert len(http._requests) == i
     for i in reversed(turns):
         assert len(http._requests) == i
         assert http.response().status_code == 200
         http.readall()
     assert len(http._requests) == 0
     http.close()
Example #4
0
 def test_can_pipeline_multiple_get_requests(self):
     count = 3
     turns = range(1, count + 1)
     http = HTTP(b"httq.io:8080")
     for i in turns:
         http.get("/echo?%d" % i)
         assert len(http._requests) == i
     for i in reversed(turns):
         assert len(http._requests) == i
         assert http.response().status_code == 200
         http.readall()
     assert len(http._requests) == 0
     http.close()
Example #5
0
 def test_can_read_some_then_all_the_rest_through_content(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello").response()
     assert http.readable()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.read(5) == b"hello"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     assert http.read(5) == b""
     http.close()
Example #6
0
 def test_can_read_some_then_all_the_rest_through_content(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello").response()
     assert http.readable()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.read(5) == b"hello"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     assert http.read(5) == b""
     http.close()
Example #7
0
 def test_can_use_get_method_with_unicode_args(self):
     if sys.version_info >= (3,):
         host = "httq.io:8080"
         path = "/hello"
     else:
         host = "httq.io:8080".decode("utf-8")
         path = "/hello".decode("utf-8")
     http = HTTP(host)
     http.get(path).response()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     http.close()
Example #8
0
 def test_can_use_get_method_with_unicode_args(self):
     if sys.version_info >= (3, ):
         host = "httq.io:8080"
         path = "/hello"
     else:
         host = "httq.io:8080".decode("utf-8")
         path = "/hello".decode("utf-8")
     http = HTTP(host)
     http.get(path).response()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.content == "hello, world"
     assert not http.readable()
     http.close()
Example #9
0
 def test_can_read_in_bits(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello").response()
     assert http.readable()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.read(5) == b"hello"
     assert http.readable()
     assert http.read(5) == b", wor"
     assert http.readable()
     assert http.read(5) == b"ld"
     assert not http.readable()
     assert http.read(5) == b""
     assert http.content == "hello, world"
     http.close()
Example #10
0
 def test_can_read_in_bits(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello").response()
     assert http.readable()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert http.readable()
     assert http.read(5) == b"hello"
     assert http.readable()
     assert http.read(5) == b", wor"
     assert http.readable()
     assert http.read(5) == b"ld"
     assert not http.readable()
     assert http.read(5) == b""
     assert http.content == "hello, world"
     http.close()
Example #11
0
 def test_can_get_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.get(b"/json?foo=bar").response()
     content = response.content
     assert content == {"method": "GET", "query": "foo=bar", "content": ""}
Example #12
0
 def test_request_headers(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_headers == {b"Host": b"httq.io:8080"}
     http.close()
Example #13
0
 def test_request_headers(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_headers == {b"Host": b"httq.io:8080"}
     http.close()
Example #14
0
 def test_request_url(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_url == b"/hello"
     http.close()
Example #15
0
 def test_request_method(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_method == b"GET"
     http.close()
Example #16
0
def main():
    http = HTTP(b"httq.io:8080")
    response = http.get(b"/hello").response()
    print(response.content)
Example #17
0
 def test_request_url(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_url == b"/hello"
     http.close()
Example #18
0
 def test_can_get_unusual_status(self):
     http = HTTP(b"httq.io:8080")
     response = http.get(b"/status?299+Unexpected+Foo").response()
     assert response.status_code == 299
     assert response.reason == 'Unexpected Foo'
Example #19
0
 def test_can_get_unusual_status(self):
     http = HTTP(b"httq.io:8080")
     response = http.get(b"/status?299+Unexpected+Foo").response()
     assert response.status_code == 299
     assert response.reason == 'Unexpected Foo'
Example #20
0
 def test_can_get_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.get(b"/json?foo=bar").response()
     content = response.content
     assert content == {"method": "GET", "query": "foo=bar", "content": ""}
Example #21
0
 def test_request_method(self):
     http = HTTP(b"httq.io:8080")
     http.get(b"/hello")
     http.response()
     assert http.request_method == b"GET"
     http.close()