-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unittest.py
75 lines (58 loc) · 2.13 KB
/
test_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
import http.client
class Test_TestAPI(unittest.TestCase):
@classmethod
def setUpClass(self):
self.conn = http.client.HTTPConnection("localhost:3000")
def test_connexion(self):
self.conn.request("GET", "/")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_control(self):
self.conn.request("GET", "/control")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_setWrongPin(self):
self.conn.request("GET", "/set/14/0")
res = self.conn.getresponse()
self.assertEqual(res.status, 404)
def test_setWrongState(self):
self.conn.request("GET", "/set/11/2")
res = self.conn.getresponse()
self.assertEqual(res.status, 400)
def test_set(self):
self.conn.request("GET", "/set/11/1")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
self.conn.request("GET", "/set/11/0")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_pins(self):
self.conn.request("GET", "/pins")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_getAll(self):
self.conn.request("GET", "/get")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_getWrongPin(self):
self.conn.request("GET", "/get/14")
res = self.conn.getresponse()
self.assertEqual(res.status, 404)
def test_getPin(self):
self.conn.request("GET", "/get/11")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
def test_switchWrongPin(self):
self.conn.request("GET", "/switch/14")
res = self.conn.getresponse()
self.assertEqual(res.status, 404)
def test_switch(self):
self.conn.request("GET", "/switch/11")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
self.conn.request("GET", "/switch/11")
res = self.conn.getresponse()
self.assertEqual(res.status, 200)
if __name__ == '__main__':
unittest.main()