-
Notifications
You must be signed in to change notification settings - Fork 2
/
service_test.py
42 lines (35 loc) · 1.29 KB
/
service_test.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
import endpoints
from google.appengine.ext import testbed
import webtest
import unittest
from service import SuggestionAPI
from jwt import JWT
class ServiceTestCase(unittest.TestCase):
def setUp(self):
tb = testbed.Testbed()
tb.setup_env(current_version_id='testbed.version')
tb.activate()
tb.init_all_stubs()
self.testbed = tb
def tearDown(self):
self.testbed.deactivate()
def test_endpoint_insert(self):
app = endpoints.api_server([SuggestionAPI], restricted=False)
testapp = webtest.TestApp(app)
token = JWT.create_token('user@example.com', "insert")
testapp.authorization = ('Bearer', token)
msg = {'title': 'Hello'}
resp = testapp.post_json('/_ah/api/suggestion/v1/suggestion', msg)
self.assertEqual(resp.json, {'title': 'Hello'})
def test_endpoint_no_authorization(self):
app = endpoints.api_server([SuggestionAPI], restricted=False)
testapp = webtest.TestApp(app)
token = JWT.create_token('user@example.com', "nope")
testapp.authorization = ('Bearer', token)
msg = {'title': 'Hello'}
try:
testapp.post_json('/_ah/api/suggestion/v1/suggestion', msg)
except:
pass
if __name__ == '__main__':
unittest.main()