-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
43 lines (33 loc) · 1.66 KB
/
tests.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
from unittest import TestCase, main as unittest_main
from webtest import TestApp
from namespace_utils import test_funs as test
from namespace_user_api import oauth2_app as oauth2_bottle_app, user_api
class TestUserApi(TestCase):
app = TestApp(user_api)
oauth2_app = TestApp(oauth2_bottle_app)
users = ({'email': '[email protected]', 'password': 'bar'},
{'email': '[email protected]', 'password': 'haz'},
{'email': '[email protected]', 'password': 'can'})
access_token = ''
@classmethod
def setUpClass(cls):
register_or_login_resp = cls.oauth2_app.put('/api/oauth2/register_or_login', cls.users[0])
test.assertEqual(register_or_login_resp.content_type, 'application/json')
test.assertEqual(register_or_login_resp.status_code, 200)
test.assertIn('access_token', register_or_login_resp.json)
test.assertIn('expires_in', register_or_login_resp.json)
cls.access_token = register_or_login_resp.json['access_token']
def test_get_profile_failure(self):
k = 'access_token'
self.assertNotEqual(self.app.get('/api/v1/user', {k: getattr(TestUserApi, k)}).json,
{'user': self.users[1]['email']})
def test_get_profile_success(self):
k = 'access_token'
self.assertEqual(self.app.get('/api/v1/user', {k: getattr(TestUserApi, k)}).json,
{'user': self.users[0]['email']})
@classmethod
def tearDownClass(cls):
unregister_resp = cls.oauth2_app.delete('/api/oauth2/unregister', params=cls.users[0])
test.assertEqual(got=unregister_resp.content_type, expect=None)
if __name__ == '__main__':
unittest_main()