diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-01-16 11:37:47 +0100 |
---|---|---|
committer | Alvaro Neira Ayuso <alvaroneay@gmail.com> | 2020-01-19 19:50:44 +0100 |
commit | 23cc1e6b86f72ea395e8c156e4e8bda05c4a8329 (patch) | |
tree | 8373f4bac972f604dccc72caa8378643fff96625 /tests/units | |
parent | bb65bd7bf03da7ad5a9ae25d6caab57d06211b99 (diff) |
Add /probe tests
These tests cover:
- Correct request
- No json request
- Malformed json request
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/test_0001_probe.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/units/test_0001_probe.py b/tests/units/test_0001_probe.py new file mode 100644 index 0000000..dc0cc17 --- /dev/null +++ b/tests/units/test_0001_probe.py @@ -0,0 +1,42 @@ +from server import Server +from client import Client +import unittest + +class TestProbeMethods(unittest.TestCase): + + def test_post(self): + msg = 'HTTP/1.0 200 OK\r\nContent-Length:17\r\n' \ + 'Content-Type:application/json\r\n\r\n{"status": "OPG"}' + c = Client() + s = Server() + server_response = s.connect() + s.stop() + c.stop() + self.assertEqual(server_response, msg) + + def test_no_json(self): + c = Client() + s = Server() + s.connect(probe=False) + s.send('POST /probe HTTP/1.0\r\nContent-Length:0\r\n\r\n') + response = s.recv() + s.stop() + c.stop() + self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n') + + def test_malformed_json(self): + json = '{"id": 0, "name": "test_local", "center": 0}' + len_json = str(len(json)) + msg = 'POST /probe HTTP/1.0\r\nContent-Length:' + len_json + \ + '\r\nContent-Type:application/json\r\n\r\n' + json + c = Client() + s = Server() + s.connect(probe=False) + s.send(msg) + response = s.recv() + s.stop() + c.stop() + self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n') + +if __name__ == '__main__': + unittest.main() |