-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_webapi.py
More file actions
71 lines (53 loc) · 2.54 KB
/
test_webapi.py
File metadata and controls
71 lines (53 loc) · 2.54 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
import unittest
from webapi import WebApi
#To run these unit tests from command line:
#python -m unittest test_webapi
#Note that the Update tests actually change the live status. It leaves the status as offline.
class TestWebApi(unittest.TestCase):
#----Query----
def test_WebApi_Query_Success(self):
v = WebApi()
r = v.Query('status')
self.assertTrue(r == 'open' or r == 'closed')
def test_WebApi_Query_Timeout(self):
v = WebApi(timeout=0)
self.assertFalse(v.Query('status'))
def test_WebApi_Query_ConnectionError(self):
#If querying a different server, we shouldn't be using our actual API key!
v = WebApi(dataURL = 'http://doesnotexist.isvhsopen.com/', apiKey = 'BADBADBAD')
self.assertFalse(v.Query('status'))
def test_WebApi_Query_NoJSON(self):
#If querying a different server, we shouldn't be using our actual API key!
v = WebApi(dataURL = 'http://www.google.ca/?q=', apiKey = 'BADBADBAD')
self.assertFalse(v.Query('status'))
def test_WebApi_Query_BadUrl(self):
v = WebApi(dataURL = 'http://isvhsopen.com/')
self.assertFalse(v.Query('status'))
#----Update----
def test_WebApi_Update_Success(self):
#Note that this only checks the response json to ensure it matches
#the update; we don't wait and then query to verify, but just trust it.
v = WebApi()
j = v.Update('open', '12:34')
self.assertTrue(j['status'] == 'open' and j['openUntil'].find('12:34:00') == 11) #TODO: Timezone is different server-side now, so this check fails
j = v.Update('closed')
self.assertTrue(j['status'] == 'closed' and j.get('openUntil') == None)
def test_WebApi_Bad_Key(self):
v = WebApi(apiKey = 'BADBADBAD')
self.assertFalse(v.Update('open', '12:34'))
def test_WebApi_Update_Timeout(self):
v = WebApi(timeout=0)
self.assertFalse(v.Update('open', '12:34'))
def test_WebApi_Update_ConnectionError(self):
#If querying a different server, we shouldn't be using our actual API key!
v = WebApi(dataURL = 'http://doesnotexist.isvhsopen.com/', apiKey = 'BADBADBAD')
self.assertFalse(v.Update('open', '12:34'))
def test_WebApi_Update_NoJSON(self):
#If querying a different server, we shouldn't be using our actual API key!
v = WebApi(dataURL = 'http://www.google.ca/?q=', apiKey = 'BADBADBAD')
self.assertFalse(v.Update('test1', 'v1'))
def test_WebApi_Update_BadUrl(self):
v = WebApi(dataURL = 'http://isvhsopen.com/')
self.assertFalse(v.Update('test1', 'v1'))
if __name__ == '__main__':
unittest.main()