[879b32]: / qiita_db / handlers / tests / test_user.py

Download this file

67 lines (52 with data), 2.4 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
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from unittest import main
from json import loads
from qiita_db.handlers.tests.oauthbase import OauthTestingBase
class UserInfoDBHandlerTests(OauthTestingBase):
def test_get_does_not_exist(self):
obs = self.get('/qiita_db/user/no-exists@foo.bar/data/',
headers=self.header)
self.assertEqual(obs.code, 404)
def test_get_no_header(self):
obs = self.get('/qiita_db/user/no-exists@foo.bar/data/')
self.assertEqual(obs.code, 400)
def test_get(self):
obs = self.get('/qiita_db/user/shared@foo.bar/data/',
headers=self.header)
self.assertEqual(obs.code, 200)
obs = loads(obs.body)
self.assertCountEqual(obs.keys(), ['data'])
# for simplicity we will only test that the keys are the same
# and that one of the key's info is correct
obs = obs['data']
exp = {"password": "$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJk"
"UM8nXG9Efe", "email": "shared@foo.bar", "level": "user",
"name": "Shared"}
self.assertEqual(obs, exp)
class UsersListDBHandlerTests(OauthTestingBase):
def test_get_no_header(self):
obs = self.get('/qiita_db/users/')
self.assertEqual(obs.code, 400)
def test_get(self):
obs = self.get('/qiita_db/users/',
headers=self.header)
self.assertEqual(obs.code, 200)
obs = loads(obs.body)
exp = {'data': [
{'email': 'shared@foo.bar', 'name': 'Shared'},
{'email': 'admin@foo.bar', 'name': 'Admin'},
{'email': 'demo@microbio.me', 'name': 'Demo'},
{'email': 'test@foo.bar', 'name': 'Dude'},
{'email': 'justnow@nonvalidat.ed', 'name': 'JustNow'},
{'email': 'ayearago@nonvalidat.ed', 'name': 'Oldie'},
{'email': '3Xdays@nonvalidat.ed', 'name': 'TooLate'}
]}
self.assertEqual(obs, exp)
if __name__ == '__main__':
main()