Beispiel #1
0
def test_category_links_plugin_with_customer(rf, show_all_categories):
    """
    Test plugin for categories that is visible for certain group
    """
    shop = get_default_shop()
    group = get_default_customer_group()
    customer = create_random_person()
    customer.groups.add(group)
    customer.save()

    request = rf.get("/")
    request.shop = get_default_shop()
    apply_request_middleware(request)
    request.customer = customer

    category = get_default_category()
    category.status = CategoryStatus.VISIBLE
    category.visibility = CategoryVisibility.VISIBLE_TO_GROUPS
    category.visibility_groups.add(group)
    category.shops.add(shop)
    category.save()

    vars = {"request": request}
    context = get_jinja_context(**vars)
    plugin = CategoryLinksPlugin({"categories": [category.pk], "show_all_categories": show_all_categories})
    assert category.is_visible(customer)
    assert category in plugin.get_context_data(context)["categories"]

    customer_without_groups = create_random_person()
    customer_without_groups.groups.clear()

    assert not category.is_visible(customer_without_groups)
    request.customer = customer_without_groups
    context = get_jinja_context(**vars)
    assert category not in plugin.get_context_data(context)["categories"]
Beispiel #2
0
def test_category_links_plugin(rf):
    """
    Test that the plugin only displays visible categories
    with shop (since we can't have a request without shop
    or customer)
    """
    category = get_default_category()
    context = get_context(rf)
    plugin = CategoryLinksPlugin({"show_all_categories": True})
    assert context["request"].customer.is_anonymous
    assert category not in plugin.get_context_data(context)["categories"]

    category.status = CategoryStatus.VISIBLE
    category.shops.add(get_default_shop())
    category.save()
    assert context["request"].customer.is_anonymous
    assert context["request"].shop in category.shops.all()
    assert category in plugin.get_context_data(context)["categories"]
Beispiel #3
0
def test_category_links_plugin_show_all(rf):
    """
    Test that show_all_categories forces plugin to return all visible categories
    """
    category = get_default_category()
    category.status = CategoryStatus.VISIBLE
    category.shops.add(get_default_shop())
    category.save()
    context = get_context(rf)
    plugin = CategoryLinksPlugin({"show_all_categories": False})
    assert context["request"].customer.is_anonymous
    assert context["request"].shop in category.shops.all()
    assert not plugin.get_context_data(context)["categories"]

    plugin = CategoryLinksPlugin({"show_all_categories": True})
    assert category in plugin.get_context_data(context)["categories"]