diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000000..ad1de03b56 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,51 @@ +name: pytest + +on: + pull_request: + workflow_dispatch: + +jobs: + pytest: + name: "pytest" + + strategy: + fail-fast: false + matrix: + include: + - name: "CentOS Stream 9" + image: "quay.io/centos/centos:stream9" + pytest_args: '--deselect test/rhsmlib_test/test_hwprobe.py::HardwareProbeTest::test_networkinfo --deselect test/rhsmlib_test/test_facts.py::TestFactsDBusObject::test_GetFacts' + # The 'test_networkinfo' breaks in CentOS container because it has IPv6 disabled. + # Because of a bug in Python, collecting 'socket.AF_INET6' via 'socket.getaddrinfo()' causes + # segfaults instead of exceptions. This deselect is a workaround until it is fixed or until + # we switch to a different way of collecting network facts. + # 'test_GetFacts' triggers full fact collection and causes the same error. + - name: "CentOS Stream 8" + image: "quay.io/centos/centos:stream8" + pytest_args: '' + - name: "Fedora latest" + image: "fedora:latest" + pytest_args: '' + - name: "Fedora Rawhide" + image: "fedora:rawhide" + pytest_args: '' + + runs-on: ubuntu-latest + container: + image: ${{ matrix.image }} + + steps: + - name: "Checkout repository" + uses: actions/checkout@v3 + + - name: "Run container-pre-test.sh" + run: | + bash scripts/container-pre-test.sh + + - name: "Run pytest" + env: + SUBMAN_TEST_IN_CONTAINER: "1" + PYTEST_ADDOPTS: "--color=yes --code-highlight=yes --showlocals" + run: | + dbus-run-session \ + python3 -m pytest ${{ matrix.pytest_args }} diff --git a/TESTING.md b/TESTING.md index 7dc336362f..c73b2e8002 100644 --- a/TESTING.md +++ b/TESTING.md @@ -67,6 +67,33 @@ coverage html coverage xml ``` +## Containers + +You can use Podman to run the test suite, ensuring your local setup does not differ from CI. + +First, pick which container you'll want to use: CentOS Stream 8 (not supported by the main branch anymore), CentOS Stream 9, Fedora latest, Fedora Rawhide, ...: + +```bash +IMAGE="quay.io/centos/centos:stream8" +IMAGE="quay.io/centos/centos:stream9" +IMAGE="registry.fedoraproject.org/fedora:latest" +IMAGE="registry.fedoraproject.org/fedora:rawhide" +``` + +Enter the container (assuming you are in the project root) and run a pre-test script that will set install the dependencies and compile C extensions: + +```bash +podman run -it --rm --name subscription-manager -v .:/subscription-manager --privileged $IMAGE bash +cd /subscription-manager/ +bash scripts/container-pre-test.sh +``` + +Then you can run the test suite. You have to use `dbus-run-session` wrapper, because D-Bus is not running in containers: + +```bash +SUBMAN_TEST_IN_CONTAINER=1 dbus-run-session python3 -m pytest +``` + --- Following text may not be up to date. diff --git a/pytest.ini b/pytest.ini index 2f0e3c0efa..c068e35245 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,8 +2,6 @@ addopts = # Non-registered markers raise errors --strict-markers - # Start with tests that failed last time, --ff - --failed-first # Show extra summary for (f)ailed, (E)rror, (s)kipped and (w)arnings -rfEsw # Mark some tests not to be run diff --git a/scripts/container-pre-test.sh b/scripts/container-pre-test.sh new file mode 100644 index 0000000000..1b4dd44dfd --- /dev/null +++ b/scripts/container-pre-test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +source /etc/os-release +# These repositories are required for the 'libdnf-devel' package. +# Fedora has it available out of the box. +# RHEL needs it to be enabled via 'subscription-manager repos'. +if [[ $ID == "centos" ]]; then + dnf --setopt install_weak_deps=False install -y dnf-plugins-core + if [[ $VERSION == "8" ]]; then + dnf config-manager --set-enabled powertools + fi + if [[ $VERSION == "9" ]]; then + dnf config-manager --enable crb + fi +fi + +# Install essential packages +dnf --setopt install_weak_deps=False install -y \ + git gcc cmake python3 python3-devel python3-pip + +# Install system, build and runtime packages +dnf --setopt install_weak_deps=False install -y \ + intltool dbus-daemon dbus-devel \ + python3-setuptools \ + openssl-devel glib2-devel libdnf-devel \ + python3-rpm python3-librepo python3-gobject python3-gobject python3-dbus \ + python3-dateutil python3-requests python3-iniparse python3-ethtool \ + glibc-langpack-en glibc-langpack-de glibc-langpack-ja + +# Install branch specific packages +dnf --setopt instal_week_deps=False install -y \ + gtk3-devel + +# Install test packages +python3 -m pip install --upgrade pip wheel +python3 -m pip install -r test-requirements.txt + +# Build the project +python3 setup.py build +python3 setup.py build_ext --inplace diff --git a/src/rhsm/utils.py b/src/rhsm/utils.py index 92c7dbf313..038a164261 100644 --- a/src/rhsm/utils.py +++ b/src/rhsm/utils.py @@ -67,29 +67,6 @@ class UnsupportedOperationException(Exception): pass -def which(program): - """ - Function returning path of program (it could be path to executable file or command) - :param program: string with command - :return: Path to command, when some executable exists in system. Otherwise it returns None. - """ - - def is_exe(_fpath): - return os.path.isfile(_fpath) and os.access(_fpath, os.X_OK) - - fpath, fname = os.path.split(program) - if fpath: - if is_exe(program): - return program - else: - for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return exe_file - - return None - - def has_bad_scheme(url): """Check a url for an invalid or unuseful schema. diff --git a/src/rhsmlib/facts/kpatch.py b/src/rhsmlib/facts/kpatch.py index d325b486e3..007e4d3bbe 100644 --- a/src/rhsmlib/facts/kpatch.py +++ b/src/rhsmlib/facts/kpatch.py @@ -19,9 +19,9 @@ import logging import os +import shutil from rhsmlib.facts import collector -from rhsm.utils import which log = logging.getLogger(__name__) @@ -62,7 +62,7 @@ def _is_kpatch_installed(): Check if kpatch is installed :return: Return true, when kpatch CLI tool is installed. Otherwise return False """ - return which('kpatch') is not None + return shutil.which('kpatch') is not None def _get_installed_live_kernel_patches(self): """ diff --git a/src/subscription_manager/repolib.py b/src/subscription_manager/repolib.py index 6a0df6314b..103517db4d 100644 --- a/src/subscription_manager/repolib.py +++ b/src/subscription_manager/repolib.py @@ -30,7 +30,7 @@ from subscription_manager.repofile import YumRepoFile from subscription_manager.utils import get_supported_resources -from rhsm.config import get_config_parser, in_container +import rhsm.config import six from six.moves import configparser @@ -43,7 +43,7 @@ log = logging.getLogger(__name__) -conf = config.Config(get_config_parser()) +conf = config.Config(rhsm.config.get_config_parser()) ALLOWED_CONTENT_TYPES = ["yum", "deb"] @@ -295,7 +295,7 @@ def get_expansion(self): # same consumer as the host they run on. They only have the same # access to content as the host they run on.) result = None - if not in_container(): + if not rhsm.config.in_container(): uep = self.cp_provider.get_consumer_auth_cp() result = self.release_status_cache.read_status(uep, self.identity.uuid) diff --git a/test-requirements.txt b/test-requirements.txt index fe6943aed9..064d73d608 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,7 @@ -e ./syspurpose flake8<4 -pytest +pytest<7 pytest-randomly pytest-timeout pytest-forked diff --git a/test/fixture.py b/test/fixture.py index 3b7ceab066..6e8f713776 100644 --- a/test/fixture.py +++ b/test/fixture.py @@ -194,7 +194,7 @@ def unstub_conf(): subscription_manager.managercli.conf = config.Config(self.mock_cfg_parser) self.addCleanup(unstub_conf) - facts_host_patcher = patch('rhsmlib.dbus.facts.FactsClient', auto_spec=True) + facts_host_patcher = patch('rhsmlib.dbus.facts.FactsClient', autospec=True) self.mock_facts_host = facts_host_patcher.start() self.mock_facts_host.return_value.GetFacts.return_value = self.set_facts() @@ -280,6 +280,13 @@ def unstub_conf(): set_up_mock_sp_store(syncedstore_mock) + # Do not read system files. Even if the tests run in container environment, + # report that we are running on bare metal. + self.in_container_patcher = patch("rhsm.config.in_container") + in_container_mock = self.in_container_patcher.start() + in_container_mock.return_value = False + self.addCleanup(self.in_container_patcher.stop) + self.files_to_cleanup = [] def tearDown(self): diff --git a/test/rhsm/functional/test_connection.py b/test/rhsm/functional/test_connection.py index a2d6e7f656..76bc1eec09 100644 --- a/test/rhsm/functional/test_connection.py +++ b/test/rhsm/functional/test_connection.py @@ -210,7 +210,7 @@ def setUp(self): @patch.object(Restlib, 'validateResponse') @patch('rhsm.connection.drift_check', return_value=False) - @patch('httplib.HTTPSConnection', auto_spec=True) + @patch('httplib.HTTPSConnection', autospec=True) def test_bind_no_args(self, mock_conn, mock_drift, mock_validate): self.cp.bind(self.consumer_uuid) @@ -225,7 +225,7 @@ def test_bind_no_args(self, mock_conn, mock_drift, mock_validate): @patch.object(Restlib, 'validateResponse') @patch('rhsm.connection.drift_check', return_value=False) - @patch('httplib.HTTPSConnection', auto_spec=True) + @patch('httplib.HTTPSConnection', autospec=True) def test_bind_by_pool(self, mock_conn, mock_drift, mock_validate): # this test is just to verify we make the httplib connection with # right args, we don't validate the bind here diff --git a/test/rhsm/unit/test_util.py b/test/rhsm/unit/test_util.py index 6bf5722f35..bfe243c331 100644 --- a/test/rhsm/unit/test_util.py +++ b/test/rhsm/unit/test_util.py @@ -7,7 +7,7 @@ ServerUrlParseErrorEmpty, ServerUrlParseErrorNone, \ ServerUrlParseErrorPort, ServerUrlParseErrorScheme, \ ServerUrlParseErrorJustScheme, has_bad_scheme, has_good_scheme, \ - parse_url, cmd_name, which + parse_url, cmd_name from rhsm.config import DEFAULT_PORT, DEFAULT_PREFIX, DEFAULT_HOSTNAME @@ -417,23 +417,3 @@ def test_rhsm_debug(self): def test_virt_who(self): argv = ['/usr/share/virt-who/virtwho.py'] self.assertEqual("virtwho.py", cmd_name(argv)) - - -class TestWhich(unittest.TestCase): - def test_which_python(self): - """Some python command just has to exist :-)""" - cmd_path = which('python') - self.assertIsNotNone(cmd_path) - - def test_which_bin_sh(self): - """Assumed that Linux is used and some /bin/sh exist""" - cmd_path = which('/bin/sh') - self.assertIsNotNone(cmd_path) - - def test_which_not_existing_command(self): - cmd_path = which('not-existing-command') - self.assertIsNone(cmd_path) - - def test_which_not_existing_command_path(self): - cmd_path = which('/not/existing/command/path/not-existing-command') - self.assertIsNone(cmd_path) diff --git a/test/rhsmlib_test/test_attach.py b/test/rhsmlib_test/test_attach.py index fa01502411..b2f0c1b2e2 100644 --- a/test/rhsmlib_test/test_attach.py +++ b/test/rhsmlib_test/test_attach.py @@ -164,32 +164,28 @@ class TestAttachDBusObject(DBusServerStubProvider): dbus_class = AttachDBusObject dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: + def setUp(self) -> None: is_simple_content_access_patch = mock.patch( "rhsmlib.dbus.objects.attach.is_simple_content_access", name="is_simple_content_access", ) - cls.patches["is_simple_content_access"] = is_simple_content_access_patch.start() - cls.addClassCleanup(is_simple_content_access_patch.stop) + self.patches["is_simple_content_access"] = is_simple_content_access_patch.start() + self.addCleanup(is_simple_content_access_patch.stop) is_registered_patch = mock.patch( "rhsmlib.dbus.base_object.BaseObject.is_registered", name="is_registered", ) - cls.patches["is_registered"] = is_registered_patch.start() - cls.addClassCleanup(is_registered_patch.stop) + self.patches["is_registered"] = is_registered_patch.start() + self.addCleanup(is_registered_patch.stop) update_patch = mock.patch( "subscription_manager.certlib.BaseActionInvoker.update", name="update", ) - cls.patches["update"] = update_patch.start() - cls.addClassCleanup(update_patch.stop) - - super().setUpClass() + self.patches["update"] = update_patch.start() + self.addCleanup(update_patch.stop) - def setUp(self) -> None: self.patches["is_simple_content_access"].return_value = False self.patches["is_registered"].return_value = True self.patches["update"].return_value = None diff --git a/test/rhsmlib_test/test_collector.py b/test/rhsmlib_test/test_collector.py index 2583e2a5c6..41c07f38d1 100644 --- a/test/rhsmlib_test/test_collector.py +++ b/test/rhsmlib_test/test_collector.py @@ -58,9 +58,8 @@ def test_get_aarch64_uuid_collection(self): result = firmware_provider_class.get_all() self.assertTrue(result['dmi.system.uuid'] == '356B6CCC-30C4-11B2-A85C-BBB0CCD29F36') + @mock.patch(OPEN_FUNCTION, mock.MagicMock(side_effect=IOError())) def test_get_aarch64_uuid_collection_no_file(self): - mock.mock_open(read_data="no file") - mock.mock_open.side_effect = IOError() firmware_provider_class = firmware_info.get_firmware_collector(arch='aarch64') firmware_provider_class.arch = 'aarch64' result = firmware_provider_class.get_all() diff --git a/test/rhsmlib_test/test_consumer.py b/test/rhsmlib_test/test_consumer.py index b26dfef63d..696f61c925 100644 --- a/test/rhsmlib_test/test_consumer.py +++ b/test/rhsmlib_test/test_consumer.py @@ -60,16 +60,15 @@ class TestConsumerDbusObject(DBusServerStubProvider): dbus_class = ConsumerDBusObject dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: + def setUp(self) -> None: get_consumer_uuid_patch = mock.patch( "rhsmlib.dbus.objects.consumer.Consumer.get_consumer_uuid", name="get_consumer_uuid", ) - cls.patches["get_consumer_uuid"] = get_consumer_uuid_patch.start() - cls.addClassCleanup(get_consumer_uuid_patch) + self.patches["get_consumer_uuid"] = get_consumer_uuid_patch.start() + self.addCleanup(get_consumer_uuid_patch.stop) - super().setUpClass() + super().setUp() def test_GetUuid(self): self.patches["get_consumer_uuid"].return_value = "fake-uuid" diff --git a/test/rhsmlib_test/test_facts.py b/test/rhsmlib_test/test_facts.py index 829fcfe369..7222a050e0 100644 --- a/test/rhsmlib_test/test_facts.py +++ b/test/rhsmlib_test/test_facts.py @@ -23,19 +23,14 @@ class TestFactsDBusObject(DBusServerStubProvider): dbus_class = AllFacts dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: - # Do not try to use system virt-what + def setUp(self) -> None: get_virt_info_patch = mock.patch( "rhsmlib.facts.virt.VirtWhatCollector.get_virt_info", name="get_virt_info", ) - cls.patches["get_virt_info"] = get_virt_info_patch.start() - cls.addClassCleanup(get_virt_info_patch.stop) - - super().setUpClass() + self.patches["get_virt_info"] = get_virt_info_patch.start() + self.addCleanup(get_virt_info_patch.stop) - def setUp(self) -> None: self.patches["get_virt_info"].return_value = {"virt.is_guest": "Unknown"} super().setUp() diff --git a/test/rhsmlib_test/test_file_monitor.py b/test/rhsmlib_test/test_file_monitor.py index dad47bcdb1..1dc5ad4106 100644 --- a/test/rhsmlib_test/test_file_monitor.py +++ b/test/rhsmlib_test/test_file_monitor.py @@ -12,14 +12,18 @@ # Red Hat trademarks are not licensed under GPLv2. No permission is # granted to use or replicate Red Hat trademarks that are incorporated # in this software or its documentation. +import subprocess +import tempfile +import time +import os +from threading import Thread +import configparser from rhsmlib import file_monitor -from six.moves import configparser -from mock import Mock, patch + +from unittest.mock import Mock, patch + from test import fixture -from threading import Thread -import subprocess -import tempfile class TestFilesystemWatcher(fixture.SubManFixture): @@ -37,6 +41,9 @@ def setUp(self): self.fsw1 = file_monitor.FilesystemWatcher(self.dir_list) self.fsw2 = file_monitor.InotifyFilesystemWatcher(self.dir_list) + now: float = time.time() + self.future = now + 120.0 + def tearDown(self): super(TestFilesystemWatcher, self).tearDown() @@ -101,18 +108,18 @@ def test_polling_stop_value_change(self): def test_polling_changed_dw_set_2_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath1, shell=True) - subprocess.call("touch %s -m" % self.testpath2, shell=True) + os.utime(self.testpath1, (self.future, self.future)) + os.utime(self.testpath2, (self.future, self.future)) self.assertEqual(self.fsw1.changed_dw_set(), {self.dw1, self.dw2, self.dw3}) def test_polling_changed_dw_set_first_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath1, shell=True) + os.utime(self.testpath1, (self.future, self.future)) self.assertEqual(self.fsw1.changed_dw_set(), {self.dw1}) def test_polling_changed_dw_set_second_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath2, shell=True) + os.utime(self.testpath2, (self.future, self.future)) self.assertEqual(self.fsw1.changed_dw_set(), {self.dw2, self.dw3}) def test_polling_changed_dw_set_0_modified(self): @@ -121,18 +128,18 @@ def test_polling_changed_dw_set_0_modified(self): def test_polling_update_2_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath1, shell=True) - subprocess.call("touch %s -m" % self.testpath2, shell=True) + os.utime(self.testpath1, (self.future, self.future)) + os.utime(self.testpath2, (self.future, self.future)) self.assertEqual(self.fsw1.update(), {self.dw1, self.dw2, self.dw3}) def test_polling_update_first_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath1, shell=True) + os.utime(self.testpath1, (self.future, self.future)) self.assertEqual(self.fsw1.update(), {self.dw1}) def test_polling_update_second_modified(self): self.fsw1.changed_dw_set() - subprocess.call("touch %s -m" % self.testpath2, shell=True) + os.utime(self.testpath2, (self.future, self.future)) self.assertEqual(self.fsw1.update(), {self.dw2, self.dw3}) def test_polling_update_0_modified(self): diff --git a/test/rhsmlib_test/test_kpatch.py b/test/rhsmlib_test/test_kpatch.py index f5f53a2d9d..45ebb3d31e 100644 --- a/test/rhsmlib_test/test_kpatch.py +++ b/test/rhsmlib_test/test_kpatch.py @@ -43,14 +43,14 @@ def tearDown(self): shutil.rmtree(self.DIRS_WITH_LOADED_MODULE[1]) shutil.rmtree(self.DIR_WITH_INSTALLED_KPATCH_MODULES) - @patch('rhsmlib.facts.kpatch.which') + @patch('shutil.which') def test_kpatch_is_not_installed(self, which): which.return_value = None collector = kpatch.KPatchCollector() kpatch_facts = collector.get_all() self.assertEqual(kpatch_facts, {}) - @patch('rhsmlib.facts.kpatch.which') + @patch('shutil.which') def test_get_kpatch_facts(self, which): which.return_value = '/usr/sbin/kpatch' collector = kpatch.KPatchCollector() diff --git a/test/rhsmlib_test/test_products.py b/test/rhsmlib_test/test_products.py index 84c37aedac..0bc9ee77a4 100644 --- a/test/rhsmlib_test/test_products.py +++ b/test/rhsmlib_test/test_products.py @@ -316,16 +316,15 @@ class TestProductsDBusObject(DBusServerStubProvider): dbus_class = ProductsDBusObject dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: + def setUp(self) -> None: list_patch = mock.patch( "rhsmlib.dbus.objects.products.InstalledProducts.list", name="list", ) - cls.patches["list"] = list_patch.start() - cls.addClassCleanup(list_patch.stop) + self.patches["list"] = list_patch.start() + self.addCleanup(list_patch.stop) - super().setUpClass() + super().setUp() def test_ListInstalledProducts__no_filter(self): expected = [ diff --git a/test/rhsmlib_test/test_register.py b/test/rhsmlib_test/test_register.py index c51b0e78ba..51cfd702a4 100644 --- a/test/rhsmlib_test/test_register.py +++ b/test/rhsmlib_test/test_register.py @@ -800,53 +800,49 @@ class DomainSocketRegisterDBusObjectTest(DBusServerStubProvider): dbus_class = DomainSocketRegisterDBusObject dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: + def setUp(self) -> None: register_patch = mock.patch( "rhsmlib.dbus.objects.register.RegisterService.register", name="register", ) - cls.patches["register"] = register_patch.start() - cls.addClassCleanup(register_patch.stop) + self.patches["register"] = register_patch.start() + self.addCleanup(register_patch.stop) unregister_patch = mock.patch( "rhsmlib.services.unregister.UnregisterService.unregister", name="unregister", ) - cls.patches["unregister"] = unregister_patch.start() - cls.addClassCleanup(unregister_patch.stop) + self.patches["unregister"] = unregister_patch.start() + self.addCleanup(unregister_patch.stop) is_registered_patch = mock.patch( "rhsmlib.dbus.base_object.BaseObject.is_registered", name="is_registered", ) - cls.patches["is_registered"] = is_registered_patch.start() - cls.addClassCleanup(is_registered_patch.stop) + self.patches["is_registered"] = is_registered_patch.start() + self.addCleanup(is_registered_patch.stop) update_patch = mock.patch( "rhsmlib.dbus.objects.register.EntCertActionInvoker.update", name="update", ) - cls.patches["update"] = update_patch.start() - cls.addClassCleanup(update_patch.stop) + self.patches["update"] = update_patch.start() + self.addCleanup(update_patch.stop) attach_auto_patch = mock.patch( "rhsmlib.dbus.objects.register.AttachService.attach_auto", name="attach_auto", ) - cls.patches["attach_auto"] = attach_auto_patch.start() - cls.addClassCleanup(attach_auto_patch.stop) + self.patches["attach_auto"] = attach_auto_patch.start() + self.addCleanup(attach_auto_patch.stop) build_uep_patch = mock.patch( "rhsmlib.dbus.base_object.BaseObject.build_uep", name="build_uep", ) - cls.patches["build_uep"] = build_uep_patch.start() - cls.addClassCleanup(build_uep_patch.stop) - - super().setUpClass() + self.patches["build_uep"] = build_uep_patch.start() + self.addCleanup(build_uep_patch.stop) - def setUp(self) -> None: self.patches["update"].return_value = None super().setUp() diff --git a/test/rhsmlib_test/test_unregister.py b/test/rhsmlib_test/test_unregister.py index 3557b01ebd..df45356ed8 100644 --- a/test/rhsmlib_test/test_unregister.py +++ b/test/rhsmlib_test/test_unregister.py @@ -60,16 +60,15 @@ class TestUnregisterDBusObject_(DBusServerStubProvider): dbus_class = UnregisterDBusObject dbus_class_kwargs = {} - @classmethod - def setUpClass(cls) -> None: + def setUp(self): is_registered_patch = mock.patch( "rhsmlib.dbus.base_object.BaseObject.is_registered", name="is_registered", ) - cls.patches["is_registered"] = is_registered_patch.start() - cls.addClassCleanup(is_registered_patch.stop) + self.patches["is_registered"] = is_registered_patch.start() + self.addCleanup(is_registered_patch.stop) - super().setUpClass() + super().setUp() def test_Unregister__must_be_registered(self): self.patches["is_registered"].return_value = False diff --git a/test/test_cp_provider.py b/test/test_cp_provider.py index 660ee19a88..ec72f7597e 100644 --- a/test/test_cp_provider.py +++ b/test/test_cp_provider.py @@ -35,6 +35,12 @@ def setUp(self): """ self.cp_provider = CPProvider() + # Do not try to perform TCP/TLS handshake during testing + self.conn_connect_patcher = patch("http.client.HTTPSConnection.connect") + conn_connect_mock = self.conn_connect_patcher.start() + conn_connect_mock.return_value = None + self.addCleanup(self.conn_connect_patcher.stop) + def test_create_cp_provider(self): """ Simple test of creating instance diff --git a/test/test_logutil.py b/test/test_logutil.py index d32645e141..81ada6b2fa 100644 --- a/test/test_logutil.py +++ b/test/test_logutil.py @@ -12,6 +12,8 @@ from rhsm import logutil +import unittest + # no NullHandler in 2.6, include our own class NullHandler(logging.Handler): @@ -197,6 +199,7 @@ def test_missing_user_log_directory(self, MockGetUID): logutil.USER_LOGFILE_DIR = old_dir_path logutil.USER_LOGFILE_PATH = old_file_path + @unittest.skipIf(os.getuid() == 0, "Test cannot be run under root.") @mock.patch("os.getuid") def test_not_possible_to_create_root_log_dir_due_to_access_perm(self, MockGetUID): """ @@ -234,6 +237,7 @@ def test_not_possible_to_create_root_log_dir_due_to_access_perm(self, MockGetUID logutil.LOGFILE_DIR = old_dir_path logutil.LOGFILE_PATH = old_file_path + @unittest.skipIf(os.getuid() == 0, "Test cannot be run under root.") @mock.patch("os.getuid") def test_not_possible_to_create_user_log_dir_due_to_access_perm(self, MockGetUID): """ @@ -271,6 +275,7 @@ def test_not_possible_to_create_user_log_dir_due_to_access_perm(self, MockGetUID logutil.USER_LOGFILE_DIR = old_dir_path logutil.USER_LOGFILE_PATH = old_file_path + @unittest.skipIf(os.getuid() == 0, "Test cannot be run under root.") @mock.patch("os.getuid") def test_wrong_rhsm_log_priv(self, MockGetUID): """ diff --git a/test/test_po_files.py b/test/test_po_files.py index 772263ae2f..e69de29bb2 100644 --- a/test/test_po_files.py +++ b/test/test_po_files.py @@ -1,73 +0,0 @@ -from __future__ import print_function, division, absolute_import - -try: - import unittest2 as unittest -except ImportError: - import unittest - -from . import fixture -import six - -from subscription_manager import managercli -from subscription_manager.printing_utils import to_unicode_or_bust - -import gettext -from subscription_manager import i18n -_ = gettext.translation(i18n.APP, fallback=True).ugettext - - -class TestLocale(unittest.TestCase): - - # see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - # http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5/html/International_Language_Support_Guide/Red_Hat_Enterprise_Linux_International_Language_Support_Guide-Installing_and_supporting_languages.html - test_locales = [ - # as_IN is kind of busted in RHEL6, and seemingly - # very busted in 14 - #"as_IN", # Assamese - "bn_IN", # Bengali - "de_DE", # German - "es_ES", # Spanish - "en_US", # english us - "fr_FR", # French - "gu_IN", # Gujarati - "hi_IN", # Hindi - "it_IT", # Italian - "ja_JP", # Japanese - "kn_IN", # Kannada - "ml_IN", # Malayalam - "mr_IN", # Marathi - "or_IN", # Oriya - "pa_IN", # Punjabi - # "ne_IN", # Nepali - #"se_IN", # Sinhala - #"br_IN", # Maithili - "pt_BR", # Portugese - "ru_RU", # Russian - #"si_LK", # Sri Lankan - "ta_IN", # Tamil - "te_IN", # telgu - "zh_CN", # Chinese Simplified - "zh_TW", # Chinese Traditional - "ko_KR"] # korean - - def test_pos(self): - for lang in self.test_locales: - l = "%s.utf8" % lang - with fixture.locale_context(l): - '%s' % _("Unable to find available subscriptions for all your installed products.") - - -class TestUnicodeGettext(TestLocale): - def test_ja_not_serial(self): - with fixture.locale_context('ja_JP.UTF-8'): - msg = _("'%s' is not a valid serial number") % "123123" - six.text_type(to_unicode_or_bust(msg)) + u'\n' - - def test_system_exit(self): - with fixture.locale_context('ja_JP.UTF-8'): - try: - with fixture.Capture(silent=True): - managercli.system_exit(1, _("'%s' is not a valid serial number") % "123123") - except SystemExit: - # tis okay, we are looking for unicode errors on the string encode - pass