summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2017-12-13 15:23:32 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2017-12-13 15:23:32 +0300
commitd2bf066b1ceabcb951c0c8be3c21b5ca4a833ed6 (patch)
treecdc7ff5d925eced7f117eb8d6a29a47b1e71043c /test
parentf7c386ece3791ec20412a1010287527f2b4ffc56 (diff)
downloadunit-d2bf066b1ceabcb951c0c8be3c21b5ca4a833ed6.tar.gz
unit-d2bf066b1ceabcb951c0c8be3c21b5ca4a833ed6.tar.bz2
Tests: http() function introduced.
Diffstat (limited to 'test')
-rw-r--r--test/unit.py46
1 files changed, 14 insertions, 32 deletions
diff --git a/test/unit.py b/test/unit.py
index 0857272e..0860d134 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -110,39 +110,32 @@ class TestUnitControl(TestUnit):
# TODO socket reuse
# TODO http client
- def get(self, path='/'):
+ def http(self, req):
with self._control_sock() as sock:
- req = ('GET ' + path
- + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode()
-
sock.sendall(req)
if '--verbose' in sys.argv:
- print('>>>\n', req)
+ print('>>>', req, sep='\n')
resp = self._recvall(sock)
if '--verbose' in sys.argv:
- print('<<<\n', resp)
-
- return self._body_json(resp)
+ print('<<<', resp, sep='\n')
- def delete(self, path='/'):
+ return resp
- with self._control_sock() as sock:
- req = ('DELETE ' + path
- + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode()
+ def get(self, path='/'):
- sock.sendall(req)
+ resp = self.http(('GET ' + path
+ + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
- if '--verbose' in sys.argv:
- print('>>>\n', req)
+ return self._body_json(resp)
- resp = self._recvall(sock)
+ def delete(self, path='/'):
- if '--verbose' in sys.argv:
- print('<<<\n', resp)
+ resp = self.http(('DELETE ' + path
+ + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
return self._body_json(resp)
@@ -151,20 +144,9 @@ class TestUnitControl(TestUnit):
if isinstance(data, str):
data = data.encode()
- with self._control_sock() as sock:
- req = ('PUT ' + path + ' HTTP/1.1\nHost: localhost\n'
- + 'Content-Length: ' + str(len(data))
- + '\r\n\r\n').encode() + data
-
- sock.sendall(req)
-
- if '--verbose' in sys.argv:
- print('>>>\n', req)
-
- resp = self._recvall(sock)
-
- if '--verbose' in sys.argv:
- print('<<<\n', resp)
+ resp = self.http(('PUT ' + path + ' HTTP/1.1\nHost: localhost\n'
+ + 'Content-Length: ' + str(len(data))
+ + '\r\n\r\n').encode() + data)
return self._body_json(resp)