summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-01-17 13:45:06 +0100
committerAlvaro Neira Ayuso <aneira@soleta.eu>2020-01-19 20:18:14 +0100
commit2c5e477dfb440fb6141c6d5bd0ee45e6a75c5ff0 (patch)
treecd0a014753e12ebca6c77eaf5b07743cbd8cdb0a
parent025e4da5a9180a4ee8b898e070afdc29b017cbaa (diff)
Add /probe tests for multiple probes and extra parameter in json
-rw-r--r--tests/units/test_0001_probe.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/tests/units/test_0001_probe.py b/tests/units/test_0001_probe.py
index fc66dbc..0f08296 100644
--- a/tests/units/test_0001_probe.py
+++ b/tests/units/test_0001_probe.py
@@ -12,15 +12,18 @@ import unittest
class TestProbeMethods(unittest.TestCase):
+ def setUp(self):
+ self.ok_response = 'HTTP/1.0 200 OK\r\nContent-Length:17\r\n' \
+ 'Content-Type:application/json\r\n\r\n' + \
+ '{"status": "OPG"}'
+
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)
+ self.assertEqual(server_response, self.ok_response)
def test_no_json(self):
c = Client()
@@ -46,5 +49,31 @@ class TestProbeMethods(unittest.TestCase):
c.stop()
self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n')
+ def test_multiple_probes(self):
+ c = Client()
+ s = Server()
+ s.connect(probe=False)
+ s.send(s._probe_msg)
+ s.send(s._probe_msg)
+ server_response = s.recv()
+ s.stop()
+ c.stop()
+ self.assertEqual(server_response, self.ok_response)
+
+ def test_extra_parameter_json(self):
+ json = '{"id": 0, "name": "test_local", "center": 0, "room": 0, ' + \
+ '"extra_param": true}'
+ 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.assertRegex(response, '^HTTP/1.0 200 OK\r\n*')
+
if __name__ == '__main__':
unittest.main()