-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_alpfs.py
123 lines (66 loc) · 2.49 KB
/
test_alpfs.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
"""alpine python baised flask server for testing
To setup a test virtual environment
$ python3 -m venv test-venv
$ source test-venv/bin/activate
$ pip install -r requirements.txt
To run
(test-venv) [lrm@lrmz-iMac-2017 ALPFS (main)]$ python3 test_alpfs.py
.
----------------------------------------------------------------------
Ran 1 test in 0.019s
OK
"""
import logging
import unittest
import alpfs
class AlpfsTests(unittest.TestCase):
def setUp(self):
"""Set up test servers"""
self.alpfs = alpfs.factory()
self.client = self.alpfs.test_client()
self.alpfs.testing = True
return
def test_home_page(self):
"""Test home page"""
a_response = self.client.get('/')
self.assertEqual('200 OK', a_response.status)
return
def test_starbug_link(self):
"""Test home page has starbug.com link"""
a_response = self.client.get('/')
self.assertIn(b'by <a href="https://www.starbug.com">starbug.com', a_response.data)
return
def test_get_whoami(self):
"""Test GET whoami API"""
a_response = self.client.get('/api/v0/whoami', query_string={'foo':'bar', 'baz':42})
self.assertEqual(200, a_response.status_code)
self.assertIn('timestamp', a_response.json)
self.assertIn('args', a_response.json)
self.assertEqual('bar', a_response.json['args']['foo'])
self.assertEqual(str(42), a_response.json['args']['baz']) # TODO as int?
return
def test_post_whoami(self):
"""Test POST whoami API fails"""
a_response = self.client.post('/api/v0/whoami')
self.assertEqual(405, a_response.status_code)
return
def test_get_whoareyou(self):
"""Test GET whoareyou API fails"""
a_response = self.client.get('/api/v0/whoareyou')
self.assertEqual(405, a_response.status_code)
return
def test_post_whoareyou(self):
"""Test POST whoareyou API"""
a_response = self.client.post('/api/v0/whoareyou', json={'foo':'bar', 'baz':42})
self.assertEqual(200, a_response.status_code)
self.assertIn('timestamp', a_response.json)
self.assertIn('args', a_response.json)
self.assertEqual('bar', a_response.json['args']['foo'])
self.assertEqual(42, a_response.json['args']['baz']) # TODO is int!
return
# ================
# ===== main =====
# ================
if __name__ == '__main__':
unittest.main()