| |
@@ -5,10 +5,12 @@
|
| |
import subprocess
|
| |
import tempfile
|
| |
|
| |
+ import six
|
| |
+ from pyrpkg.errors import rpkgError
|
| |
from six.moves import configparser
|
| |
+ from utils import unittest
|
| |
|
| |
from fedpkg.cli import fedpkgClient
|
| |
- from utils import unittest
|
| |
|
| |
try:
|
| |
from unittest import mock
|
| |
@@ -76,8 +78,14 @@
|
| |
'fedpkg.spec')))
|
| |
self.assertEqual(self._get_latest_commit(), reason)
|
| |
|
| |
+ @mock.patch('requests.post')
|
| |
@mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404))
|
| |
- def test_retire_with_namespace(self):
|
| |
+ def test_retire_with_namespace(self, requests_post):
|
| |
+ mock_rv = mock.Mock()
|
| |
+ mock_rv.ok = True
|
| |
+ mock_rv.json.return_value = {"anitya_status": "no-monitoring"}
|
| |
+ requests_post.return_value = mock_rv
|
| |
+
|
| |
self._setup_repo('ssh://git@pkgs.example.com/rpms/fedpkg')
|
| |
args = ['fedpkg', '--release=rawhide', 'retire', 'my reason']
|
| |
|
| |
@@ -87,8 +95,52 @@
|
| |
self.assertRetired('my reason')
|
| |
self.assertEqual(len(client.cmd.push.call_args_list), 1)
|
| |
|
| |
+ url = 'https://src.example.com/_dg/anitya/rpms/fedpkg'
|
| |
+ data = '{"anitya_status": "no-monitoring"}'
|
| |
+ headers = {
|
| |
+ 'Authorization': 'token notsecretatall',
|
| |
+ 'Accept': 'application/json',
|
| |
+ 'Content-Type': 'application/json'
|
| |
+ }
|
| |
+ requests_post.assert_called_once_with(url, data=data, headers=headers, timeout=90)
|
| |
+
|
| |
+ @mock.patch('requests.post')
|
| |
+ @mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404))
|
| |
+ def test_retire_with_namespace_disable_monitoring_fails(self, requests_post):
|
| |
+ """
|
| |
+ retire operation itself runs fine, but subsequent procedure disable-monitoring fails
|
| |
+ """
|
| |
+ mock_rv = mock.Mock()
|
| |
+ mock_rv.ok = False
|
| |
+ mock_rv.json.return_value = {"error": "Invalid or expired token"}
|
| |
+ requests_post.return_value = mock_rv
|
| |
+
|
| |
+ self._setup_repo('ssh://git@pkgs.example.com/rpms/fedpkg')
|
| |
+ args = ['fedpkg', '--release=rawhide', 'retire', 'my reason']
|
| |
+
|
| |
+ client = self._fake_client(args)
|
| |
+ self.assertRaisesRegex(
|
| |
+ rpkgError,
|
| |
+ "The following error occurred while disabling monitoring: Invalid or expired token\n"
|
| |
+ "For invalid or expired tokens please set a new token",
|
| |
+ client.retire
|
| |
+ )
|
| |
+
|
| |
+ self.assertRetired('my reason')
|
| |
+ self.assertEqual(len(client.cmd.push.call_args_list), 1)
|
| |
+
|
| |
+ url = 'https://src.example.com/_dg/anitya/rpms/fedpkg'
|
| |
+ data = '{"anitya_status": "no-monitoring"}'
|
| |
+ headers = {
|
| |
+ 'Authorization': 'token notsecretatall',
|
| |
+ 'Accept': 'application/json',
|
| |
+ 'Content-Type': 'application/json'
|
| |
+ }
|
| |
+ requests_post.assert_called_once_with(url, data=data, headers=headers, timeout=90)
|
| |
+
|
| |
+ @mock.patch('requests.post')
|
| |
@mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404))
|
| |
- def test_retire_without_namespace(self):
|
| |
+ def test_retire_without_namespace(self, requests_post):
|
| |
self._setup_repo('ssh://git@pkgs.example.com/fedpkg')
|
| |
args = ['fedpkg', '--release=rawhide', 'retire', 'my reason']
|
| |
|
| |
@@ -98,8 +150,9 @@
|
| |
self.assertRetired('my reason')
|
| |
self.assertEqual(len(client.cmd.push.call_args_list), 1)
|
| |
|
| |
+ @mock.patch('requests.post')
|
| |
@mock.patch("requests.get", new=lambda *args, **kwargs: mock.Mock(status_code=404))
|
| |
- def test_package_is_retired_already(self):
|
| |
+ def test_package_is_retired_already(self, requests_post):
|
| |
self._setup_repo('ssh://git@pkgs.example.com/fedpkg')
|
| |
with open(os.path.join(self.tmpdir, 'dead.package'), 'w') as f:
|
| |
f.write('dead package')
|
| |
After the repository is retired, its monitoring needs to be disabled.
Relates: https://pagure.io/releng/issue/10724
JIRA: RHELCMP-11025
Signed-off-by: Ondrej Nosek onosek@redhat.com