#1365 Check CLI arguments for enable/disable host
Merged 6 months ago by mikem. Opened 7 months ago by tkopecek.
tkopecek/koji issue1364  into  master

@@ -1004,6 +1004,9 @@ 

      parser.add_option("--comment", help=_("Comment indicating why the host(s) are being disabled"))

      (options, args) = parser.parse_args(args)

  

+     if not args:

+         parser.error(_("At least one host must be specified"))

+ 

      activate_session(session, goptions)

      session.multicall = True

      for host in args:

@@ -1032,6 +1035,9 @@ 

      parser.add_option("--comment", help=_("Comment indicating why the host(s) are being enabled"))

      (options, args) = parser.parse_args(args)

  

+     if not args:

+         parser.error(_("At least one host must be specified"))

+ 

      activate_session(session, goptions)

      session.multicall = True

      for host in args:

@@ -16,6 +16,14 @@ 

      # Show long diffs in error output...

      maxDiff = None

  

+     def setUp(self):

+         self.error_format = """Usage: %s disable-host [options] hostname ...

+ (Specify the --help global option for a list of other help options)

+ 

+ %s: error: {message}

+ """ % (self.progname, self.progname)

+ 

+ 

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

      def test_handle_disable_host(

@@ -84,7 +92,7 @@ 

               call('host2', comment='disable host test')])

          self.assert_console_message(stdout, '')

  

-     @mock.patch('sys.stdout', new_callable=six.StringIO)

+     @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

      def test_handle_disable_host_no_argument(self, activate_session_mock, stdout):

          """Test %s function without arguments""" % handle_disable_host.__name__

@@ -96,13 +104,20 @@ 

          session.disableHost.return_value = True

          session.editHost.return_value = True

  

-         handle_disable_host(options, session, [])

-         activate_session_mock.assert_called_once()

+         expected = self.format_error_message("At least one host must be specified")

+         self.assert_system_exit(

+             handle_disable_host,

+             options,

+             session,

+             [],

+             stderr=expected,

+             activate_session=None)

+ 

+         activate_session_mock.assert_not_called()

          session.getHost.assert_not_called()

-         session.multiCall.assert_called()

+         session.multiCall.assert_not_called()

          session.disableHost.assert_not_called()

          session.editHost.assert_not_called()

-         self.assert_console_message(stdout, '')

  

      def test_handle_disable_host_help(self):

          """Test %s help message""" % handle_disable_host.__name__

@@ -16,6 +16,13 @@ 

      # Show long diffs in error output...

      maxDiff = None

  

+     def setUp(self):

+         self.error_format = """Usage: %s enable-host [options] hostname ...

+ (Specify the --help global option for a list of other help options)

+ 

+ %s: error: {message}

+ """ % (self.progname, self.progname)

+ 

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

      def test_handle_enable_host(

@@ -96,13 +103,20 @@ 

          session.enableHost.return_value = True

          session.editHost.return_value = True

  

-         handle_enable_host(options, session, [])

-         activate_session_mock.assert_called_once()

+         expected = self.format_error_message("At least one host must be specified")

+         self.assert_system_exit(

+             handle_enable_host,

+             options,

+             session,

+             [],

+             stderr=expected,

+             activate_session=None)

+ 

+         activate_session_mock.assert_not_called()

          session.getHost.assert_not_called()

-         session.multiCall.assert_called()

+         session.multiCall.assert_not_called()

          session.enableHost.assert_not_called()

          session.editHost.assert_not_called()

-         self.assert_console_message(stdout, '')

  

      def test_handle_enable_host_help(self):

          """Test %s help message""" % handle_enable_host.__name__

rebased onto 997c6b6

7 months ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

7 months ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

6 months ago

Commit ef4712a fixes this pull-request

Pull-Request has been merged by mikem

6 months ago