Exemple #1
0
    def test_anon_handle_taskinfo(self, activate_session_mock, stdout):
        """Test anon_handle_taskinfo function"""
        session = mock.MagicMock()
        options = mock.MagicMock()

        # Case 1. no task id error
        expected = self.format_error_message(
            "You must specify at least one task ID")

        self.assert_system_exit(anon_handle_taskinfo,
                                options,
                                session, [],
                                stderr=expected,
                                activate_session=None)
        activate_session_mock.assert_not_called()

        # Case 2. show task info
        task_output = """Task: 1
Type: newRepo
Owner: kojiadmin
State: closed
Created: Thu Nov 16 17:34:29 2017
Started: Thu Nov 16 17:51:07 2017
Finished: Thu Nov 16 17:54:55 2017
Host: kojibuilder
"""

        def print_task(*args, **kwargs):
            print(task_output, end='')

        with mock.patch('koji_cli.commands._printTaskInfo', new=print_task):
            anon_handle_taskinfo(options, session, ['1'])
        self.assert_console_message(stdout, task_output)
    def test_anon_handle_taskinfo(
            self,
            activate_session_mock,
            stdout):
        """Test anon_handle_taskinfo function"""
        session = mock.MagicMock()
        options = mock.MagicMock()

        # Case 1. no task id error
        expected = self.format_error_message(
            "You must specify at least one task ID")

        self.assert_system_exit(
            anon_handle_taskinfo,
            options,
            session,
            [],
            stderr=expected,
            activate_session=None)
        activate_session_mock.assert_not_called()

        # Case 2. show task info
        task_output = """Task: 1
Type: newRepo
Owner: kojiadmin
State: closed
Created: Thu Nov 16 17:34:29 2017
Started: Thu Nov 16 17:51:07 2017
Finished: Thu Nov 16 17:54:55 2017
Host: kojibuilder
"""

        def print_task(*args, **kwargs):
            print(task_output, end='')

        with mock.patch('koji_cli.commands._printTaskInfo', new=print_task):
            anon_handle_taskinfo(options, session, ['1'])
        self.assert_console_message(stdout, task_output)