debian-koji/tests/test_cli/test_list_volumes.py
Yuming Zhu ca05418fb5 unittest: use unittest.mock instead of mock
because the absence of unittest.mock on python2.7, we still fallback to
mock
2024-10-23 16:35:30 +00:00

50 lines
1.4 KiB
Python

from __future__ import absolute_import
try:
from unittest import mock
except ImportError:
import mock
import six
import unittest
from koji_cli.commands import anon_handle_list_volumes
from . import utils
class TestListVolumes(utils.CliTestCase):
# Show long diffs in error output...
maxDiff = None
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.ensure_connection')
def test_anon_handle_list_volumes(
self,
ensure_connection_mock,
stdout):
"""Test anon_handle_list_volumes function"""
session = mock.MagicMock()
options = mock.MagicMock()
vol_info = [
{'id': 1, 'name': 'DEFAULT'},
{'id': 2, 'name': 'TEST-1'},
{'id': 3, 'name': 'TEST-2'},
]
expected = "\n".join([v['name'] for v in vol_info]) + "\n"
session.listVolumes.return_value = vol_info
anon_handle_list_volumes(options, session, [])
self.assert_console_message(stdout, expected)
def test_anon_handle_list_volumes_help(self):
self.assert_help(
anon_handle_list_volumes,
"""Usage: %s list-volumes
(Specify the --help global option for a list of other help options)
Options:
-h, --help show this help message and exit
""" % self.progname)
if __name__ == '__main__':
unittest.main()