Repository navigation
Expand file tree
/
Copy pathtests.py
More file actions
93 lines (79 loc) · 3.88 KB
/
Copy pathtests.py
File metadata and controls
93 lines (79 loc) · 3.88 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import unittest, requests
class TestStringMethods(unittest.TestCase):
ip = 'localhost'
port = '8080'
def test_keepalive_method(self):
r = requests.get('http://{}:{}/scripts/update.php'.format(self.ip, self.port), timeout=1)
# test the response status
self.assertTrue(r.status_code == 200,
"The status code {} was not expected".format(
r.status_code
)
)
# test the response contains the expected values
self.assertTrue('status=0' in r.text,
"The response should contains the param 'status'"
)
self.assertTrue('ka_time=' in r.text,
"The response should contains the param 'ka_time'"
)
self.assertTrue('allow=' in r.text,
"The response should contains the param 'allow'"
)
# test the response contains the expected headers
self.assertTrue('Content-Type' in r.headers,
"The response should contains the 'Content-Type' header."
)
self.assertTrue(
r.headers['Content-Type'].lower() == 'text/plain; charset=utf-8',
"The header[Content-Type] = {} is not the expected".format(
r.headers['Content-Type']
)
)
def test_notification_method(self):
index_code = '1234'
payload = """<?xml version='1.0'?>
<notify>
<pmax_account>001234</pmax_account>
<index>{}</index>
<serial>052eeb</serial>
<time>1459463087</time>
<priority>2</priority>
<event id='81' type='Arm. Parcial'/>
<profile id='3' type='Open / Close'/>
<device id='3' type='Usuario'/>
<location id='1' type='admin'/>
<zone id='1'/>
<partition>1</partition>
<forward_automation>true</forward_automation>
<userlist>
<user name='admin' email='ownermailbox@hotmail.com' phone='555
666 777' is_sms='0' is_mms='0' is_email='1'/>
<user name='carmen' email='wifemailbox@gmail.com' phone='555 777
888' is_sms='0' is_mms='0' is_email='1'/>
<user name='juan' email='neigbourgmailbox@yahoo.com' phone='555
555 555' is_sms='0' is_mms='0' is_email='1'/>
</userlist>
</notify>""".format(index_code)
r = requests.post('http://{}:{}/scripts/notify.php'.format(self.ip, self.port), data=payload, timeout=1)
# test the response status
self.assertTrue(r.status_code == 200,
"The 200 status code was expected instead {}".format(r.status_code)
)
# test that the response does not contains php errors
self.assertTrue('this will throw an Error in a future version of PHP' not in r.text,
'We expect no PHP warnings at the response'
)
# test the response contains the expected values
self.assertTrue('<index>{}</index>'.format(index_code) in r.text,
"The same index value sent at request was expected at the response"
)
# test the headers received are correct
# print(r.headers)
self.assertTrue(r.headers['Content-Type'].lower() == 'text/xml;charset=utf-8',
"The 'Content-Type' header = {} was not the expected".format(r.headers['Content-Type'])
)
if __name__ == '__main__':
# unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
unittest.TextTestRunner(verbosity=2).run(suite)