| |
@@ -30,67 +30,22 @@
|
| |
class TestUtils(unittest.TestCase):
|
| |
"""Test functions in fedpkg.utils"""
|
| |
|
| |
- @patch('requests.get')
|
| |
- def test_get_sl_type(self, mock_get):
|
| |
- """Test get_sl_type"""
|
| |
- sl_type = {
|
| |
- 'id': 1,
|
| |
- 'name': 'security_fixes',
|
| |
- 'description': 'security_fixes',
|
| |
- }
|
| |
- mock_rv = Mock()
|
| |
- mock_rv.ok = True
|
| |
- mock_rv.json.return_value = {
|
| |
- 'count': 1,
|
| |
- 'results': [sl_type]
|
| |
- }
|
| |
- mock_get.return_value = mock_rv
|
| |
- rv = utils.get_sl_type('http://pdc.local/', 'securty_fixes')
|
| |
- self.assertEqual(rv, sl_type)
|
| |
-
|
| |
- @patch('requests.get')
|
| |
- def test_get_sl_type_pdc_error(self, mock_request_get):
|
| |
- """Test get_sl_type when PDC errors"""
|
| |
- mock_rv = Mock()
|
| |
- mock_rv.ok = False
|
| |
- mock_rv.text = 'Some error'
|
| |
- mock_request_get.return_value = mock_rv
|
| |
- try:
|
| |
- utils.get_sl_type('http://pdc.local/', 'securty_fixes')
|
| |
- assert False, 'rpkgError not raised'
|
| |
- except rpkgError as error:
|
| |
- expected_error = ('The following error occurred while validating '
|
| |
- 'the passed in service level in PDC: Some error')
|
| |
- self.assertEqual(str(error), expected_error)
|
| |
-
|
| |
- @patch('fedpkg.utils.get_sl_type')
|
| |
- def test_verify_sls(self, mock_get_sl_type):
|
| |
+ def test_verify_sls(self):
|
| |
"""Test verify_sls"""
|
| |
- mock_get_sl_type.return_value = {
|
| |
- 'id': 1,
|
| |
- 'name': 'security_fixes',
|
| |
- 'description': 'security_fixes',
|
| |
- }
|
| |
- sls = {'security_fixes': '2222-12-01'}
|
| |
+ sls = {"security_fixes": "2222-12-01"}
|
| |
# If it's invalid, an rpkgError will be raised
|
| |
try:
|
| |
- utils.verify_sls('http://pdc.local/', sls)
|
| |
+ utils.verify_sls(sls)
|
| |
except rpkgError:
|
| |
assert False, 'An rpkgError exception was raised but not expected'
|
| |
|
| |
- @patch('fedpkg.utils.get_sl_type')
|
| |
- def test_verify_sls_eol_expired(self, mock_get_sl_type):
|
| |
+ def test_verify_sls_eol_expired(self):
|
| |
"""Test verify_sls raises an exception when an EOL is expired"""
|
| |
- mock_get_sl_type.return_value = {
|
| |
- 'id': 1,
|
| |
- 'name': 'security_fixes',
|
| |
- 'description': 'security_fixes',
|
| |
- }
|
| |
- sls = {'security_fixes': '2001-12-01'}
|
| |
+ sls = {"security_fixes": "2001-12-01"}
|
| |
|
| |
try:
|
| |
- utils.verify_sls('http://pdc.local/', sls)
|
| |
- assert False, 'An rpkgError exception was not raised'
|
| |
+ utils.verify_sls(sls)
|
| |
+ assert False, "An rpkgError exception was not raised"
|
| |
except rpkgError as e:
|
| |
self.assertEqual(str(e), 'The SL "2001-12-01" is already expired')
|
| |
|
| |
@@ -118,9 +73,9 @@
|
| |
"""
|
| |
for eol in ['2030-01-01', '2030-12-25']:
|
| |
try:
|
| |
- sls = {'security_fixes': eol, 'bug_fixes': eol}
|
| |
- utils.verify_sls('http://pdc.example.com/', sls)
|
| |
- assert False, 'An rpkgError exception was not raised'
|
| |
+ sls = {"security_fixes": eol, "bug_fixes": eol}
|
| |
+ utils.verify_sls(sls)
|
| |
+ assert False, "An rpkgError exception was not raised"
|
| |
except rpkgError as e:
|
| |
assert str(e) == ('The SL "{0}" must expire on June 1st or '
|
| |
'December 1st'.format(eol))
|
| |
@@ -132,29 +87,33 @@
|
| |
"""
|
| |
mock_rv = Mock()
|
| |
mock_rv.ok = True
|
| |
- # This abbreviated data returned from the product-versions PDC API
|
| |
- mock_rv.json.return_value = {
|
| |
- 'count': 7,
|
| |
- 'next': None,
|
| |
- 'previous': None,
|
| |
- 'results': [
|
| |
- {'short': 'epel', 'version': '6'},
|
| |
- {'short': 'epel', 'version': '7'},
|
| |
- {'short': 'fedora', 'version': '25'},
|
| |
- {'short': 'fedora', 'version': '26'},
|
| |
- {'short': 'fedora', 'version': '27'},
|
| |
- {'short': 'fedora', 'version': '28'},
|
| |
- {'short': 'fedora', 'version': 'rawhide'}
|
| |
- ]
|
| |
- }
|
| |
+ # This abbreviated data returned from the Bodhi API active releases
|
| |
+ mock_rv.json.return_value = {'releases': [
|
| |
+ {'name': 'EPEL-7', 'branch': 'epel7'},
|
| |
+ {'name': 'EPEL-8', 'branch': 'epel8'},
|
| |
+ {'name': 'EPEL-8N',
|
| |
+ 'long_name': 'Fedora EPEL 8 Next',
|
| |
+ 'version': '8',
|
| |
+ 'id_prefix': 'FEDORA-EPEL-NEXT',
|
| |
+ 'branch': 'epel8-next'},
|
| |
+ {'name': 'EPEL-9', 'branch': 'epel9'},
|
| |
+ {'name': 'EPEL-9N', 'branch': 'epel9-next'},
|
| |
+ {'name': 'F38', 'branch': 'f38'},
|
| |
+ {'name': 'F38C', 'branch': 'f38'},
|
| |
+ {'name': 'F38F', 'branch': 'f38'},
|
| |
+ {'name': 'F38M', 'branch': 'f38m'},
|
| |
+ {'name': 'F39', 'branch': 'f39'},
|
| |
+ {'name': 'F39C', 'branch': 'f39'},
|
| |
+ {'name': 'F39F', 'branch': 'f39'},
|
| |
+ ], 'page': 1, 'pages': 1, 'rows_per_page': 20, 'total': 12}
|
| |
mock_request_get.return_value = mock_rv
|
| |
- expected = set(['el6', 'epel7', 'f25', 'f26', 'f27', 'f28'])
|
| |
expected = {
|
| |
- 'epel': ['el6', 'epel7'],
|
| |
- 'fedora': ['f25', 'f26', 'f27', 'f28'],
|
| |
+ 'epel': ['epel7', 'epel8', 'epel8-next', 'epel9', 'epel9-next'],
|
| |
+ 'fedora': ['f38', 'f38m', 'f39'],
|
| |
}
|
| |
- actual = utils.get_release_branches('http://pdc.local')
|
| |
- self.assertEqual(expected, actual)
|
| |
+ actual = utils.get_release_branches('http://src.local')
|
| |
+ actual_sorted = {key: sorted(value) for key, value in sorted(actual.items())}
|
| |
+ self.assertDictEqual(expected, actual_sorted)
|
| |
|
| |
|
| |
@patch('requests.get')
|
| |
@@ -207,54 +166,20 @@
|
| |
utils.config_get_safely, config, 'fedpkg.pagure', 'token')
|
| |
|
| |
|
| |
- @patch('requests.get')
|
| |
- class TestGetServiceLevelType(unittest.TestCase):
|
| |
- """Test get_sl_type"""
|
| |
-
|
| |
- def test_raise_error_if_connection_error_to_pdc(self, get):
|
| |
- get.side_effect = ConnectionError
|
| |
-
|
| |
- six.assertRaisesRegex(
|
| |
- self, rpkgError, 'The connection to PDC failed',
|
| |
- utils.get_sl_type, 'http://localhost/', 'bug_fixes:2020-12-01')
|
| |
-
|
| |
- def test_sl_type_not_exist(self, get):
|
| |
- rv = Mock(ok=True)
|
| |
- rv.json.return_value = {'count': 0}
|
| |
- get.return_value = rv
|
| |
-
|
| |
- sl_type = utils.get_sl_type('http://localhost/',
|
| |
- 'bug_fixes:2020-12-01')
|
| |
- self.assertIsNone(sl_type)
|
| |
-
|
| |
- def test_raise_error_if_response_not_ok(self, get):
|
| |
- get.return_value = Mock(ok=False)
|
| |
-
|
| |
- six.assertRaisesRegex(
|
| |
- self, rpkgError, 'The following error occurred',
|
| |
- utils.get_sl_type, 'http://localhost/', 'bug_fixes:2020-12-01')
|
| |
-
|
| |
-
|
| |
class TestVerifySLS(unittest.TestCase):
|
| |
"""Test verify_sls"""
|
| |
|
| |
def test_sl_date_format_is_invalid(self):
|
| |
six.assertRaisesRegex(
|
| |
- self, rpkgError, 'The EOL date .+ is in an invalid format',
|
| |
- utils.verify_sls, 'http://localhost/', {'bug_fixes': '2018/7/21'})
|
| |
-
|
| |
- @freeze_time('2018-01-01')
|
| |
- @patch('requests.get')
|
| |
- def test_sl_not_exist(self, get):
|
| |
- rv = Mock(ok=True)
|
| |
- rv.json.return_value = {'count': 0}
|
| |
-
|
| |
- six.assertRaisesRegex(
|
| |
- self, rpkgError, 'The SL .+ is not in PDC',
|
| |
- utils.verify_sls, 'http://localhost/', {'some_sl': '2018-06-01'})
|
| |
+ self,
|
| |
+ rpkgError,
|
| |
+ "The EOL date .+ is in an invalid format",
|
| |
+ utils.verify_sls,
|
| |
+ {"bug_fixes": "2018/7/21"},
|
| |
+ )
|
| |
|
| |
- @freeze_time('2018-01-01')
|
| |
- @patch('requests.get')
|
| |
+ @freeze_time("2018-01-01")
|
| |
+ @patch("requests.get")
|
| |
def test_keep_quiet_if_service_levels_are_ok(self, get):
|
| |
rv = Mock(ok=True)
|
| |
rv.json.side_effect = [
|
| |
@@ -278,11 +203,8 @@
|
| |
get.return_value = rv
|
| |
|
| |
utils.verify_sls(
|
| |
- 'http://localhost/',
|
| |
- {
|
| |
- 'bug_fixes': '2018-06-01',
|
| |
- 'security_fixes': '2018-12-01'
|
| |
- })
|
| |
+ {"bug_fixes": "2018-06-01", "security_fixes": "2018-12-01"},
|
| |
+ )
|
| |
|
| |
|
| |
@patch('requests.get')
|
| |
@@ -434,22 +356,22 @@
|
| |
)
|
| |
|
| |
|
| |
- @patch('requests.get')
|
| |
- class TestQueryPDC(unittest.TestCase):
|
| |
- """Test utils.query_pdc"""
|
| |
+ @patch("requests.get")
|
| |
+ class TestQueryBodhi(unittest.TestCase):
|
| |
+ """Test utils.query_bodhi"""
|
| |
|
| |
def test_connection_error(self, get):
|
| |
get.side_effect = ConnectionError
|
| |
|
| |
- result = utils.query_pdc('http://localhost/', 'endpoint', {})
|
| |
+ result = utils.query_bodhi('http://localhost/')
|
| |
six.assertRaisesRegex(
|
| |
- self, rpkgError, 'The connection to PDC failed',
|
| |
+ self, rpkgError, 'The connection to BODHI failed',
|
| |
list, result)
|
| |
|
| |
def test_response_not_ok(self, get):
|
| |
get.return_value.ok = False
|
| |
|
| |
- result = utils.query_pdc('http://localhost/', 'endpoint', {})
|
| |
+ result = utils.query_bodhi('http://localhost/')
|
| |
six.assertRaisesRegex(
|
| |
self, rpkgError, 'The following error occurred',
|
| |
list, result)
|
| |
@@ -458,37 +380,44 @@
|
| |
rv = Mock()
|
| |
rv.ok = True
|
| |
rv.json.side_effect = [
|
| |
- {'results': ['item1', 'item2'],
|
| |
- 'next': 'http://localhost/?page=2'},
|
| |
- {'results': ['item3'], 'next': None}
|
| |
+ {'releases': [
|
| |
+ {'name': 'item1', 'branch': 'item2'},
|
| |
+ {'name': 'item5', 'branch': 'item6'},
|
| |
+ {'name': 'item3', 'branch': 'item4'},
|
| |
+ ]}
|
| |
]
|
| |
get.return_value = rv
|
| |
|
| |
- result = utils.query_pdc('http://localhost/', 'endpoint', {})
|
| |
- self.assertEqual(['item1', 'item2', 'item3'], list(result))
|
| |
+ result = utils.query_bodhi('http://localhost/')
|
| |
+ v = next(result)
|
| |
+ self.assertEqual('item2', v)
|
| |
+ v = next(result)
|
| |
+ self.assertEqual('item6', v)
|
| |
+ v = next(result)
|
| |
+ self.assertEqual('item4', v)
|
| |
|
| |
|
| |
class TestGetStreamBranches(unittest.TestCase):
|
| |
"""Test get_stream_branches"""
|
| |
|
| |
+ @patch('fedpkg.utils.get_pagure_branches')
|
| |
@patch('requests.get')
|
| |
- def test_fedora_and_epel_branches_are_filtered_out(self, get):
|
| |
+ def test_fedora_and_epel_branches_are_filtered_out(self, get, pagure_branches):
|
| |
+ logger = Mock()
|
| |
+ apibaseurl = "https://bodhiurl"
|
| |
rv = Mock(ok=True)
|
| |
- rv.json.return_value = {
|
| |
- 'results': [
|
| |
- {'name': '8'},
|
| |
- {'name': '10'},
|
| |
- {'name': 'f28'},
|
| |
- {'name': 'epel7'},
|
| |
- {'name': 'rawhide'},
|
| |
- {'name': 'epel8'},
|
| |
- ],
|
| |
- 'next': None
|
| |
- }
|
| |
+ rv.json.return_value = {'releases': [
|
| |
+ {'name': 'ELN', 'branch': 'eln'},
|
| |
+ {'name': 'F40', 'branch': 'rawhide'},
|
| |
+ {'name': 'F40C', 'branch': 'f40'},
|
| |
+ {'name': 'epel8', 'branch': 'epel8'},
|
| |
+ ], 'page': 1, 'pages': 1, 'rows_per_page': 20, 'total': 3}
|
| |
+ {'releases': [], 'page': 1, 'pages': 0, 'rows_per_page': 20, 'total': 0}
|
| |
get.return_value = rv
|
| |
+ pagure_branches.return_value = ["epel7", "epel8", "epel9", "f38", "f39"]
|
| |
|
| |
- result = utils.get_stream_branches('http://localhost/', 'pkg')
|
| |
- self.assertEqual([{'name': '8'}, {'name': '10'}, {'name': 'epel8'}], list(result))
|
| |
+ result = utils.get_stream_branches('http://localhost/', 'pkg', apibaseurl, logger)
|
| |
+ self.assertEqual(['epel8'], list(result))
|
| |
|
| |
|
| |
class TestExpandRelease(unittest.TestCase):
|
| |
Since PDC is going to be dismissed, we need to redirect all pdc call to other APIs, for example bodhi.
Related to issue #535
Signed-off-by: Lenka Segura lsegura@redhat.com