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

Download this file

41 lines (30 with data), 1.3 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
# -----------------------------------------------------------------------------
# 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 tornado.web import HTTPError
from qiita_db.handlers.tests.oauthbase import OauthTestingBase
import qiita_db as qdb
class UtilTests(OauthTestingBase):
def test_get_sample_info(self):
ST = qdb.metadata_template.sample_template.SampleTemplate
exp = ST(1)
obs = qdb.handlers.util._get_instance(ST, 1, 'error')
self.assertEqual(obs, exp)
# It does not exist
with self.assertRaises(HTTPError):
qdb.handlers.util._get_instance(ST, 100, 'error')
def test_get_user_info(self):
US = qdb.user.User
obs = qdb.handlers.util._get_instance(US, 'shared@foo.bar', 'error')
exp = US('shared@foo.bar')
self.assertEqual(obs, exp)
# It does not exist
with self.assertRaises(HTTPError):
qdb.handlers.util._get_instance(US, 'no-exists@foo.bar', 'error')
if __name__ == '__main__':
main()