source: ogClient-Git/tests/units/test_0001_probe.py @ 23cc1e6

Last change on this file since 23cc1e6 was 23cc1e6, checked in by Alvaro Neira Ayuso <alvaroneay@…>, 5 years ago

Add /probe tests

These tests cover:

  • Correct request
  • No json request
  • Malformed json request
  • Property mode set to 100644
File size: 1.2 KB
Line 
1from server import Server
2from client import Client
3import unittest
4
5class TestProbeMethods(unittest.TestCase):
6
7    def test_post(self):
8        msg = 'HTTP/1.0 200 OK\r\nContent-Length:17\r\n' \
9              'Content-Type:application/json\r\n\r\n{"status": "OPG"}'
10        c = Client()
11        s = Server()
12        server_response = s.connect()
13        s.stop()
14        c.stop()
15        self.assertEqual(server_response, msg)
16
17    def test_no_json(self):
18        c = Client()
19        s = Server()
20        s.connect(probe=False)
21        s.send('POST /probe HTTP/1.0\r\nContent-Length:0\r\n\r\n')
22        response = s.recv()
23        s.stop()
24        c.stop()
25        self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n')
26
27    def test_malformed_json(self):
28        json = '{"id": 0, "name": "test_local", "center": 0}'
29        len_json = str(len(json))
30        msg = 'POST /probe HTTP/1.0\r\nContent-Length:' + len_json + \
31              '\r\nContent-Type:application/json\r\n\r\n' + json
32        c = Client()
33        s = Server()
34        s.connect(probe=False)
35        s.send(msg)
36        response = s.recv()
37        s.stop()
38        c.stop()
39        self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n')
40
41if __name__ == '__main__':
42    unittest.main()
Note: See TracBrowser for help on using the repository browser.