def add_pool(self, pool, default_quantity_value):
        self.total_contracts += 1
        self.total_contracts_label.set_text(str(self.total_contracts))
        self.subscription_name_label.set_text(pool['productName'])

        # Use unlimited for -1 quanities
        quantity = pool['quantity']
        if quantity < 0:
            quantity = _('Unlimited')
            quantity_available = -1
        else:
            quantity_available = int(pool['quantity']) - int(pool['consumed'])

        # cap the default selected quantity at the max available
        # for that pool. See #855257. Watch out for quantity_available
        # being -1 (unlimited).
        if default_quantity_value > quantity_available and quantity_available >= 0:
            default_quantity_value = quantity_available

        quantity_increment = 1
        if 'calculatedAttributes' in pool:
            calculated_attrs = pool['calculatedAttributes']

            if 'quantity_increment' in calculated_attrs:
                quantity_increment = int(
                    calculated_attrs['quantity_increment'])

        self.model.add_map({
            'contract_number':
            pool['contractNumber'],
            'consumed_fraction':
            "%s / %s" % (pool['consumed'], quantity),
            'start_date':
            isodate.parse_date(pool['startDate']),
            'end_date':
            isodate.parse_date(pool['endDate']),
            'default_quantity':
            default_quantity_value,
            'product_name':
            pool['productName'],
            'pool':
            pool,
            'is_virt_only':
            PoolWrapper(pool).is_virt_only(),
            'multi_entitlement':
            allows_multi_entitlement(pool),
            'quantity_available':
            quantity_available,
            'quantity_increment':
            quantity_increment,
        })
    def add_pool(self, pool, default_quantity_value):
        self.total_contracts += 1
        self.total_contracts_label.set_text(str(self.total_contracts))
        self.subscription_name_label.set_text(pool['productName'])

        # Use unlimited for -1 quanities
        quantity = pool['quantity']
        if quantity < 0:
            quantity = _('Unlimited')
            quantity_available = -1
        else:
            quantity_available = int(pool['quantity']) - int(pool['consumed'])

        # cap the default selected quantity at the max available
        # for that pool. See #855257. Watch out for quantity_available
        # being -1 (unlimited).
        if default_quantity_value > quantity_available and quantity_available >= 0:
            default_quantity_value = quantity_available

        quantity_increment = 1
        if 'calculatedAttributes' in pool:
            calculated_attrs = pool['calculatedAttributes']

            if 'quantity_increment' in calculated_attrs:
                quantity_increment = int(calculated_attrs['quantity_increment'])

        self.model.add_map({
            'contract_number': pool['contractNumber'],
            'consumed_fraction': "%s / %s" % (pool['consumed'], quantity),
            'start_date': isodate.parse_date(pool['startDate']),
            'end_date': isodate.parse_date(pool['endDate']),
            'default_quantity': default_quantity_value,
            'product_name': pool['productName'],
            'pool': pool,
            'is_virt_only': PoolWrapper(pool).is_virt_only(),
            'multi_entitlement': allows_multi_entitlement(pool),
            'quantity_available': quantity_available,
            'quantity_increment': quantity_increment,
            })
    def test_is_case_insensitive(self):
        pool = self._create_pool_data_with_multi_entitlement_attribute("YeS")
        self.assertTrue(allows_multi_entitlement(pool))

        pool = self._create_pool_data_with_multi_entitlement_attribute("nO")
        self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_any_other_value(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("not_a_good_value")
     self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_empty_string(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("")
     self.assertFalse(allows_multi_entitlement(pool))
 def test_does_not_allow_when_not_set(self):
     pool = {"productAttributes": []}
     self.assertFalse(allows_multi_entitlement(pool))
 def test_allows_when_1(self):
     pool = self._create_pool_data_with_multi_entitlement_attribute("1")
     self.assertTrue(allows_multi_entitlement(pool))
Esempio n. 8
0
    def display_pools(self):
        """
        Re-display the list of pools last queried, based on current filter options.
        """
        selection = self.top_view.get_selection()
        selected_pool_id = None
        itr = selection.get_selected()[1]
        if itr:
            selected_pool_id = self.store.get_value(itr, self.store['pool_id'])

        self.store.clear()

        # It may seem backwards that incompatible = self.filters.show_compatible
        # etc., but think of it like "if show_compatible is true, then
        # filter out all the incompatible products."
        merged_pools = self.pool_stash.merge_pools(
                incompatible=self.filters.show_compatible,
                overlapping=self.filters.show_no_overlapping,
                uninstalled=self.filters.show_installed,
                subscribed=True,
                text=self.get_filter_text())

        if self.pool_stash.all_pools_size() == 0:
            self.sub_details.clear()
            # If the date is None (now), use current time
            on_date = self.date_picker.date or datetime.datetime.now()
            self.display_message(_("No subscriptions are available on %s.") %
                                   on_date.strftime("%Y-%m-%d"))
            return

        if len(merged_pools) == 0:
            self.sub_details.clear()
            self.display_message(_("No subscriptions match current filters."))
            return

        # Hide the no subscriptions label and show the pools list:
        self.widget_switcher.set_active(1)

        sorter = managerlib.MergedPoolsStackingGroupSorter(list(merged_pools.values()))
        for group in sorter.groups:
            tree_iter = None
            if group.name and len(group.entitlements) > 1:
                tree_iter = self.store.add_map(tree_iter, self._create_parent_map(group.name))

            for entry in group.entitlements:
                quantity_available = 0
                if entry.quantity < 0:
                    available = _('Unlimited')
                    quantity_available = -1
                else:
                    available = entry.quantity - entry.consumed
                    quantity_available = entry.quantity - entry.consumed

                pool = entry.pools[0]
                # Use the maximum suggested quantity, not the first one.  BZ 1022198
                # This is still incorrect when quantities from multiple merged pools are required
                suggested_quantity = max([self.calculate_default_quantity(p) for p in entry.pools])

                pool_type = PoolWrapper(pool).get_pool_type()

                attrs = self._product_attrs_to_dict(pool['productAttributes'])

                # Display support level and type if the attributes are present:
                support_level = ""
                support_type = ""
                if 'support_level' in attrs:
                    support_level = attrs['support_level']
                if 'support_type' in attrs:
                    support_type = attrs['support_type']

                quantity_increment = 1
                if 'calculatedAttributes' in pool:
                    calculated_attrs = pool['calculatedAttributes']

                    if 'quantity_increment' in calculated_attrs:
                        quantity_increment = int(calculated_attrs['quantity_increment'])

                self.store.add_map(tree_iter, {
                    'virt_only': self._machine_type(entry.pools),
                    'product_name': str(entry.product_name),
                    'product_name_formatted': apply_highlight(entry.product_name,
                                                              self.get_filter_text()),
                    'quantity_to_consume': suggested_quantity,
                    'available': str(available),
                    'product_id': str(entry.product_id),
                    'pool_id': entry.pools[0]['id'],  # not displayed, just for lookup later
                    'merged_pools': entry,  # likewise not displayed, for subscription
                    'align': 0.5,
                    'multi-entitlement': allows_multi_entitlement(pool),
                    'background': None,
                    'quantity_available': quantity_available,
                    'support_level': support_level,
                    'support_type': support_type,
                    'quantity_increment': quantity_increment,
                    'pool_type': str(pool_type)
                })

        # Ensure that all nodes are expanded in the tree view.
        self.top_view.expand_all()
        self._stripe_rows(None, self.store)

        # set the selection/details back to what they were, if possible
        def select_row(model, path, itr, data):
            if model.get_value(itr, model['pool_id']) == data[0]:
                data[1].set_cursor(path)
                return True

        # Attempt to re-select if there was a selection
        if selected_pool_id:
            self.store.foreach(select_row, (selected_pool_id, self.top_view))

        # If we don't have a selection, clear the sub_details view
        # TODO: is this conditional necessary?  If so, when?
        if not self.top_view.get_selection().get_selected()[1]:
            self.sub_details.clear()
Esempio n. 9
0
    def display_pools(self):
        """
        Re-display the list of pools last queried, based on current filter options.
        """
        selection = self.top_view.get_selection()
        selected_pool_id = None
        itr = selection.get_selected()[1]
        if itr:
            selected_pool_id = self.store.get_value(itr, self.store['pool_id'])

        self.store.clear()

        # It may seem backwards that incompatible = self.filters.show_compatible
        # etc., but think of it like "if show_compatible is true, then
        # filter out all the incompatible products."
        merged_pools = self.pool_stash.merge_pools(
            incompatible=self.filters.show_compatible,
            overlapping=self.filters.show_no_overlapping,
            uninstalled=self.filters.show_installed,
            subscribed=True,
            text=self.get_filter_text())

        if self.pool_stash.all_pools_size() == 0:
            self.sub_details.clear()
            # If the date is None (now), use current time
            on_date = self.date_picker.date or datetime.datetime.now()
            self.display_message(
                _("No subscriptions are available on %s.") %
                on_date.strftime("%Y-%m-%d"))
            return

        if len(merged_pools) == 0:
            self.sub_details.clear()
            self.display_message(_("No subscriptions match current filters."))
            return

        # Hide the no subscriptions label and show the pools list:
        self.widget_switcher.set_active(1)

        sorter = managerlib.MergedPoolsStackingGroupSorter(
            list(merged_pools.values()))
        for group in sorter.groups:
            tree_iter = None
            if group.name and len(group.entitlements) > 1:
                tree_iter = self.store.add_map(
                    tree_iter, self._create_parent_map(group.name))

            for entry in group.entitlements:
                quantity_available = 0
                if entry.quantity < 0:
                    available = _('Unlimited')
                    quantity_available = -1
                else:
                    available = entry.quantity - entry.consumed
                    quantity_available = entry.quantity - entry.consumed

                pool = entry.pools[0]
                # Use the maximum suggested quantity, not the first one.  BZ 1022198
                # This is still incorrect when quantities from multiple merged pools are required
                suggested_quantity = max(
                    [self.calculate_default_quantity(p) for p in entry.pools])

                pool_type = PoolWrapper(pool).get_pool_type()

                attrs = self._product_attrs_to_dict(pool['productAttributes'])

                # Display support level and type if the attributes are present:
                support_level = ""
                support_type = ""
                if 'support_level' in attrs:
                    support_level = attrs['support_level']
                if 'support_type' in attrs:
                    support_type = attrs['support_type']

                quantity_increment = 1
                if 'calculatedAttributes' in pool:
                    calculated_attrs = pool['calculatedAttributes']

                    if 'quantity_increment' in calculated_attrs:
                        quantity_increment = int(
                            calculated_attrs['quantity_increment'])

                self.store.add_map(
                    tree_iter,
                    {
                        'virt_only':
                        self._machine_type(entry.pools),
                        'product_name':
                        str(entry.product_name),
                        'product_name_formatted':
                        apply_highlight(entry.product_name,
                                        self.get_filter_text()),
                        'quantity_to_consume':
                        suggested_quantity,
                        'available':
                        str(available),
                        'product_id':
                        str(entry.product_id),
                        'pool_id':
                        entry.pools[0]
                        ['id'],  # not displayed, just for lookup later
                        'merged_pools':
                        entry,  # likewise not displayed, for subscription
                        'align':
                        0.5,
                        'multi-entitlement':
                        allows_multi_entitlement(pool),
                        'background':
                        None,
                        'quantity_available':
                        quantity_available,
                        'support_level':
                        support_level,
                        'support_type':
                        support_type,
                        'quantity_increment':
                        quantity_increment,
                        'pool_type':
                        str(pool_type)
                    })

        # Ensure that all nodes are expanded in the tree view.
        self.top_view.expand_all()
        self._stripe_rows(None, self.store)

        # set the selection/details back to what they were, if possible
        def select_row(model, path, itr, data):
            if model.get_value(itr, model['pool_id']) == data[0]:
                data[1].set_cursor(path)
                return True

        # Attempt to re-select if there was a selection
        if selected_pool_id:
            self.store.foreach(select_row, (selected_pool_id, self.top_view))

        # If we don't have a selection, clear the sub_details view
        # TODO: is this conditional necessary?  If so, when?
        if not self.top_view.get_selection().get_selected()[1]:
            self.sub_details.clear()