| |
@@ -14,6 +14,9 @@
|
| |
import os
|
| |
import sys
|
| |
import json
|
| |
+ import pkg_resources
|
| |
+ import unittest
|
| |
+
|
| |
from datetime import datetime, timedelta
|
| |
from tempfile import mkdtemp
|
| |
from os import rmdir
|
| |
@@ -26,6 +29,7 @@
|
| |
from pyrpkg.errors import rpkgError
|
| |
from utils import CliTestCase
|
| |
from fedpkg.bugzilla import BugzillaClient
|
| |
+ from fedpkg.cli import check_bodhi_version
|
| |
|
| |
from mock import call, patch, PropertyMock, Mock
|
| |
|
| |
@@ -45,10 +49,8 @@
|
| |
self.mock_run_command = self.run_command_patcher.start()
|
| |
|
| |
# Let's always use the bodhi 2 command line to test here
|
| |
- self.get_bodhi_major_version_patcher = patch(
|
| |
- 'fedpkg._get_bodhi_major_version', return_value=2)
|
| |
- self.mock_get_bodhi_major_version = \
|
| |
- self.get_bodhi_major_version_patcher.start()
|
| |
+ self.check_bodhi_version_patcher = patch('fedpkg.cli.check_bodhi_version')
|
| |
+ self.mock_check_bodhi_version = self.check_bodhi_version_patcher.start()
|
| |
|
| |
# Not write clog actually. Instead, file object will be mocked and
|
| |
# return fake clog content for tests.
|
| |
@@ -74,7 +76,7 @@
|
| |
os.unlink(os.path.join(self.cloned_repo_path, 'clog'))
|
| |
self.os_environ_patcher.stop()
|
| |
self.clog_patcher.stop()
|
| |
- self.get_bodhi_major_version_patcher.stop()
|
| |
+ self.check_bodhi_version_patcher.stop()
|
| |
self.run_command_patcher.stop()
|
| |
self.nvr_patcher.stop()
|
| |
super(TestUpdate, self).tearDown()
|
| |
@@ -168,28 +170,10 @@
|
| |
@patch('os.path.isfile', return_value=True)
|
| |
@patch('hashlib.new')
|
| |
@patch('fedpkg.lookaside.FedoraLookasideCache.hash_file')
|
| |
- def test_fail_if_bodhi_version_is_not_supported(
|
| |
- self, hash_file, hashlib_new, isfile):
|
| |
- # As of writing this test, only supports version v3, v2, and <v2.
|
| |
- self.mock_get_bodhi_major_version.return_value = 4
|
| |
- hashlib_new.return_value.hexdigest.return_value = 'origin hash'
|
| |
- hash_file.return_value = 'different hash'
|
| |
-
|
| |
- cli_cmd = ['fedpkg', '--path', self.cloned_repo_path, 'update']
|
| |
-
|
| |
- cli = self.get_cli(cli_cmd)
|
| |
- six.assertRaisesRegex(
|
| |
- self, rpkgError, 'This system has bodhi v4, which is unsupported',
|
| |
- self.assert_bodhi_update, cli)
|
| |
-
|
| |
- @patch('os.path.isfile', return_value=True)
|
| |
- @patch('hashlib.new')
|
| |
- @patch('fedpkg.lookaside.FedoraLookasideCache.hash_file')
|
| |
@patch('fedpkg.Commands.user', new_callable=PropertyMock)
|
| |
def test_create_update_in_stage_bodhi(
|
| |
self, user, hash_file, hashlib_new, isfile):
|
| |
user.return_value = 'someone'
|
| |
- self.mock_get_bodhi_major_version.return_value = 2
|
| |
hashlib_new.return_value.hexdigest.return_value = 'origin hash'
|
| |
hash_file.return_value = 'different hash'
|
| |
|
| |
@@ -1126,3 +1110,15 @@
|
| |
assert False, 'rpkgError not raised'
|
| |
except rpkgError as error:
|
| |
self.assertEqual(str(error), expected_error)
|
| |
+
|
| |
+
|
| |
+ class TestCheckBodhiVersion(unittest.TestCase):
|
| |
+ """Test check_bodhi_version"""
|
| |
+
|
| |
+ @patch('pkg_resources.get_distribution')
|
| |
+ def test_no_2_x_version_installed(self, get_distribution):
|
| |
+ get_distribution.side_effect = pkg_resources.DistributionNotFound
|
| |
+
|
| |
+ six.assertRaisesRegex(
|
| |
+ self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
| |
+ check_bodhi_version)
|
| |
Fixes #223
Signed-off-by: Chenxiong Qi cqi@redhat.com