Tests: response handling improved.
This commit is contained in:
@@ -167,7 +167,7 @@ Connection: close
|
|||||||
def test_access_log_partial(self):
|
def test_access_log_partial(self):
|
||||||
self.load('empty')
|
self.load('empty')
|
||||||
|
|
||||||
self.http(b"""GE""", raw_resp=True, raw=True)
|
self.http(b"""GE""", raw=True)
|
||||||
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ Connection: close
|
|||||||
def test_access_log_partial_2(self):
|
def test_access_log_partial_2(self):
|
||||||
self.load('empty')
|
self.load('empty')
|
||||||
|
|
||||||
self.http(b"""GET /\n""", raw_resp=True, raw=True)
|
self.http(b"""GET /\n""", raw=True)
|
||||||
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ Connection: close
|
|||||||
def test_access_log_partial_3(self):
|
def test_access_log_partial_3(self):
|
||||||
self.load('empty')
|
self.load('empty')
|
||||||
|
|
||||||
self.http(b"""GET / HTTP/1.1""", raw_resp=True, raw=True)
|
self.http(b"""GET / HTTP/1.1""", raw=True)
|
||||||
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ Connection: close
|
|||||||
def test_access_log_partial_4(self):
|
def test_access_log_partial_4(self):
|
||||||
self.load('empty')
|
self.load('empty')
|
||||||
|
|
||||||
resp = self.http(b"""GET / HTTP/1.1\n""", raw_resp=True, raw=True)
|
resp = self.http(b"""GET / HTTP/1.1\n""", raw=True)
|
||||||
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ Connection: close
|
|||||||
def test_access_log_partial_5(self):
|
def test_access_log_partial_5(self):
|
||||||
self.load('empty')
|
self.load('empty')
|
||||||
|
|
||||||
self.http(b"""GET / HTTP/1.1\n\n""", raw_resp=True, raw=True)
|
self.http(b"""GET / HTTP/1.1\n\n""", raw=True)
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
|
|||||||
def test_python_application_not_iterable(self):
|
def test_python_application_not_iterable(self):
|
||||||
self.load('not_iterable')
|
self.load('not_iterable')
|
||||||
|
|
||||||
self.get(raw_resp=True)
|
self.get()
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|||||||
12
test/unit.py
12
test/unit.py
@@ -259,17 +259,21 @@ class TestUnitHTTP(TestUnit):
|
|||||||
return self.http('PUT', **kwargs)
|
return self.http('PUT', **kwargs)
|
||||||
|
|
||||||
def _recvall(self, sock, buff_size=4096):
|
def _recvall(self, sock, buff_size=4096):
|
||||||
data = ''
|
data = b''
|
||||||
while select.select([sock], [], [], 1)[0]:
|
while select.select([sock], [], [], 1)[0]:
|
||||||
part = sock.recv(buff_size).decode()
|
part = sock.recv(buff_size)
|
||||||
data += part
|
data += part
|
||||||
if part is '':
|
if not len(part):
|
||||||
break
|
break
|
||||||
|
|
||||||
return data
|
return data.decode()
|
||||||
|
|
||||||
def _resp_to_dict(self, resp):
|
def _resp_to_dict(self, resp):
|
||||||
m = re.search('(.*?\x0d\x0a?)\x0d\x0a?(.*)', resp, re.M | re.S)
|
m = re.search('(.*?\x0d\x0a?)\x0d\x0a?(.*)', resp, re.M | re.S)
|
||||||
|
|
||||||
|
if not m:
|
||||||
|
return {}
|
||||||
|
|
||||||
headers_text, body = m.group(1), m.group(2)
|
headers_text, body = m.group(1), m.group(2)
|
||||||
|
|
||||||
p = re.compile('(.*?)\x0d\x0a?', re.M | re.S)
|
p = re.compile('(.*?)\x0d\x0a?', re.M | re.S)
|
||||||
|
|||||||
Reference in New Issue
Block a user