cli: drop unneeded activate_session

Fixes: https://pagure.io/koji/issue/2070
This commit is contained in:
Tomas Kopecek 2020-05-05 11:15:25 +02:00
parent c4b5316cba
commit 637be55ef4
9 changed files with 101 additions and 86 deletions

View file

@ -47,7 +47,7 @@ class TestDownloadTask(utils.CliTestCase):
self.list_task_output_all_volumes = mock.patch('koji_cli.commands.list_task_output_all_volumes').start()
self.ensuredir = mock.patch('koji.ensuredir').start()
self.download_file = mock.patch('koji_cli.commands.download_file').start()
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()
self.ensure_connection = mock.patch('koji_cli.commands.ensure_connection').start()
self.stdout = mock.patch('sys.stdout', new_callable=six.StringIO).start()
self.stderr = mock.patch('sys.stderr', new_callable=six.StringIO).start()
@ -80,7 +80,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = ''
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@ -105,8 +105,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = 'No such task: #123333\n'
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session,
self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
@ -148,7 +147,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = ''
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_called_once_with(task_id)
self.assertEqual(self.list_task_output_all_volumes.mock_calls, [
@ -189,7 +188,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = ''
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@ -224,7 +223,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = 'No files for download found.\n'
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@ -257,7 +256,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = 'Task 123333 has not finished yet.\n'
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@ -288,7 +287,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = 'Child task 22222 has not finished yet.\n'
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_called_once_with(task_id)
self.list_task_output_all_volumes.assert_called_once_with(self.session, 22222)
@ -315,7 +314,7 @@ class TestDownloadTask(utils.CliTestCase):
expected = 'Invalid file name: somerpm..src.rpm\n'
self.assertMultiLineEqual(actual, expected)
# Finally, assert that things were called as we expected.
self.activate_session.assert_called_once_with(self.session, self.options)
self.ensure_connection.assert_called_once_with(self.session)
self.session.getTaskInfo.assert_called_once_with(task_id)
self.session.getTaskChildren.assert_not_called()
self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)

View file

@ -23,10 +23,10 @@ class TestListApi(utils.CliTestCase):
""" % (self.progname, self.progname)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_anon_handle_list_api(
self,
activate_session_mock,
ensure_connection_mock,
stdout):
"""Test anon_handle_list_api function"""
session = mock.MagicMock()

View file

@ -19,8 +19,8 @@ class TestListChannels(unittest.TestCase):
self.args = []
@mock.patch('sys.stdout', new_callable=StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_list_channels(self, activate_session_mock, stdout):
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_channels(self, ensure_connection_mock, stdout):
self.session.listChannels.return_value = [
{'id': 1, 'name': 'default'},
{'id': 2, 'name': 'test'},
@ -47,4 +47,4 @@ default 3 1 0 1 6 22%
test 2 2 1 1 6 28%
"""
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
ensure_connection_mock.assert_called_once_with(self.session)

View file

@ -34,8 +34,10 @@ class TestListGroups(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_anon_handle_list_groups_argument_error(
self,
ensure_connection_mock,
activate_session_mock,
stdout):
"""Test anon_handle_list_groups function"""
@ -71,7 +73,8 @@ class TestListGroups(utils.CliTestCase):
expected = "Querying at event %(id)i (%(timestr)s)" % event + "\n"
self.__list_groups('build', ['--ts', '1234567'], expected)
def __list_groups(self, query_group, options, expected):
@mock.patch('koji_cli.commands.ensure_connection')
def __list_groups(self, query_group, options, expected, ensure_connection_mock):
_list_tags = [
{
'maven_support': False,

View file

@ -45,15 +45,15 @@ No notification blocks
self.maxDiff=None
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
activate_session_mock.assert_called_once()
self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])
self.session.getPackage.assert_has_calls([mock.call(11), mock.call(11)])
self.session.getUser.assert_not_called()
self.session.getBuildNotifications.assert_called_once_with(None)
@mock.patch('sys.stdout', new_callable=StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_list_notifications_user(self, activate_session_mock, stdout):
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_notifications_user(self, ensure_connection_mock, stdout):
self.session.getBuildNotifications.return_value = [
{'id': 1, 'tag_id': 1, 'package_id': 11, 'email': 'email@test.com', 'success_only': True},
{'id': 2, 'tag_id': None, 'package_id': 11, 'email': 'email@test.com', 'success_only': False},
@ -94,7 +94,7 @@ Notification blocks
self.maxDiff=None
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
ensure_connection_mock.assert_called_once_with(self.session)
self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])
self.session.getPackage.assert_has_calls([mock.call(11), mock.call(11)])
self.session.getUser.assert_called_once_with('random_name')

View file

@ -64,14 +64,13 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value={'id': 1000,
'ts': 1000000.11})
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_builds(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_builds(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest', '--inherit', '--event=1000']
anon_handle_list_tagged(self.options, self.session, args)
activate_session_mock.assert_called_once_with(self.session,
self.options)
ensure_connection_mock.assert_called_once_with(self.session)
self.session.getTag.assert_called_once_with('tag', event=1000)
self.session.listTagged.assert_called_once_with('tag',
event=1000,
@ -87,8 +86,8 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_builds_paths(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_builds_paths(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest', '--inherit', '--paths']
@ -100,15 +99,14 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_rpms(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_rpms(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest-n=3', '--rpms', '--sigs',
'--arch=x86_64', '--arch=noarch']
anon_handle_list_tagged(self.options, self.session, args)
activate_session_mock.assert_called_once_with(self.session,
self.options)
ensure_connection_mock.assert_called_once_with(self.session)
self.session.getTag.assert_called_once_with('tag', event=None)
self.session.listTaggedRPMS.assert_called_once_with('tag',
package='pkg',
@ -124,8 +122,8 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_rpms_paths(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_rpms_paths(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest-n=3', '--rpms',
'--arch=x86_64', '--paths']
@ -137,8 +135,8 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_sigs_paths(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_sigs_paths(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest-n=3', '--rpms', '--sigs',
'--arch=x86_64', '--paths']
@ -148,8 +146,8 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_type(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_type(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest-n=3', '--type=maven']
self.session.listTagged.return_value = [{'id': 1,
@ -163,8 +161,7 @@ class TestCliListTagged(utils.CliTestCase):
'maven_artifact_id': 'artifact'}]
anon_handle_list_tagged(self.options, self.session, args)
activate_session_mock.assert_called_once_with(self.session,
self.options)
ensure_connection_mock.assert_called_once_with(self.session)
self.session.getTag.assert_called_once_with('tag', event=None)
self.session.listTagged.assert_called_once_with('tag',
package='pkg',
@ -179,8 +176,8 @@ class TestCliListTagged(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value=None)
@mock.patch('koji_cli.commands.activate_session')
def test_list_tagged_type_paths(self, activate_session_mock,
@mock.patch('koji_cli.commands.ensure_connection')
def test_list_tagged_type_paths(self, ensure_connection_mock,
event_from_opts_mock, stdout):
args = ['tag', 'pkg', '--latest-n=3', '--type=maven', '--paths']
self.session.listTagged.return_value = [{'id': 1,
@ -199,9 +196,10 @@ class TestCliListTagged(utils.CliTestCase):
'---------------------------------------- -------------------- -------------------- -------------------- ----------------\n'
'/mnt/koji/packages/packagename/version/1.el6/maven tag group artifact owner\n')
@mock.patch('koji_cli.commands.ensure_connection')
@mock.patch('koji.util.eventFromOpts', return_value={'id': 1000,
'ts': 1000000.11})
def test_list_tagged_args(self, event_from_opts_mock):
def test_list_tagged_args(self, event_from_opts_mock, ensure_connection_mock):
# Case 1, no argument
expected = self.format_error_message(
"A tag name must be specified")
@ -233,7 +231,8 @@ class TestCliListTagged(utils.CliTestCase):
self.options,
self.session,
['tag', 'pkg1'],
stderr=expected)
stderr=expected,
activate_session=None)
def test_handle_list_tagged_help(self):
self.assert_help(

View file

@ -61,9 +61,9 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.genMockConfig')
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_handle_mock_config_buildroot_option(
self, activate_session_mock, gen_config_mock, stdout, stderr):
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
"""Test anon_handle_mock_config buildroot options"""
arguments = []
options = mock.MagicMock()
@ -89,7 +89,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
arguments = self.common_args + ['--buildroot', '1',
'--name', self.progname]
@ -117,9 +118,9 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.genMockConfig')
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_handle_mock_config_task_option(
self, activate_session_mock, gen_config_mock, stdout, stderr):
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
"""Test anon_handle_mock_config task options"""
arguments = []
task_id = 1001
@ -138,7 +139,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
arguments = ['--task', str(task_id)]
expected = "No buildroots for task %s (or no such task)\n" % str(task_id)
@ -176,9 +178,9 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.genMockConfig')
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_handle_mock_config_tag_option(
self, activate_session_mock, gen_config_mock, stdout, stderr):
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
"""Test anon_handle_mock_config with tag option"""
arguments = []
tag = 'tag'
@ -205,7 +207,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
# return tag info
session.getTag.return_value = tag
@ -248,10 +251,10 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.genMockConfig')
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
@mock.patch('koji_cli.commands.open')
def test_handle_mock_config_target_option(
self, openf, activate_session_mock, gen_config_mock, stdout, stderr):
self, openf, ensure_connection_mock, gen_config_mock, stdout, stderr):
"""Test anon_handle_mock_config with target option"""
arguments = []
arch = "x86_64"
@ -284,7 +287,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
session.getBuildTarget.return_value = target
expected = "Could not get a repo for tag: %s\n" % target['build_tag_name']
@ -321,7 +325,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
self.progname, arch, **opts)
@mock.patch('sys.stderr', new_callable=six.StringIO)
def test_handle_mock_config_errors(self, stderr):
@mock.patch('koji_cli.commands.ensure_connection')
def test_handle_mock_config_errors(self, ensure_connection_mock, stderr):
"""Test anon_handle_mock_config general error messages"""
arguments = []
options = mock.MagicMock()
@ -338,7 +343,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
# name is specified twice case
arguments = [self.progname, '--name', 'name']
@ -349,7 +355,8 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
options,
session,
arguments,
stderr=expected)
stderr=expected,
activate_session=None)
def test_handle_mock_config_help(self):
"""Test anon_handle_mock_config help message full output"""

View file

@ -596,8 +596,10 @@ class TestTaskInfo(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands.ensure_connection')
def test_anon_handle_taskinfo(
self,
ensure_connection_mock,
activate_session_mock,
stdout):
"""Test anon_handle_taskinfo function"""