def test_remove_some_pools_by_id(self):
        """
        Test of removing only some pools, because one pool ID is not valid
        """
        ent_service = EntitlementService(self.mock_cp)

        def stub_unbind(uuid, pool_id):
            if pool_id == 'does_not_exist_d015dea0adf560152':
                raise connection.RestlibException(400, 'Error')

        ent_service.cp.unbindByPoolId = mock.Mock(side_effect=stub_unbind)
        ent_service.entitlement_dir.list_serials_for_pool_ids = mock.Mock(return_value={
            '4028fa7a5dea087d015dea0b025003f6': ['6219625278114868779'],
            '4028fa7a5dea087d015dea0adf560152': ['3573249574655121394']
        })
        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_pools, unremoved_pools, removed_serials = ent_service.remove_entilements_by_pool_ids(
            ['4028fa7a5dea087d015dea0b025003f6', 'does_not_exist_d015dea0adf560152']
        )

        expected_removed_serials = ['6219625278114868779']
        expected_removed_pools = ['4028fa7a5dea087d015dea0b025003f6']
        expected_unremoved_pools = ['does_not_exist_d015dea0adf560152']

        self.assertEqual(expected_removed_serials, removed_serials)
        self.assertEqual(expected_removed_pools, removed_pools)
        self.assertEqual(expected_unremoved_pools, unremoved_pools)
    def test_remove_dupli_pools_by_id(self):
        """
        Test of removing pools specified with duplicities
        (one pool id is set twice)
        """
        ent_service = EntitlementService(self.mock_cp)
        ent_service.cp.unbindByPoolId = mock.Mock()
        ent_service.entitlement_dir.list_serials_for_pool_ids = mock.Mock(return_value={
            '4028fa7a5dea087d015dea0b025003f6': ['6219625278114868779'],
            '4028fa7a5dea087d015dea0adf560152': ['3573249574655121394']
        })
        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_pools, unremoved_pools, removed_serials = ent_service.remove_entilements_by_pool_ids(
            ['4028fa7a5dea087d015dea0b025003f6',
             '4028fa7a5dea087d015dea0b025003f6',
             '4028fa7a5dea087d015dea0adf560152']
        )

        expected_removed_serials = [
            '6219625278114868779',
            '3573249574655121394'
        ]
        expected_removed_pools = [
            '4028fa7a5dea087d015dea0b025003f6',
            '4028fa7a5dea087d015dea0adf560152'
        ]

        self.assertEqual(expected_removed_serials, removed_serials)
        self.assertEqual(expected_removed_pools, removed_pools)
        self.assertEqual([], unremoved_pools)
    def test_remove_all_pools_by_id(self):
        """
        Test of removing all pools by IDs of pool
        """
        ent_service = EntitlementService(self.mock_cp)
        ent_service.cp.unbindByPoolId = mock.Mock()
        ent_service.entitlement_dir.list_serials_for_pool_ids = mock.Mock(
            return_value={
                "4028fa7a5dea087d015dea0b025003f6": ["6219625278114868779"],
                "4028fa7a5dea087d015dea0adf560152": ["3573249574655121394"],
            })
        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_pools, unremoved_pools, removed_serials = ent_service.remove_entilements_by_pool_ids(
            [
                "4028fa7a5dea087d015dea0b025003f6",
                "4028fa7a5dea087d015dea0adf560152"
            ])

        expected_removed_serials = [
            "6219625278114868779", "3573249574655121394"
        ]
        expected_removed_pools = [
            "4028fa7a5dea087d015dea0b025003f6",
            "4028fa7a5dea087d015dea0adf560152"
        ]

        self.assertEqual(expected_removed_serials, removed_serials)
        self.assertEqual(expected_removed_pools, removed_pools)
        self.assertEqual([], unremoved_pools)
示例#4
0
    def RemoveEntitlementsByPoolIds(self,
                                    pool_ids,
                                    proxy_options,
                                    locale,
                                    sender=None):
        """
        Try to remove entitlements (subscriptions) by pool_ids
        :param pool_ids: List of pool IDs
        :param proxy_options: Settings of proxy
        :param locale: String with locale (e.g. de_DE.UTF-8)
        :param sender: Not used argument
        :return: Json string representing list of serial numbers
        """
        pool_ids = dbus_utils.dbus_to_python(pool_ids, expected_type=list)
        proxy_options = dbus_utils.dbus_to_python(proxy_options,
                                                  expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)

        cp = self.build_uep(proxy_options, proxy_only=True)
        entitlement_service = EntitlementService(cp)
        removed_pools, unremoved_pools, removed_serials = entitlement_service.remove_entilements_by_pool_ids(
            pool_ids)

        return json.dumps(removed_serials)
    def RemoveEntitlementsByPoolIds(self, pool_ids, proxy_options, locale, sender=None):
        """
        Try to remove entitlements (subscriptions) by pool_ids
        :param pool_ids: List of pool IDs
        :param proxy_options: Settings of proxy
        :param locale: String with locale (e.g. de_DE.UTF-8)
        :param sender: Not used argument
        :return: Json string representing list of serial numbers
        """
        pool_ids = dbus_utils.dbus_to_python(pool_ids, expected_type=list)
        proxy_options = dbus_utils.dbus_to_python(proxy_options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)

        cp = self.build_uep(proxy_options, proxy_only=True)
        entitlement_service = EntitlementService(cp)
        removed_pools, unremoved_pools, removed_serials = entitlement_service.remove_entilements_by_pool_ids(pool_ids)

        return json.dumps(removed_serials)