[879b32]: / qiita_db / test / test_base.py

Download this file

87 lines (67 with data), 3.1 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -----------------------------------------------------------------------------
# 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 TestCase, main
from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_core.util import qiita_test_checker
from qiita_core.qiita_settings import qiita_config
import qiita_db as qdb
@qiita_test_checker()
class QiitaBaseTest(TestCase):
"""Tests that the base class functions act correctly"""
def setUp(self):
# We need an actual subclass in order to test the equality functions
self.tester = qdb.artifact.Artifact(1)
self.portal = qiita_config.portal
def tearDown(self):
qiita_config.portal = self.portal
def test_init_base_error(self):
"""Raises an error when instantiating a base class directly"""
with self.assertRaises(IncompetentQiitaDeveloperError):
qdb.base.QiitaObject(1)
def test_init_error_inexistent(self):
"""Raises an error when instantiating an object that does not exists"""
with self.assertRaises(qdb.exceptions.QiitaDBUnknownIDError):
qdb.artifact.Artifact(10)
def test_check_subclass(self):
"""Nothing happens if check_subclass called from a subclass"""
self.tester._check_subclass()
def test_check_subclass_error(self):
"""check_subclass raises an error if called from a base class"""
# Checked through the __init__ call
with self.assertRaises(IncompetentQiitaDeveloperError):
qdb.base.QiitaObject(1)
def test_check_id(self):
"""Correctly checks if an id exists on the database"""
self.assertTrue(self.tester._check_id(1))
self.assertFalse(self.tester._check_id(100))
def test_check_portal(self):
"""Correctly checks if object is accessable in portal given"""
qiita_config.portal = 'QIITA'
tester = qdb.analysis.Analysis(1)
self.assertTrue(tester._check_portal(1))
qiita_config.portal = 'EMP'
self.assertFalse(tester._check_portal(1))
self.assertTrue(self.tester._check_portal(1))
def test_equal_self(self):
"""Equality works with the same object"""
self.assertEqual(self.tester, self.tester)
def test_equal(self):
"""Equality works with two objects pointing to the same instance"""
new = qdb.artifact.Artifact(1)
self.assertEqual(self.tester, new)
def test_not_equal(self):
"""Not equals works with object of the same type"""
sp1 = qdb.study.StudyPerson(1)
sp2 = qdb.study.StudyPerson(2)
self.assertNotEqual(sp1, sp2)
def test_not_equal_type(self):
"""Not equals works with object of different type"""
new = qdb.study.Study(1)
self.assertNotEqual(self.tester, new)
if __name__ == '__main__':
main()