Ejemplo n.º 1
0
 def test_can_delete_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.delete(b"/json?foo=bar").response()
     content = response.content
     assert content == {
         "method": "DELETE",
         "query": "foo=bar",
         "content": ""
     }
Ejemplo n.º 2
0
 def test_can_post_dict_as_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.post(b"/json?foo=bar", {"bee": "bumble"}).response()
     content = response.content
     assert content == {
         "method": "POST",
         "query": "foo=bar",
         "content": '{"bee": "bumble"}'
     }
Ejemplo n.º 3
0
 def test_can_put_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.put(b"/json?foo=bar", b"bumblebee").response()
     content = response.content
     assert content == {
         "method": "PUT",
         "query": "foo=bar",
         "content": "bumblebee"
     }
Ejemplo n.º 4
0
 def test_can_post_json_in_chunks(self):
     http = HTTP(b"httq.io:8080")
     http.post(b"/json?foo=bar")
     http.write(b"bum")
     http.write(b"ble")
     http.write(b"bee")
     http.write(b"")
     response = http.response()
     content = response.content
     assert content == {"method": "POST", "query": "foo=bar", "content": "bumblebee"}
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
 def test_can_use_head_method_long_hand(self):
     http = HTTP(b"httq.io:8080")
     http.head(b"/hello")
     http.response()
     assert http.status_code == 200
     assert http.reason == "OK"
     assert http.content_type == "text/plain"
     assert not http.readable()
     assert http.content is None
     http.close()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import sys
from httq import HTTP

http = HTTP("neo4j:password@localhost:7474", user_agent="httq/0")


def cypher(statement):
    http.post("/db/data/transaction/commit",
              {"statements": [{
                  "statement": statement
              }]})
    if http.response().status_code == 200:
        print(http.content)
    else:
        raise RuntimeError()


def main():
    script, args = sys.argv[0], sys.argv[1:]
    cypher(args[0])


if __name__ == "__main__":
    main()
Ejemplo n.º 12
0
def main():
    http = HTTP(b"httq.io:8080")
    response = http.get(b"/hello").response()
    print(response.content)
Ejemplo n.º 13
0
 def test_can_reconnect(self):
     http = HTTP(b"httq.io:8080")
     assert http.host == b"httq.io:8080"
     http.reconnect()
     assert http.host == b"httq.io:8080"
     http.close()
Ejemplo n.º 14
0
 def test_can_establish_http_connection_without_port(self):
     http = HTTP(b"eu.httpbin.org")
     assert http.host == b"eu.httpbin.org"
     http.close()
Ejemplo n.º 15
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()
Ejemplo n.º 16
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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
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()
Ejemplo n.º 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'
Ejemplo n.º 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": ""}
Ejemplo n.º 21
0
 def test_can_get_chunks(self):
     assert HTTP(b"httq.io:8080").get(b"/chunks").response(
     ).content == "chunk 1\r\nchunk 2\r\nchunk 3\r\n"
Ejemplo n.º 22
0
 def test_can_get_http_1_0_for_one_request(self):
     assert HTTP(b"httq.io:8080").get(
         b"/hello",
         user_agent=b"OldBrowser/1.0").response().content == "hello, world"
Ejemplo n.º 23
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()
Ejemplo n.º 24
0
 def test_can_establish_http_connection_with_port(self):
     http = HTTP(b"httq.io:8080")
     assert http.host == b"httq.io:8080"
     http.close()
Ejemplo n.º 25
0
 def test_request_headers_with_no_request(self):
     http = HTTP(b"httq.io:8080")
     assert http.request_headers == {b"Host": b"httq.io:8080"}
     http.close()
Ejemplo n.º 26
0
 def test_can_reconnect(self):
     http = HTTP(b"httq.io:8080")
     assert http.host == b"httq.io:8080"
     http.reconnect()
     assert http.host == b"httq.io:8080"
     http.close()
Ejemplo n.º 27
0
 def test_request_headers_with_no_request(self):
     http = HTTP(b"httq.io:8080")
     assert http.request_headers == {b"Host": b"httq.io:8080"}
     http.close()
Ejemplo n.º 28
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()
Ejemplo n.º 29
0
 def test_can_use_get_method_short_hand(self):
     assert HTTP(b"httq.io:8080").get(
         b"/hello").response().content == "hello, world"
Ejemplo n.º 30
0
 def test_request_url_with_no_request(self):
     http = HTTP(b"httq.io:8080")
     assert http.request_url is None
     http.close()
Ejemplo n.º 31
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()
Ejemplo n.º 32
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()
Ejemplo n.º 33
0
 def test_request_url_with_no_request(self):
     http = HTTP(b"httq.io:8080")
     assert http.request_url is None
     http.close()
Ejemplo n.º 34
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'
Ejemplo n.º 35
0
 def test_can_put_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.put(b"/json?foo=bar", b"bumblebee").response()
     content = response.content
     assert content == {"method": "PUT", "query": "foo=bar", "content": "bumblebee"}
Ejemplo n.º 36
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()
Ejemplo n.º 37
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()
Ejemplo n.º 38
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": ""}
Ejemplo n.º 39
0
 def test_can_post_json_in_chunks(self):
     http = HTTP(b"httq.io:8080")
     http.post(b"/json?foo=bar")
     http.write(b"bum")
     http.write(b"ble")
     http.write(b"bee")
     http.write(b"")
     response = http.response()
     content = response.content
     assert content == {
         "method": "POST",
         "query": "foo=bar",
         "content": "bumblebee"
     }
Ejemplo n.º 40
0
 def test_can_delete_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.delete(b"/json?foo=bar").response()
     content = response.content
     assert content == {"method": "DELETE", "query": "foo=bar", "content": ""}
Ejemplo n.º 41
0
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import json
import os

from httq import HTTP, log_dump

http = HTTP(b"neo4j:password@localhost:7474",
            user_agent=b"httq/0",
            content_type=b"application/json")

try:
    loops = int(os.getenv("LOOPS", "1"))
except (IndexError, ValueError):
    loops = 1

body = json.dumps({
    "statements": [{
        "statement": "RETURN 1"
    }]
},
                  ensure_ascii=True,
                  separators=",:").encode("UTF-8")


def query():
    if http.request(b"POST", b"/db/data/transaction/commit",
                    body).response().status_code == 200:
        if loops == 1:
            print(http.content)
Ejemplo n.º 42
0
 def test_can_post_dict_as_json(self):
     http = HTTP(b"httq.io:8080")
     response = http.post(b"/json?foo=bar", {"bee": "bumble"}).response()
     content = response.content
     assert content == {"method": "POST", "query": "foo=bar", "content": '{"bee": "bumble"}'}
Ejemplo n.º 43
0
 def test_can_establish_http_connection_with_port(self):
     http = HTTP(b"httq.io:8080")
     assert http.host == b"httq.io:8080"
     http.close()