#40 Fix typo and extend tests
Merged 3 years ago by mohanboddu. Opened 3 years ago by humaton.
humaton/fedscm-admin master  into  master

file modified
+1 -1
@@ -199,7 +199,7 @@ 

      payload = {

          'namespace': namespace,

          'name': repo,

-         'description': description or 'The {0} package\n'.format(repo)

+         'description': description or 'The {0} package\n'.format(repo),

          'url': upstreamurl or '',

          'wait': True

      }

@@ -86,11 +86,11 @@ 

          return requests_function(*args, **kwargs)

      except (ConnectionError, ConnectTimeout) as e:

          if service_name is not None:

-             error_msg = ('Could not connect to "{0}" at {1}. Please try again.'

-                          .format(service_name, e.request.url))

+             error_msg = f'Could not connect to "{service_name}" ' \

+                         f'at {e.request.url}. Please try again.'

          else:

-             error_msg = ('Could not connect to a required service at {1}. '

-                          'Please try again.'.format(e.request.url))

+             error_msg = f'Could not connect to a required service at "{e.request.url}". ' \

+                         f'Please try again.'

          raise click.ClickException(error_msg)

  

  

file modified
+5 -5
@@ -101,7 +101,7 @@ 

      return issue

  

  

- def get_mock_new_repo_issue(branch, sla=None, repo='nethack', exception=False):

+ def get_mock_new_repo_issue(branch, sla=None, repo='nethack', exception=False, namespace='rpms'):

      content = {

          'bug_id': '1441813',

          'repo': repo,
@@ -110,8 +110,8 @@ 

          'action': 'new_repo',

          'upstreamurl': '',

          'summary': 'A rogue-like single player dungeon exploration game',

-         'namespace': 'rpms',

-         'monitor': 'monitoring-with-scratch'

+         'monitor': 'monitoring-with-scratch',

+         'namespace': namespace

      }

      if sla:

          content['sls'] = sla
@@ -124,11 +124,11 @@ 

  

  

  def get_mock_issue_rv(branch, sla=None, ticket_type='new_repo',

-                       repo='nethack', exception=False):

+                       repo='nethack', exception=False, namespace='rpms'):

      mock_rv = Mock()

      mock_rv.ok = True

      if ticket_type == 'new_repo':

-         title, content = get_mock_new_repo_issue(branch, sla, repo, exception)

+         title, content = get_mock_new_repo_issue(branch, sla, repo, exception, namespace)

      else:

          title, content = get_mock_new_branch_issue(branch, sla, repo)

  

file modified
+86
@@ -160,6 +160,92 @@ 

  

      @patch('fedscm_admin.utils.verify_slas', return_value=None)

      @patch('fedscm_admin.request_utils.retry_session')

+     def test_fedscm_admin_process_modules(self, mock_retry_session, mock_slas):

+         """

+         Tests fedscm-admin with the option "process" on a new repo request

+         for a module

+         """

+         from fedscm_admin.fedscm_admin import cli as fedscm_admin_cli

+         mock_session = Mock()

+         mock_rv = Mock()

+         mock_rv.ok = True

+         mock_rv.json.return_value = {}

+         mock_session.get.side_effect = [

+             mock_values.get_mock_issue_rv(

+                 'abc', sla={'security_fixes': '2025-06-01'}, namespace='modules'),

+             mock_values.get_mock_users_query('akhairna'),

+             mock_values.get_mock_pagure_project(exists=False),

+             mock_values.get_mock_pdc_branch('abc', exists=False),

+             mock_values.get_mock_pdc_branch('master', exists=False),

+             mock_values.get_mock_pdc_global_component(exists=True),

+             mock_values.get_mock_pdc_branch('abc', exists=False),

+             mock_values.get_mock_pdc_branch('master', exists=False),

+             mock_values.get_mock_pagure_git_urls()

+         ]

+         mock_session.post.return_value = mock_rv

+         mock_session.patch.return_value = mock_rv

+         mock_retry_session.return_value = mock_session

+         runner = CliRunner()

+         result = runner.invoke(

+             fedscm_admin_cli, ['process', '2'],

+             input='mprahl\n12345\nmprahl\n12345\napprove\nn\n')

+         assert result.exit_code == 0

+         assert result.output.count('- Adding comment to Pagure issue') == 1

+         assert result.output.count('- Adding comment to rhbz#') == 1

+         outputs = [

+             'New Repo for "rpms/nethack"',

+             'The Pagure repository was created',

+             'You may commit to the branch "abc" in about 10 minutes.'

+         ]

+         for output in outputs:

+             assert output in result.output

+         assert self.mock_git_obj.clone_repo.call_count == 0

+ 

+     @patch('fedscm_admin.utils.verify_slas', return_value=None)

+     @patch('fedscm_admin.request_utils.retry_session')

+     def test_fedscm_admin_process_tests(self, mock_retry_session, mock_slas):

+         """

+         Tests fedscm-admin with the option "process" on a new repo request

+         for a repo for shared tests

+         """

+         from fedscm_admin.fedscm_admin import cli as fedscm_admin_cli

+         mock_session = Mock()

+         mock_rv = Mock()

+         mock_rv.ok = True

+         mock_rv.json.return_value = {}

+         mock_session.get.side_effect = [

+             mock_values.get_mock_issue_rv(

+                 'abc', sla={'security_fixes': '2025-06-01'}, namespace='tests'),

+             mock_values.get_mock_users_query('akhairna'),

+             mock_values.get_mock_pagure_project(exists=False),

+             mock_values.get_mock_pdc_branch('abc', exists=False),

+             mock_values.get_mock_pdc_branch('master', exists=False),

+             mock_values.get_mock_pdc_global_component(exists=True),

+             mock_values.get_mock_pdc_branch('abc', exists=False),

+             mock_values.get_mock_pdc_branch('master', exists=False),

+             mock_values.get_mock_pagure_git_urls()

+         ]

+         mock_session.post.return_value = mock_rv

+         mock_session.patch.return_value = mock_rv

+         mock_retry_session.return_value = mock_session

+         runner = CliRunner()

+         result = runner.invoke(

+             fedscm_admin_cli, ['process', '2'],

+             input='mprahl\n12345\nmprahl\n12345\napprove\nn\n')

+         assert result.exit_code == 0

+         assert result.output.count('- Adding comment to Pagure issue') == 1

+         assert result.output.count('- Adding comment to rhbz#') == 1

+         outputs = [

+             'New Repo for "rpms/nethack"',

+             'The Pagure repository was created',

+             'You may commit to the branch "abc" in about 10 minutes.'

+         ]

+         for output in outputs:

+             assert output in result.output

+         assert self.mock_git_obj.clone_repo.call_count == 0

+ 

+     @patch('fedscm_admin.utils.verify_slas', return_value=None)

+     @patch('fedscm_admin.request_utils.retry_session')

      def test_fedscm_admin_process_force(

              self, mock_retry_session, mock_slas):

          """

Introduce two new tests for modules and test namespace.
Actual code coverage has increased 0.98%

I'm kinda wondering how this worked until now

Turns out this was changed in https://pagure.io/fedscm-admin/c/d28d87936879f41bd2531bb472361606865e4b28 which hasn't been released yet, so that's why it wasn't noticed until now.

:thumbsup: to merge for me

2 new commits added

  • Use namespace in tests
  • Make linter happy
3 years ago

Pull-Request has been merged by mohanboddu

3 years ago