def test_visible_attributes():
    shop = get_default_shop()
    supplier = get_default_supplier()
    product = create_product("test-sku", shop=shop, supplier=supplier)

    _add_attribute_for_product(product, "attr1", AttributeType.BOOLEAN,
                               AttributeVisibility.SHOW_ON_PRODUCT_PAGE,
                               "attr1")
    _add_attribute_for_product(product, "attr2", AttributeType.BOOLEAN,
                               AttributeVisibility.HIDDEN, "attr2")

    assert len(product_helpers.get_visible_attributes(product)) == 1

    _add_attribute_for_product(product, "attr3", AttributeType.BOOLEAN,
                               AttributeVisibility.SHOW_ON_PRODUCT_PAGE,
                               "attr3")

    assert len(product_helpers.get_visible_attributes(product)) == 2

    new_product = create_product("test-sku-2", shop=shop, supplier=supplier)
    ProductAttribute.objects.create(
        product=new_product,
        attribute=Attribute.objects.filter(identifier="attr1").first())

    assert len(product_helpers.get_visible_attributes(product)) == 2
    assert len(product_helpers.get_visible_attributes(new_product)) == 1
def test_visible_attributes():
    shop = get_default_shop()
    supplier = get_default_supplier()
    product = create_product("test-sku", shop=shop, supplier=supplier)

    _add_attribute_for_product(
        product, "attr1", AttributeType.BOOLEAN, AttributeVisibility.SHOW_ON_PRODUCT_PAGE, "attr1")
    _add_attribute_for_product(
        product, "attr2", AttributeType.BOOLEAN, AttributeVisibility.HIDDEN, "attr2")

    assert len(product_helpers.get_visible_attributes(product)) == 1

    _add_attribute_for_product(
        product, "attr3", AttributeType.BOOLEAN, AttributeVisibility.SHOW_ON_PRODUCT_PAGE, "attr3")

    assert len(product_helpers.get_visible_attributes(product)) == 2

    new_product = create_product("test-sku-2", shop=shop, supplier=supplier)
    ProductAttribute.objects.create(product=new_product, attribute=Attribute.objects.filter(identifier="attr1").first())

    assert len(product_helpers.get_visible_attributes(product)) == 2
    assert len(product_helpers.get_visible_attributes(new_product)) == 1