def display_variant(self, attributes=None): if attributes is None: attributes = self.product.attributes.all() values = get_attributes_display_map(self, attributes).values() if values: return ', '.join([smart_text(value) for value in values]) else: return smart_text(self)
def display_variant(self, attributes=None): if attributes is None: attributes = self.product.attributes.all() values = get_attributes_display_map(self, attributes).values() if values: return ', '.join([smart_text(value) for value in values]) else: return smart_text(self)
def test_get_attributes_display_map_no_choices(product_in_stock): attributes = product_in_stock.product_class.product_attributes.all() product_attr = attributes.first() product_in_stock.set_attribute(product_attr.pk, -1) attributes_display_map = get_attributes_display_map( product_in_stock, attributes) assert attributes_display_map == {product_attr.pk: smart_text(-1)}
def test_get_attributes_display_map_no_choices(product_in_stock): attributes = product_in_stock.product_class.product_attributes.all() product_attr = attributes.first() product_in_stock.set_attribute(product_attr.pk, -1) attributes_display_map = get_attributes_display_map( product_in_stock, attributes) assert attributes_display_map == {product_attr.pk: smart_text(-1)}
def test_get_attributes_display_map_no_choices(product_in_stock): attributes = product_in_stock.product_type.product_attributes.all() product_attr = attributes.first() product_in_stock.attributes[str(product_attr.pk)] = '-1' attributes_display_map = get_attributes_display_map( product_in_stock, attributes) assert attributes_display_map == {product_attr.pk: '-1'}
def test_get_attributes_display_map(product_in_stock): attributes = product_in_stock.product_class.product_attributes.all() attributes_display_map = get_attributes_display_map( product_in_stock, attributes) product_attr = product_in_stock.product_class.product_attributes.first() attr_value = product_attr.values.first() assert len(attributes_display_map) == 1 assert attributes_display_map == {product_attr.pk: attr_value}
def test_get_attributes_display_map(product_in_stock): attributes = product_in_stock.product_class.product_attributes.all() attributes_display_map = get_attributes_display_map( product_in_stock, attributes) product_attr = product_in_stock.product_class.product_attributes.first() attr_value = product_attr.values.first() assert len(attributes_display_map) == 1 assert attributes_display_map == {product_attr.pk: attr_value}
def test_get_attributes_display_map_empty(product_with_no_attributes): product = product_with_no_attributes attributes = product.product_class.product_attributes.all() assert get_attributes_display_map(product, attributes) == {}
def test_get_attributes_display_map_empty(product_with_no_attributes): product = product_with_no_attributes attributes = product.product_class.product_attributes.all() assert get_attributes_display_map(product, attributes) == {}