-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_vhsapi.py
More file actions
57 lines (41 loc) · 1.63 KB
/
test_vhsapi.py
File metadata and controls
57 lines (41 loc) · 1.63 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
import unittest
from vhsapi import VHSApi
#To run these unit tests from command line:
#python -m unittest test_vhsapi
class TestVHSApi(unittest.TestCase):
#----Query----
def test_VHSApi_Query_Success(self):
v = VHSApi()
r = v.Query('door')
self.assertTrue(r == 'open' or r == 'closed')
def test_VHSApi_Query_Timeout(self):
v = VHSApi(timeout=0)
self.assertFalse(v.Query('door'))
def test_VHSApi_Query_ConnectionError(self):
v = VHSApi(dataURL = 'http://doesnotexist.vanhack.ca/')
self.assertFalse(v.Query('door'))
def test_VHSApi_Query_NoJSON(self):
v = VHSApi(dataURL = 'http://www.google.ca/?q=')
self.assertFalse(v.Query('door'))
def test_VHSApi_Query_BadUrl(self):
v = VHSApi(dataURL = 'http://api.vanhack.ca/')
self.assertFalse(v.Query('door'))
#----Update----
def test_VHSApi_Update_Success(self):
v = VHSApi()
self.assertTrue('v1' == v.Update('test1', 'v1') == v.Query('test1'))
self.assertTrue('v2' == v.Update('test1', 'v2') == v.Query('test1'))
def test_VHSApi_Update_Timeout(self):
v = VHSApi(timeout=0)
self.assertFalse(v.Update('test1', 'v1'))
def test_VHSApi_Update_ConnectionError(self):
v = VHSApi(dataURL = 'http://doesnotexist.vanhack.ca/')
self.assertFalse(v.Update('test1', 'v1'))
def test_VHSApi_Update_NoJSON(self):
v = VHSApi(dataURL = 'http://www.google.ca/?q=')
self.assertFalse(v.Update('test1', 'v1'))
def test_VHSApi_Update_BadUrl(self):
v = VHSApi(dataURL = 'http://api.vanhack.ca/')
self.assertFalse(v.Update('test1', 'v1'))
if __name__ == '__main__':
unittest.main()