2009-12-09 10:09:53 -06:00
|
|
|
# Authors:
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2009-12-09 10:09:53 -06:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output` module.
|
|
|
|
"""
|
|
|
|
|
2013-05-21 06:40:27 -05:00
|
|
|
from ipatests.util import raises, ClassChecker
|
2009-12-09 10:09:53 -06:00
|
|
|
from ipalib import output
|
|
|
|
from ipalib.frontend import Command
|
2014-03-27 08:04:00 -05:00
|
|
|
from ipapython.version import API_VERSION
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2015-04-24 07:39:48 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.tier0
|
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
class test_Output(ClassChecker):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output.Output` class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = output.Output
|
|
|
|
|
|
|
|
def test_init(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output.Output.__init__` method.
|
|
|
|
"""
|
|
|
|
o = self.cls('result')
|
|
|
|
assert o.name == 'result'
|
|
|
|
assert o.type is None
|
|
|
|
assert o.doc is None
|
|
|
|
|
|
|
|
def test_repr(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output.Output.__repr__` method.
|
|
|
|
"""
|
|
|
|
o = self.cls('aye')
|
2016-08-15 07:24:11 -05:00
|
|
|
assert repr(o) == "Output('aye')"
|
2009-12-09 10:09:53 -06:00
|
|
|
o = self.cls('aye', type=int, doc='An A, aye?')
|
2018-02-14 09:59:50 -06:00
|
|
|
assert repr(o) == (
|
|
|
|
"Output('aye', type=[<type 'int'>], doc='An A, aye?')"
|
|
|
|
)
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
class Entry(self.cls):
|
|
|
|
pass
|
|
|
|
o = Entry('aye')
|
2016-08-15 07:24:11 -05:00
|
|
|
assert repr(o) == "Entry('aye')"
|
2009-12-09 10:09:53 -06:00
|
|
|
o = Entry('aye', type=int, doc='An A, aye?')
|
2018-02-14 09:59:50 -06:00
|
|
|
assert repr(o) == (
|
|
|
|
"Entry('aye', type=[<type 'int'>], doc='An A, aye?')"
|
|
|
|
)
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
|
|
|
|
class test_ListOfEntries(ClassChecker):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output.ListOfEntries` class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
_cls = output.ListOfEntries
|
|
|
|
|
|
|
|
def test_validate(self):
|
|
|
|
"""
|
|
|
|
Test the `ipalib.output.ListOfEntries.validate` method.
|
|
|
|
"""
|
2015-06-22 05:58:43 -05:00
|
|
|
api = 'the api instance'
|
2009-12-09 10:09:53 -06:00
|
|
|
class example(Command):
|
|
|
|
pass
|
2015-06-22 05:58:43 -05:00
|
|
|
cmd = example(api)
|
2009-12-09 10:09:53 -06:00
|
|
|
inst = self.cls('stuff')
|
|
|
|
|
|
|
|
okay = dict(foo='bar')
|
|
|
|
nope = ('aye', 'bee')
|
|
|
|
|
2014-03-27 08:04:00 -05:00
|
|
|
e = raises(TypeError, inst.validate,
|
|
|
|
cmd, [okay, okay, nope], API_VERSION)
|
2009-12-09 10:09:53 -06:00
|
|
|
assert str(e) == output.emsg % (
|
|
|
|
'example', 'ListOfEntries', 'stuff', 2, dict, tuple, nope
|
|
|
|
)
|
|
|
|
|
2014-03-27 08:04:00 -05:00
|
|
|
e = raises(TypeError, inst.validate,
|
|
|
|
cmd, [nope, okay, nope], API_VERSION)
|
2009-12-09 10:09:53 -06:00
|
|
|
assert str(e) == output.emsg % (
|
|
|
|
'example', 'ListOfEntries', 'stuff', 0, dict, tuple, nope
|
|
|
|
)
|