| |
@@ -24,6 +24,8 @@
|
| |
from unittest.mock import Mock, PropertyMock, call, patch
|
| |
|
| |
import git
|
| |
+ import arrow
|
| |
+
|
| |
# Use deprecated pkg_resources if packaging library isn't available (python 3.6)
|
| |
try:
|
| |
from packaging.version import parse as parse_version
|
| |
@@ -2498,3 +2500,274 @@
|
| |
except rpkgError as error:
|
| |
expected_error = "ERROR: Token is not properly formatted."
|
| |
self.assertEqual(error, expected_error)
|
| |
+
|
| |
+
|
| |
+ class TestRequestUnretirement(CliTestCase):
|
| |
+ """Test the request-unretirement cli command."""
|
| |
+
|
| |
+ def setUp(self):
|
| |
+ super(TestRequestUnretirement, self).setUp()
|
| |
+
|
| |
+ def tearDown(self):
|
| |
+ super(TestRequestUnretirement, self).tearDown()
|
| |
+
|
| |
+ def get_cli(self, cli_cmd, name='fedpkg-stage', cfg="fedpkg-stage.conf",
|
| |
+ user_cfg="fedpkg-user.conf"):
|
| |
+ with patch('sys.argv', new=cli_cmd):
|
| |
+ return self.new_cli(name=name, cfg=cfg, user_cfg=user_cfg)
|
| |
+
|
| |
+ @patch("fedpkg.cli.get_last_commit_date")
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement(self, mock_request_post, mock_grb, mock_gcd):
|
| |
+ """Tests request-unretirement command."""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ commit_time = arrow.now().shift(days=-1).timestamp()
|
| |
+ mock_gcd.return_value = commit_time
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f40'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement']
|
| |
+
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ cli.request_unretirement()
|
| |
+
|
| |
+ expected_issue_content = {
|
| |
+ 'action': 'unretirement',
|
| |
+ 'name': 'testpkg',
|
| |
+ 'type': 'rpms',
|
| |
+ 'branches': ['f40'],
|
| |
+ 'review_bugzilla': None,
|
| |
+ 'maintainer': 'root',
|
| |
+ }
|
| |
+
|
| |
+ post_data = mock_request_post.call_args_list[0][1]['data']
|
| |
+ actual_issue_content = json.loads(json.loads(
|
| |
+ post_data)['issue_content'].strip('```'))
|
| |
+ self.assertEqual(expected_issue_content, actual_issue_content)
|
| |
+ output = sys.stdout.getvalue().strip()
|
| |
+ expected_output = ('https://pagure.stg.example.com/releng/'
|
| |
+ 'fedora-scm-requests/issue/41')
|
| |
+ self.assertEqual(output, expected_output)
|
| |
+
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement_not_release_branch(self, mock_request_post, mock_grb):
|
| |
+ """Tests request-unretirement command on branch that is not a release branch."""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ expected_error = (
|
| |
+ "All requested branches {0} are not release branches. So there is nothing to unretire."
|
| |
+ .format(['f15']))
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f15'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement']
|
| |
+
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ try:
|
| |
+ cli.request_unretirement()
|
| |
+ assert False, 'rpkgError not raised'
|
| |
+ except rpkgError as error:
|
| |
+ self.assertEqual(str(error), expected_error)
|
| |
+
|
| |
+ @patch("fedpkg.cli.get_last_commit_date")
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement_bugzilla_needed_but_not_provided(
|
| |
+ self, mock_request_post, mock_grb, mock_gcd
|
| |
+ ):
|
| |
+ """Tests request-unretirement that require to check bugzilla, but bug id wasn't provided"""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ commit_time = arrow.now().shift(days=-57).timestamp()
|
| |
+ mock_gcd.return_value = commit_time
|
| |
+
|
| |
+ expected_error = (
|
| |
+ "Bugzilla url should be provided, "
|
| |
+ "because last commit was made more than 8 weeks ago."
|
| |
+ )
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f40'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement']
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+
|
| |
+ try:
|
| |
+ cli.request_unretirement()
|
| |
+ assert False, 'rpkgError not raised'
|
| |
+ except rpkgError as error:
|
| |
+ self.assertEqual(str(error), expected_error)
|
| |
+
|
| |
+ @patch("fedpkg.bugzilla.BugzillaClient.get_review_bug")
|
| |
+ @patch("fedpkg.cli.get_last_commit_date")
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement_bz_id_provided(
|
| |
+ self, mock_request_post, mock_grb, mock_gcd, mock_bz_grb
|
| |
+ ):
|
| |
+ """Tests request-unretirement command when bz_id provided"""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ commit_time = arrow.now().shift(days=-57).timestamp()
|
| |
+ mock_gcd.return_value = commit_time
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f40'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = [
|
| |
+ 'fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement',
|
| |
+ '--bz_bug_id', '1234567']
|
| |
+
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ cli.request_unretirement()
|
| |
+
|
| |
+ expected_issue_content = {
|
| |
+ 'action': 'unretirement',
|
| |
+ 'name': 'testpkg',
|
| |
+ 'type': 'rpms',
|
| |
+ 'branches': ['f40'],
|
| |
+ 'review_bugzilla': '1234567',
|
| |
+ 'maintainer': 'root',
|
| |
+ }
|
| |
+
|
| |
+ post_data = mock_request_post.call_args_list[0][1]['data']
|
| |
+ actual_issue_content = json.loads(json.loads(
|
| |
+ post_data)['issue_content'].strip('```'))
|
| |
+ self.assertEqual(expected_issue_content, actual_issue_content)
|
| |
+ output = sys.stdout.getvalue().strip()
|
| |
+ expected_output = ('https://pagure.stg.example.com/releng/'
|
| |
+ 'fedora-scm-requests/issue/41')
|
| |
+ self.assertEqual(output, expected_output)
|
| |
+
|
| |
+ @patch("fedpkg.bugzilla.BugzillaClient.get_review_bug")
|
| |
+ @patch("fedpkg.cli.get_last_commit_date")
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement_bz_url_provided(
|
| |
+ self, mock_request_post, mock_grb, mock_gcd, mock_bz_grb
|
| |
+ ):
|
| |
+ """Tests request-unretirement command when bz url provided"""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ commit_time = arrow.now().shift(days=-57).timestamp()
|
| |
+ mock_gcd.return_value = commit_time
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f40'], cwd=self.cloned_repo_path)
|
| |
+
|
| |
+ cli_cmd = [
|
| |
+ 'fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement',
|
| |
+ '--bz_bug_id', 'https://bugzilla.redhat.com/show_bug.cgi?id=1234567']
|
| |
+
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ cli.request_unretirement()
|
| |
+
|
| |
+ expected_issue_content = {
|
| |
+ 'action': 'unretirement',
|
| |
+ 'name': 'testpkg',
|
| |
+ 'type': 'rpms',
|
| |
+ 'branches': ['f40'],
|
| |
+ 'review_bugzilla': '1234567',
|
| |
+ 'maintainer': 'root',
|
| |
+ }
|
| |
+
|
| |
+ post_data = mock_request_post.call_args_list[0][1]['data']
|
| |
+ actual_issue_content = json.loads(json.loads(
|
| |
+ post_data)['issue_content'].strip('```'))
|
| |
+ self.assertEqual(expected_issue_content, actual_issue_content)
|
| |
+ output = sys.stdout.getvalue().strip()
|
| |
+ expected_output = ('https://pagure.stg.example.com/releng/'
|
| |
+ 'fedora-scm-requests/issue/41')
|
| |
+ self.assertEqual(output, expected_output)
|
| |
+
|
| |
+ @patch("fedpkg.cli.get_last_commit_date")
|
| |
+ @patch("fedpkg.cli.get_release_branches")
|
| |
+ @patch("requests.post")
|
| |
+ @patch('sys.stdout', new=io.StringIO())
|
| |
+ def test_request_unretirement_repo_name_provided(
|
| |
+ self, mock_request_post, mock_grb, mock_gcd
|
| |
+ ):
|
| |
+ """Tests request-unretirement command."""
|
| |
+ mock_grb.return_value = {
|
| |
+ 'fedora': ['f39', 'f40', 'f41'],
|
| |
+ 'epel': ['epel9', 'epel10'],
|
| |
+ }
|
| |
+
|
| |
+ mock_rv = Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {'issue': {'id': 41}}
|
| |
+ mock_request_post.return_value = mock_rv
|
| |
+
|
| |
+ commit_time = arrow.now().shift(days=-1).timestamp()
|
| |
+ mock_gcd.return_value = commit_time
|
| |
+
|
| |
+ self.run_cmd(['git', 'checkout', '-b', 'f40'], cwd=self.cloned_repo_path)
|
| |
+ cli_cmd = [
|
| |
+ 'fedpkg-stage', '--path', self.cloned_repo_path, 'request-unretirement',
|
| |
+ '--repo', 'belusha'
|
| |
+ ]
|
| |
+ cli = self.get_cli(cli_cmd)
|
| |
+ cli.request_unretirement()
|
| |
+
|
| |
+ expected_issue_content = {
|
| |
+ 'action': 'unretirement',
|
| |
+ 'name': 'belusha',
|
| |
+ 'type': 'rpms',
|
| |
+ 'branches': ['f40'],
|
| |
+ 'review_bugzilla': None,
|
| |
+ 'maintainer': 'root',
|
| |
+ }
|
| |
+
|
| |
+ post_data = mock_request_post.call_args_list[0][1]['data']
|
| |
+ actual_issue_content = json.loads(json.loads(
|
| |
+ post_data)['issue_content'].strip('```'))
|
| |
+ self.assertEqual(expected_issue_content, actual_issue_content)
|
| |
+ output = sys.stdout.getvalue().strip()
|
| |
+ expected_output = ('https://pagure.stg.example.com/releng/'
|
| |
+ 'fedora-scm-requests/issue/41')
|
| |
+ self.assertEqual(output, expected_output)
|
| |
This command will insure that the user filled all necessary information and will open a ticket with unretirement requests.
Signed-off-by: amedvede amedvede@redhat.com