Last change
on this file since 025e4da was
05b1088,
checked in by Alvaro Neira Ayuso <alvaroneay@…>, 5 years ago
|
Include License header
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | # |
---|
2 | # Copyright (C) 2020 Soleta Networks <info@soleta.eu> |
---|
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 |
---|
6 | # Free Software Foundation, version 3. |
---|
7 | # |
---|
8 | |
---|
9 | from server import Server |
---|
10 | from client import Client |
---|
11 | import unittest |
---|
12 | |
---|
13 | class TestProbeMethods(unittest.TestCase): |
---|
14 | |
---|
15 | def test_post(self): |
---|
16 | msg = 'HTTP/1.0 200 OK\r\nContent-Length:17\r\n' \ |
---|
17 | 'Content-Type:application/json\r\n\r\n{"status": "OPG"}' |
---|
18 | c = Client() |
---|
19 | s = Server() |
---|
20 | server_response = s.connect() |
---|
21 | s.stop() |
---|
22 | c.stop() |
---|
23 | self.assertEqual(server_response, msg) |
---|
24 | |
---|
25 | def test_no_json(self): |
---|
26 | c = Client() |
---|
27 | s = Server() |
---|
28 | s.connect(probe=False) |
---|
29 | s.send('POST /probe HTTP/1.0\r\nContent-Length:0\r\n\r\n') |
---|
30 | response = s.recv() |
---|
31 | s.stop() |
---|
32 | c.stop() |
---|
33 | self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n') |
---|
34 | |
---|
35 | def test_malformed_json(self): |
---|
36 | json = '{"id": 0, "name": "test_local", "center": 0}' |
---|
37 | len_json = str(len(json)) |
---|
38 | msg = 'POST /probe HTTP/1.0\r\nContent-Length:' + len_json + \ |
---|
39 | '\r\nContent-Type:application/json\r\n\r\n' + json |
---|
40 | c = Client() |
---|
41 | s = Server() |
---|
42 | s.connect(probe=False) |
---|
43 | s.send(msg) |
---|
44 | response = s.recv() |
---|
45 | s.stop() |
---|
46 | c.stop() |
---|
47 | self.assertEqual(response, 'HTTP/1.0 400 Bad Request\r\n\r\n') |
---|
48 | |
---|
49 | if __name__ == '__main__': |
---|
50 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.