From 9f48f2b3e78d268c39dbd772a0a0f9ef07530846 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Tue, 30 Jan 2018 16:16:52 +0300 Subject: Tests: added methods to manage unit configuration. --- test/unit.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'test/unit.py') diff --git a/test/unit.py b/test/unit.py index 38c001ba..c17038eb 100644 --- a/test/unit.py +++ b/test/unit.py @@ -149,6 +149,18 @@ class TestUnitControl(TestUnit): # TODO socket reuse # TODO http client + def conf(self, conf, path='/'): + if isinstance(conf, dict): + conf = json.dumps(conf) + + return self._body_json(self.put(path, conf)) + + def conf_get(self, path='/'): + return self._body_json(self.get(path)) + + def conf_delete(self, path='/'): + return self._body_json(self.delete(path)) + def http(self, req): with self._control_sock() as sock: sock.sendall(req) @@ -167,13 +179,13 @@ class TestUnitControl(TestUnit): resp = self.http(('GET ' + path + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode()) - return self._body_json(resp) + return resp def delete(self, path='/'): resp = self.http(('DELETE ' + path + ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode()) - return self._body_json(resp) + return resp def put(self, path='/', data=''): if isinstance(data, str): @@ -183,7 +195,7 @@ class TestUnitControl(TestUnit): + 'Content-Length: ' + str(len(data)) + '\r\n\r\n').encode() + data) - return self._body_json(resp) + return resp def _control_sock(self): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -- cgit