mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Tests for a basic GET and HTTP pipelining
This commit is contained in:
parent
eee18f4d76
commit
8045fec313
@ -61,3 +61,7 @@ class TestServer(Thread):
|
|||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
return httplib.HTTPConnection(self.address[0], self.address[1], strict=True, timeout=0.1)
|
return httplib.HTTPConnection(self.address[0], self.address[1], strict=True, timeout=0.1)
|
||||||
|
|
||||||
|
def change_handler(self, handler):
|
||||||
|
from calibre.srv.http import create_http_handler
|
||||||
|
self.loop.http_handler = create_http_handler(handler)
|
||||||
|
@ -65,6 +65,7 @@ class TestHTTP(BaseTest):
|
|||||||
def handler(conn):
|
def handler(conn):
|
||||||
raise HTTP404(body)
|
raise HTTP404(body)
|
||||||
with TestServer(handler) as server:
|
with TestServer(handler) as server:
|
||||||
|
# Test 404
|
||||||
conn = server.connect()
|
conn = server.connect()
|
||||||
conn.request('HEAD', '/moose')
|
conn.request('HEAD', '/moose')
|
||||||
r = conn.getresponse()
|
r = conn.getresponse()
|
||||||
@ -78,4 +79,22 @@ class TestHTTP(BaseTest):
|
|||||||
r = conn.getresponse()
|
r = conn.getresponse()
|
||||||
self.ae(r.status, httplib.NOT_FOUND)
|
self.ae(r.status, httplib.NOT_FOUND)
|
||||||
self.ae(r.read(), 'Requested resource not found')
|
self.ae(r.read(), 'Requested resource not found')
|
||||||
|
|
||||||
|
server.change_handler(lambda conn:conn.path[1])
|
||||||
|
# Test simple GET
|
||||||
|
conn.request('GET', '/test')
|
||||||
|
self.ae(conn.getresponse().read(), 'test')
|
||||||
|
|
||||||
|
# Test pipelining
|
||||||
|
responses = []
|
||||||
|
for i in xrange(10):
|
||||||
|
conn._HTTPConnection__state = httplib._CS_IDLE
|
||||||
|
conn.request('GET', '/%d'%i)
|
||||||
|
responses.append(conn.response_class(conn.sock, strict=conn.strict, method=conn._method))
|
||||||
|
for i in xrange(10):
|
||||||
|
r = responses[i]
|
||||||
|
r.begin()
|
||||||
|
self.ae(r.read(), ('%d' % i).encode('ascii'))
|
||||||
|
conn._HTTPConnection__state = httplib._CS_IDLE
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user