From f853263c479c5415897d61e0ab6a84dccc5a4179 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Nov 29 2019 13:04:49 +0000 Subject: Mock requests in all tests Without this the test do network operations and fail when run with no network access. Signed-off-by: Lubomír Sedlář --- diff --git a/test/test_cli.py b/test/test_cli.py index 58dd0d9..9c12567 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -942,10 +942,13 @@ class TestRequestBranch(CliTestCase): 'fedora-scm-requests/issue/2') self.assertEqual(output, expected_output) + @patch('requests.get') @patch('requests.post') @patch('fedpkg.cli.get_release_branches') @patch('sys.stdout', new=StringIO()) - def test_request_epel_branch_override(self, mock_grb, mock_request_post): + def test_request_epel_branch_override( + self, mock_grb, mock_request_post, mock_request_get + ): """Tests request-epel-branch-override epel8 branch operation generates two requests for two branches: @@ -957,6 +960,11 @@ class TestRequestBranch(CliTestCase): mock_rv.ok = True mock_rv.json.return_value = {'issue': {'id': 2}} mock_request_post.return_value = mock_rv + + mock_rv = Mock() + mock_rv.ok = True + mock_rv.json.return_value = {"arches": [], "packages": {}} + mock_request_get.return_value = mock_rv # Checkout the epel7 branch self.run_cmd(['git', 'checkout', 'epel8'], cwd=self.cloned_repo_path) diff --git a/test/test_retire.py b/test/test_retire.py index a967458..af5fd59 100644 --- a/test/test_retire.py +++ b/test/test_retire.py @@ -72,6 +72,7 @@ class RetireTestCase(unittest.TestCase): 'fedpkg.spec'))) self.assertEqual(self._get_latest_commit(), reason) + @mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404)) def test_retire_with_namespace(self): self._setup_repo('ssh://git@pkgs.example.com/rpms/fedpkg') args = ['fedpkg', '--dist=master', 'retire', 'my reason'] @@ -82,6 +83,7 @@ class RetireTestCase(unittest.TestCase): self.assertRetired('my reason') self.assertEqual(len(client.cmd.push.call_args_list), 1) + @mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404)) def test_retire_without_namespace(self): self._setup_repo('ssh://git@pkgs.example.com/fedpkg') args = ['fedpkg', '--dist=master', 'retire', 'my reason'] @@ -92,6 +94,7 @@ class RetireTestCase(unittest.TestCase): self.assertRetired('my reason') self.assertEqual(len(client.cmd.push.call_args_list), 1) + @mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404)) def test_package_is_retired_already(self): self._setup_repo('ssh://git@pkgs.example.com/fedpkg') with open(os.path.join(self.tmpdir, 'dead.package'), 'w') as f: