diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-01-17 13:47:35 +0100 |
---|---|---|
committer | Alvaro Neira Ayuso <aneira@soleta.eu> | 2020-01-19 20:18:14 +0100 |
commit | 65a5c95cc20e7dab755f74c34aa04f254d8cb705 (patch) | |
tree | 40a5d26f26e7759bc17abf5b0e948f928aa29d42 /tests/units | |
parent | 2c5e477dfb440fb6141c6d5bd0ee45e6a75c5ff0 (diff) |
Add test for sequential /shell/run requests
This also fixes test bugs in the cases:
- Malformed json
- No json
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/test_0003_shellrun.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/units/test_0003_shellrun.py b/tests/units/test_0003_shellrun.py index cd0a8e1..ada1795 100644 --- a/tests/units/test_0003_shellrun.py +++ b/tests/units/test_0003_shellrun.py @@ -48,7 +48,7 @@ class TestShellRunMethods(unittest.TestCase): def test_no_json(self): c = Client() s = Server() - s.connect(probe=False) + s.connect() s.send('POST /shell/run HTTP/1.0\r\nContent-Length:0\r\n\r\n') response = s.recv() s.stop() @@ -62,12 +62,35 @@ class TestShellRunMethods(unittest.TestCase): '\r\nContent-Type:application/json\r\n\r\n' + json c = Client() s = Server() - s.connect(probe=False) + s.connect() s.send(msg) response = s.recv() s.stop() c.stop() self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n') + def test_serial_requests(self): + req1_json = '{"run":"echo 1", "echo":true}' + req1 = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \ + str(len(req1_json)) + \ + '\r\nContent-Type:application/json\r\n\r\n' + req1_json + req2_json = '{"run":"echo 2", "echo":true}' + req2 = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \ + str(len(req2_json)) + \ + '\r\nContent-Type:application/json\r\n\r\n' + req2_json + response_json = '{"out": "2\n"}' + resp = 'HTTP/1.0 200 OK\r\nContent-Length:' + \ + str(len(response_json)) + \ + '\r\nContent-Type:application/json\r\n\r\n' + response_json + c = Client() + s = Server() + s.connect() + s.send(req1) + s.send(req2) + client_response = s.recv() + s.stop() + c.stop() + self.assertEqual(client_response, client_response) + if __name__ == '__main__': unittest.main() |