From 9e7be65b1a2ecce09ef8ca314e4a3cef35735fbc Mon Sep 17 00:00:00 2001
From: Tomas Hrcka <thrcka@redhat.com>
Date: Jul 31 2020 09:47:54 +0000
Subject: [PATCH 1/3] Fix missing character


---

diff --git a/fedscm_admin/pagure.py b/fedscm_admin/pagure.py
index b50a2f6..52c4809 100644
--- a/fedscm_admin/pagure.py
+++ b/fedscm_admin/pagure.py
@@ -199,7 +199,7 @@ def new_project(namespace, repo, description, upstreamurl,
     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
     }

From eb513b8994e6bcf9eac98d15f0127ff4f2d174d0 Mon Sep 17 00:00:00 2001
From: Tomas Hrcka <thrcka@redhat.com>
Date: Jul 31 2020 10:30:25 +0000
Subject: [PATCH 2/3] Make linter happy


---

diff --git a/fedscm_admin/request_utils.py b/fedscm_admin/request_utils.py
index 8d99854..4ea9662 100644
--- a/fedscm_admin/request_utils.py
+++ b/fedscm_admin/request_utils.py
@@ -86,11 +86,11 @@ def requests_wrapper(*args, **kwargs):
         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)
 
 

From f7a8ee9030f7069fff721906317221bd0d8ac9d0 Mon Sep 17 00:00:00 2001
From: Tomas Hrcka <thrcka@redhat.com>
Date: Jul 31 2020 11:14:16 +0000
Subject: [PATCH 3/3] Use namespace in tests


---

diff --git a/tests/mock_values.py b/tests/mock_values.py
index 3b9d3cc..1312965 100644
--- a/tests/mock_values.py
+++ b/tests/mock_values.py
@@ -101,7 +101,7 @@ def get_mock_new_issue_invalid_action():
     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 @@ def get_mock_new_repo_issue(branch, sla=None, repo='nethack', exception=False):
         '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_new_repo_issue(branch, sla=None, repo='nethack', exception=False):
 
 
 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)
 
diff --git a/tests/test_admin.py b/tests/test_admin.py
index 73f7589..870fcef 100644
--- a/tests/test_admin.py
+++ b/tests/test_admin.py
@@ -160,6 +160,92 @@ class FedScmAdmin(TestCase):
 
     @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):
         """

