#476 fedpkg update --suggest-logout option added
Merged 2 years ago by onosek. Opened 2 years ago by drumian.
drumian/fedpkg suggest-logout_command  into  master

file modified
+4
@@ -62,6 +62,7 @@ 

  

          UPDATE_TYPES = ['bugfix', 'security', 'enhancement', 'newpackage']

          REQUEST_TYPES = ['testing', 'stable']

+         SUGGEST_TYPES = ['unspecified', 'reboot', 'logout']

  

          @clear_csrf_and_retry

          def save(self, *args, **kwargs):
@@ -359,6 +360,9 @@ 

              if detail['request'] not in BodhiClient.REQUEST_TYPES:

                  raise ValueError(

                      'Incorrect request type {0}'.format(detail['request']))

+             if detail['suggest'] not in BodhiClient.SUGGEST_TYPES:

+                 raise ValueError(

+                     'Incorrect suggest type {0}'.format(detail['suggest']))

  

              try:

                  self.log.info(bodhi.update_str(bodhi.save(**detail), minimal=False))

file modified
+25 -9
@@ -78,8 +78,10 @@ 

  # Automatically close bugs when this marked as stable

  close_bugs=%(close_bugs)s

  

- # Suggest that users restart after update

- suggest_reboot=%(suggest_reboot)s

+ # Suggest that users performs one of the following actions after the update:

+ # unspecified, restart, logout

+ # The default value is unspecified

+ suggest=%(suggest)s

  

  # A boolean to require that all of the bugs in your update have been confirmed by testers.

  require_bugs=%(require_bugs)s
@@ -245,12 +247,6 @@ 

                   ' automatically. If this is what you do not want, use this '

                   'option to disable the default behavior.')

          update_parser.add_argument(

-             '--suggest-reboot',

-             action='store_true',

-             default=False,

-             dest='suggest_reboot',

-             help='Suggest user to reboot after update. Default is False.')

-         update_parser.add_argument(

              '--no-require-bugs',

              action='store_false',

              default=True,
@@ -264,6 +260,21 @@ 

              dest='require_testcases',

              help='Disables the requirement that this update passes all test cases '

                   'before reaching stable. Default is True.')

+ 

+         group = update_parser.add_mutually_exclusive_group()

+         group.add_argument(

+             '--suggest-reboot',

+             action='store_true',

+             default=False,

+             dest='suggest_reboot',

+             help='Suggest user to reboot after update. Default is False.')

+         group.add_argument(

+             '--suggest-logout',

+             action='store_true',

+             default=False,

+             dest='suggest_logout',

+             help='Suggest user to logout after update. Default is False.')

+ 

          update_parser.set_defaults(command=self.update)

  

      def get_distgit_namespaces(self):
@@ -810,11 +821,16 @@ 

              'stable_karma': self.args.stable_karma,

              'unstable_karma': self.args.unstable_karma,

              'close_bugs': str(self.args.close_bugs),

-             'suggest_reboot': str(self.args.suggest_reboot),

+             'suggest': 'unspecified',

              'require_bugs': str(self.args.require_bugs),

              'require_testcases': str(self.args.require_testcases),

          }

  

+         if self.args.suggest_reboot:

+             bodhi_args['suggest'] = 'reboot'

+         elif self.args.suggest_logout:

+             bodhi_args['suggest'] = 'logout'

+ 

          if self.args.update_type:

              bodhi_args['type_'] = self.args.update_type

          else:

file modified
+14 -1
@@ -169,7 +169,8 @@ 

      @patch('fedora.client.OpenIdBaseClient._load_cookies')

      def assert_bodhi_update(self, cli, _load_cookies, send_request, csrf,

                              update_type=None, request_type=None, notes=None,

-                             stable_karma=None, unstable_karma=None):

+                             stable_karma=None, unstable_karma=None,

+                             suggest=None):

          csrf.return_value = '123456'

  

          def run_command_side_effect(command, shell):
@@ -189,6 +190,10 @@ 

                      content = re.sub('request=[a-z]+\n',

                                       'request={0}\n'.format(request_type),

                                       content)

+                 if suggest:

+                     content = re.sub('suggest=[a-z]+\n',

+                                      'suggest={0}\n'.format(suggest),

+                                      content)

                  f.write(content)

  

          self.mock_run_command.side_effect = run_command_side_effect
@@ -327,6 +332,14 @@ 

                                update_type='enhancement',

                                request_type='xxx')

  

+     def test_incorrect_suggest_type_in_template(self):

+         cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']

+         cli = self.get_cli(cli_cmd)

+         six.assertRaisesRegex(self, rpkgError, 'Incorrect suggest type',

+                               self.assert_bodhi_update, cli,

+                               update_type='enhancement',

+                               suggest='123')

+ 

      def test_create_with_cli_options(self):

          cli_cmd = [

              'fedpkg-stage', '--path', self.cloned_repo_path,

Option --suggest-logout was not implemented although it
is supported by Bodhi. This commit adds this option.

Jira: RHELCMP-8704
Fixes: https://pagure.io/fedpkg/issue/472

Signed-off-by: Dominik Rumian drumian@redhat.com

Fix the comment. Maybe show possible values in it.

Fix the comment. Maybe show possible values in it.

Of course. I will do it.

You could use this code for basic unit-testing.

diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py
index a52c70d..c69f757 100644
--- a/fedpkg/__init__.py
+++ b/fedpkg/__init__.py
@@ -62,6 +62,7 @@ if _BodhiClient is not None:

         UPDATE_TYPES = ['bugfix', 'security', 'enhancement', 'newpackage']
         REQUEST_TYPES = ['testing', 'stable']
+        SUGGEST_TYPES = ['unspecified', 'reboot', 'logout']

         @clear_csrf_and_retry
         def save(self, *args, **kwargs):
@@ -359,7 +360,9 @@ class Commands(pyrpkg.Commands):
             if detail['request'] not in BodhiClient.REQUEST_TYPES:
                 raise ValueError(
                     'Incorrect request type {0}'.format(detail['request']))
-
+            if detail['suggest'] not in BodhiClient.SUGGEST_TYPES:
+                raise ValueError(
+                    'Incorrect suggest type {0}'.format(detail['suggest']))
             try:
                 self.log.info(bodhi.update_str(bodhi.save(**detail), minimal=False))
             # Only because tests do not return a valid bodhi.save value
diff --git a/test/test_cli.py b/test/test_cli.py
index 957cefe..63e0876 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -169,7 +169,8 @@ class TestUpdate(CliTestCase):
     @patch('fedora.client.OpenIdBaseClient._load_cookies')
     def assert_bodhi_update(self, cli, _load_cookies, send_request, csrf,
                             update_type=None, request_type=None, notes=None,
-                            stable_karma=None, unstable_karma=None):
+                            stable_karma=None, unstable_karma=None,
+                            suggest=None):
         csrf.return_value = '123456'

         def run_command_side_effect(command, shell):
@@ -189,6 +190,10 @@ class TestUpdate(CliTestCase):
                     content = re.sub('request=[a-z]+\n',
                                      'request={0}\n'.format(request_type),
                                      content)
+                if suggest:
+                    content = re.sub('suggest=[a-z]+\n',
+                                     'suggest={0}\n'.format(suggest),
+                                     content)
                 f.write(content)

         self.mock_run_command.side_effect = run_command_side_effect
@@ -327,6 +332,14 @@ class TestUpdate(CliTestCase):
                               update_type='enhancement',
                               request_type='xxx')

+    def test_incorrect_suggest_in_template(self):
+        cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
+        cli = self.get_cli(cli_cmd)
+        six.assertRaisesRegex(self, rpkgError, 'Incorrect suggest',
+                              self.assert_bodhi_update, cli,
+                              suggest='xxx',
+                              update_type='enhancement')
+
     def test_create_with_cli_options(self):
         cli_cmd = [
             'fedpkg-stage', '--path', self.cloned_repo_path,

You could use this code for basic unit-testing.

~
diff --git a/fedpkg/init.py b/fedpkg/init.py

thank you, I will try it

rebased onto 07e7c53

2 years ago

Looks like it's working.

Pull-Request has been merged by onosek

2 years ago