source: ogClient-Git/tests/units/test_0001_probe.py

Last change on this file was cb9edc8, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

ogClient is AGPLv3+

Update license header in files.

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[05b1088]1#
[cb9edc8]2# Copyright (C) 2020-2021 Soleta Networks <info@soleta.eu>
[05b1088]3#
4# This program is free software: you can redistribute it and/or modify it under
5# the terms of the GNU Affero General Public License as published by the
[cb9edc8]6# Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
[05b1088]8
[23cc1e6]9from server import Server
10from client import Client
11import unittest
12
13class TestProbeMethods(unittest.TestCase):
14
[2c5e477]15    def setUp(self):
[f86999d]16        self.ok_response = 'HTTP/1.0 200 OK\r\nContent-Length: 17\r\n' \
17                           'Content-Type: application/json\r\n\r\n' + \
[2c5e477]18                           '{"status": "OPG"}'
19
[23cc1e6]20    def test_post(self):
21        c = Client()
22        s = Server()
23        server_response = s.connect()
24        s.stop()
25        c.stop()
[2c5e477]26        self.assertEqual(server_response, self.ok_response)
[23cc1e6]27
28    def test_no_json(self):
29        c = Client()
30        s = Server()
31        s.connect(probe=False)
[f86999d]32        s.send('POST /probe HTTP/1.0\r\nContent-Length: 0\r\n\r\n')
[23cc1e6]33        response = s.recv()
34        s.stop()
35        c.stop()
36        self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n')
37
38    def test_malformed_json(self):
39        json = '{"id": 0, "name": "test_local", "center": 0}'
40        len_json = str(len(json))
[f86999d]41        msg = 'POST /probe HTTP/1.0\r\nContent-Length: ' + len_json + \
42              '\r\nContent-Type: application/json\r\n\r\n' + json
[23cc1e6]43        c = Client()
44        s = Server()
45        s.connect(probe=False)
46        s.send(msg)
47        response = s.recv()
48        s.stop()
49        c.stop()
50        self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n')
51
[2c5e477]52    def test_multiple_probes(self):
53        c = Client()
54        s = Server()
55        s.connect(probe=False)
56        s.send(s._probe_msg)
57        s.send(s._probe_msg)
58        server_response = s.recv()
59        s.stop()
60        c.stop()
61        self.assertEqual(server_response, self.ok_response)
62
63    def test_extra_parameter_json(self):
64        json = '{"id": 0, "name": "test_local", "center": 0, "room": 0, ' + \
65               '"extra_param": true}'
66        len_json = str(len(json))
[f86999d]67        msg = 'POST /probe HTTP/1.0\r\nContent-Length: ' + len_json + \
68              '\r\nContent-Type: application/json\r\n\r\n' + json
[2c5e477]69        c = Client()
70        s = Server()
71        s.connect(probe=False)
72        s.send(msg)
73        response = s.recv()
74        s.stop()
75        c.stop()
76        self.assertRegex(response, '^HTTP/1.0 200 OK\r\n*')
77
[23cc1e6]78if __name__ == '__main__':
79    unittest.main()
Note: See TracBrowser for help on using the repository browser.