def test_remove_some_pools_by_serial(self):
        """
        Test of removing some of pools by serial numbers, because one serial
        number is not valid.
        """
        ent_service = EntitlementService(self.mock_cp)

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

        ent_service.cp.unbindBySerial = mock.Mock(side_effect=stub_unbind)

        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_serial, unremoved_serials = ent_service.remove_entitlements_by_serials(
            ['6219625278114868779',
             'does_not_exist_1394']
        )

        expected_removed_serials = ['6219625278114868779']
        expected_unremoved_serials = ['does_not_exist_1394']

        self.assertEqual(expected_removed_serials, removed_serial)
        self.assertEqual(expected_unremoved_serials, unremoved_serials)
Esempio n. 2
0
    def RemoveEntitlementsBySerials(self,
                                    serials,
                                    proxy_options,
                                    locale,
                                    sender=None):
        """
        Try to remove entitlements (subscriptions) by serials
        :param serials: List of serial numbers of subscriptions
        :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
        """
        serials = dbus_utils.dbus_to_python(serials, 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_serials, unremoved_serials = entitlement_service.remove_entitlements_by_serials(
            serials)

        return json.dumps(removed_serials)
    def test_remove_all_pools_by_serial(self):
        """
        Test of removing all pools by serial numbers
        """
        ent_service = EntitlementService(self.mock_cp)
        ent_service.cp.unbindBySerial = mock.Mock()

        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_serial, unremoved_serials = ent_service.remove_entitlements_by_serials(
            ['6219625278114868779', '3573249574655121394']
        )

        expected_removed_serials = ['6219625278114868779', '3573249574655121394']

        self.assertEqual(expected_removed_serials, removed_serial)
        self.assertEqual([], unremoved_serials)
    def RemoveEntitlementsBySerials(self, serials, proxy_options, locale, sender=None):
        """
        Try to remove entitlements (subscriptions) by serials
        :param serials: List of serial numbers of subscriptions
        :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
        """
        serials = dbus_utils.dbus_to_python(serials, 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_serials, unremoved_serials = entitlement_service.remove_entitlements_by_serials(serials)

        return json.dumps(removed_serials)
    def test_remove_dupli_pools_by_serial(self):
        """
        Test of removing pools specified with duplicities
        (one serial number is set twice)
        """
        ent_service = EntitlementService(self.mock_cp)
        ent_service.cp.unbindBySerial = mock.Mock()

        ent_service.entcertlib = mock.Mock().return_value
        ent_service.entcertlib.update = mock.Mock()

        removed_serial, unremoved_serials = ent_service.remove_entitlements_by_serials(
            [
                "6219625278114868779", "6219625278114868779",
                "3573249574655121394"
            ])

        expected_removed_serials = [
            "6219625278114868779", "3573249574655121394"
        ]

        self.assertEqual(expected_removed_serials, removed_serial)
        self.assertEqual([], unremoved_serials)