api getLastHostUpdate returns timestamp
fixes: https://pagure.io/koji/issue/2497
This commit is contained in:
parent
217704fd67
commit
9dc0efd476
6 changed files with 150 additions and 14 deletions
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
import os
|
||||
import time
|
||||
import locale
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
|
|
@ -10,13 +12,51 @@ from . import utils
|
|||
|
||||
class TestListHosts(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
# force locale to compare 'expect' value
|
||||
locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.original_timezone = os.environ.get('TZ')
|
||||
os.environ['TZ'] = 'UTC'
|
||||
time.tzset()
|
||||
|
||||
def tearDown(self):
|
||||
locale.resetlocale()
|
||||
if self.original_timezone is None:
|
||||
del os.environ['TZ']
|
||||
else:
|
||||
os.environ['TZ'] = self.original_timezone
|
||||
time.tzset()
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||
@mock.patch('koji_cli.commands.ensure_connection')
|
||||
def test_list_hosts_valid(self, ensure_connection, stdout):
|
||||
host_update = 1615875554.862938
|
||||
expected = """kojibuilder Y Y 0.0/2.0 x86_64 Tue, 16 Mar 2021 06:19:14 UTC
|
||||
"""
|
||||
list_hosts = [{'arches': 'x86_64',
|
||||
'capacity': 2.0,
|
||||
'comment': None,
|
||||
'description': None,
|
||||
'enabled': True,
|
||||
'id': 1,
|
||||
'name': 'kojibuilder',
|
||||
'ready': True,
|
||||
'task_load': 0.0,
|
||||
'user_id': 2}]
|
||||
self.session.getLastHostUpdate.return_value = host_update
|
||||
self.session.multiCall.return_value = [[host_update]]
|
||||
self.session.listHosts.return_value = list_hosts
|
||||
rv = anon_handle_list_hosts(self.options, self.session, [])
|
||||
self.assertEqual(rv, None)
|
||||
self.assert_console_message(stdout, expected)
|
||||
self.session.listHosts.assert_called_once_with()
|
||||
self.session.getLastHostUpdate.assert_called_once_with(list_hosts[0]['id'], ts=True)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_pkgs_non_exist_channel(self, stderr):
|
||||
def test_list_hosts_non_exist_channel(self, stderr):
|
||||
channel = 'test-channel'
|
||||
expected = "Usage: %s list-hosts [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue