| |
@@ -913,17 +913,25 @@
|
| |
with patch('sys.argv', new=cli_cmd):
|
| |
return self.new_cli(name=name, cfg=cfg, user_cfg=user_cfg)
|
| |
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
@patch('sys.stdout', new=StringIO())
|
| |
- def test_request_branch(self, mock_grb, mock_request_post):
|
| |
+ def test_request_branch(self, mock_grb, mock_request_post, mock_request_get):
|
| |
"""Tests request-branch"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
mock_request_post.return_value = mock_rv
|
| |
+
|
| |
# Checkout the f27 branch
|
| |
self.run_cmd(['git', 'checkout', 'f27'], cwd=self.cloned_repo_path)
|
| |
|
| |
@@ -932,6 +940,8 @@
|
| |
cli = self.get_cli(cli_cmd)
|
| |
cli.request_branch()
|
| |
|
| |
+ self.assertEqual(1, mock_request_get.call_count)
|
| |
+
|
| |
expected_issue_content = {
|
| |
'action': 'new_branch',
|
| |
'repo': 'testpkg',
|
| |
@@ -949,13 +959,47 @@
|
| |
'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_existing_branch(self, mock_grb, mock_request_post, mock_request_get):
|
| |
+ """Tests request-existing-branch"""
|
| |
+ mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
+ 'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ # branch 'f27' already exists and there is no POST request sent to Pagure (it would create
|
| |
+ # an issue)
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "f27", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
+ # Checkout the f27 branch
|
| |
+ self.run_cmd(['git', 'checkout', 'f27'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
| |
+ 'request-branch']
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ cli.request_branch()
|
| |
+
|
| |
+ self.assertEqual(1, mock_request_get.call_count)
|
| |
+ mock_request_post.assert_not_called()
|
| |
+
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
@patch('sys.stdout', new=StringIO())
|
| |
- def test_request_branch_override(self, mock_grb, mock_request_post):
|
| |
+ def test_request_branch_override(self, mock_grb, mock_request_post, mock_request_get):
|
| |
"""Tests request-branch with an overridden package and branch name"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
@@ -966,6 +1010,8 @@
|
| |
cli = self.get_cli(cli_cmd)
|
| |
cli.request_branch()
|
| |
|
| |
+ self.assertEqual(1, mock_request_get.call_count)
|
| |
+
|
| |
expected_issue_content = {
|
| |
'action': 'new_branch',
|
| |
'repo': 'nethack',
|
| |
@@ -1010,6 +1056,8 @@
|
| |
cli = self.get_cli(cli_cmd)
|
| |
cli.request_branch()
|
| |
|
| |
+ self.assertEqual(2, mock_request_get.call_count)
|
| |
+
|
| |
expected_issue_content = {
|
| |
'action': 'new_branch',
|
| |
'repo': 'sudoku',
|
| |
@@ -1040,15 +1088,17 @@
|
| |
"""Tests request-epel-branch-override"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7', 'epel8']}
|
| |
- mock_rv = Mock()
|
| |
- 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
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
# Checkout the epel7 branch
|
| |
self.run_cmd(['git', 'checkout', 'epel7'], cwd=self.cloned_repo_path)
|
| |
|
| |
@@ -1077,13 +1127,20 @@
|
| |
'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_branch_module(self, mock_grb, mock_request_post):
|
| |
+ def test_request_branch_module(self, mock_grb, mock_request_post, mock_request_get):
|
| |
"""Tests request-branch for a new module branch"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
@@ -1112,12 +1169,20 @@
|
| |
'fedora-scm-requests/issue/2')
|
| |
self.assertEqual(output, expected_output)
|
| |
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
- def assert_request_branch_container(self, cli_cmd, mock_grb, mock_request_post):
|
| |
+ def assert_request_branch_container(self, cli_cmd, mock_grb, mock_request_post,
|
| |
+ mock_request_get):
|
| |
"""Tests request-branch for a new container branch"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
@@ -1157,15 +1222,28 @@
|
| |
'--repo', 'nethack', '--namespace', 'container', 'f27']
|
| |
self.assert_request_branch_container(cli_cmd)
|
| |
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
@patch('fedpkg.cli.verify_sls')
|
| |
@patch('sys.stdout', new=StringIO())
|
| |
def test_request_branch_sls(self, mock_verify_sls, mock_grb,
|
| |
- mock_request_post):
|
| |
+ mock_request_post, mock_request_get):
|
| |
"""Tests request-branch with service levels"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ responses = []
|
| |
+ mock_rv_get = Mock()
|
| |
+ mock_rv_get.ok = True
|
| |
+ mock_rv_get.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ responses.append(mock_rv_get)
|
| |
+ mock_rv_get = Mock()
|
| |
+ mock_rv_get.ok = False
|
| |
+ mock_rv_get.json.return_value = {'error': 'Project not found', 'error_code': 'ENOPROJECT'}
|
| |
+ responses.append(mock_rv_get)
|
| |
+ mock_request_get.side_effect = responses
|
| |
+
|
| |
responses = []
|
| |
for idx in range(2, 5):
|
| |
mock_rv_post = Mock()
|
| |
@@ -1180,6 +1258,7 @@
|
| |
cli = self.get_cli(cli_cmd)
|
| |
cli.request_branch()
|
| |
|
| |
+ self.assertEqual(2, mock_request_get.call_count)
|
| |
# Get the data that was submitted to Pagure
|
| |
output = sys.stdout.getvalue().strip()
|
| |
# Three bugs are filed. One for the rpm branch, and one for a new
|
| |
@@ -1247,13 +1326,23 @@
|
| |
post_data)['issue_content'].strip('```'))
|
| |
self.assertDictEqual(expected_issue_content, actual_issue_content)
|
| |
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
@patch('sys.stdout', new=StringIO())
|
| |
- def test_request_branch_all_releases(self, mock_grb, mock_request_post):
|
| |
+ def test_request_branch_all_releases(self, mock_grb, mock_request_post, mock_request_get):
|
| |
"""Tests request-branch with the '--all-releases' option """
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ get_side_effect = []
|
| |
+ for i in range(1, 4):
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["main", "rawhide"]}
|
| |
+ get_side_effect.append(mock_rv)
|
| |
+ mock_request_post.side_effect = get_side_effect
|
| |
+
|
| |
post_side_effect = []
|
| |
for i in range(1, 4):
|
| |
mock_rv = Mock()
|
| |
@@ -1268,6 +1357,8 @@
|
| |
cli = self.get_cli(cli_cmd)
|
| |
cli.request_branch()
|
| |
|
| |
+ self.assertEqual(3, mock_request_get.call_count)
|
| |
+
|
| |
for i in range(3):
|
| |
expected_issue_content = {
|
| |
'action': 'new_branch',
|
| |
@@ -1431,13 +1522,20 @@
|
| |
with six.assertRaisesRegex(self, rpkgError, expected_error):
|
| |
cli.request_branch()
|
| |
|
| |
+ @patch('requests.get')
|
| |
@patch('requests.post')
|
| |
@patch('fedpkg.cli.get_release_branches')
|
| |
@patch('sys.stdout', new=StringIO())
|
| |
- def test_request_with_repo_option(self, mock_grb, mock_request_post):
|
| |
+ def test_request_with_repo_option(self, mock_grb, mock_request_post, mock_request_get):
|
| |
"""Test request branch with option --repo"""
|
| |
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
| |
'epel': ['el6', 'epel7']}
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"branches": ["f25", "f26", "main", "rawhide"]}
|
| |
+ mock_request_get.return_value = mock_rv
|
| |
+
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
mock_rv.json.return_value = {'issue': {'id': 2}}
|
| |
Prevent opening an issue for 'fedora-scm-requests' team to create
a new branch when the branch already exists.
JIRA: RHELCMP-9404
Fixes: #481
Signed-off-by: Ondrej Nosek onosek@redhat.com