def get_name_from_attributes(variant): attributes = variant.product.product_type.variant_attributes.all() values = get_attributes_display_map(variant, attributes) return ' / '.join( attributechoice.name for attribute_pk, attributechoice in sorted( values.items(), key=lambda x: x[0]))
def test_get_attributes_display_map(product): attributes = product.product_type.product_attributes.all() attributes_display_map = get_attributes_display_map( product, attributes) product_attr = product.product_type.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): attributes = product.product_type.product_attributes.all() attributes_display_map = get_attributes_display_map( product, attributes) product_attr = product.product_type.product_attributes.first() attr_value = product_attr.values.first() assert len(attributes_display_map) == 1 assert {k: v.pk for k, v in attributes_display_map.items()} == { product_attr.pk: attr_value.translated.pk}
def test_get_attributes_display_map(product): attributes = product.product_type.product_attributes.all() attributes_display_map = get_attributes_display_map( product, attributes) product_attr = product.product_type.product_attributes.first() attr_value = product_attr.values.first() assert len(attributes_display_map) == 1 assert {k: v.pk for k, v in attributes_display_map.items()} == { product_attr.pk: attr_value.translated.pk}
def test_get_attributes_display_map_empty(product_with_no_attributes): product = product_with_no_attributes attributes = product.product_type.product_attributes.all() assert get_attributes_display_map(product, attributes) == {}
def get_name_from_attributes(variant): attributes = variant.product.product_type.variant_attributes.all() values = get_attributes_display_map(variant, attributes) return " / ".join(attributechoice.name for attribute_pk, attributechoice in sorted(values.items(), key=lambda x: x[0]))
def test_get_attributes_display_map_empty(product_with_no_attributes): product = product_with_no_attributes attributes = product.product_type.product_attributes.all() assert get_attributes_display_map(product, attributes) == {}