Ejemplo n.º 1
0
def test_mass_action_multishop(rf, admin_user):
    def create_shop(name):
        return Shop.objects.create(
            name="foobar",
            identifier=name,
            status=ShopStatus.ENABLED,
            public_name=name,
            currency=get_default_currency().code,
        )

    shop_one = get_default_shop()
    shop_two = create_shop("foobar")
    product = get_default_product()
    shop_product_one = product.get_shop_instance(shop_one)
    shop_product_two = ShopProduct.objects.create(shop=shop_two, product=product)
    shop_product_two.save()
    assert shop_product_one.visibility == ShopProductVisibility.ALWAYS_VISIBLE
    assert shop_product_two.visibility == ShopProductVisibility.ALWAYS_VISIBLE
    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop_one)
    InvisibleMassAction().process(request, "all")
    shop_product_one.refresh_from_db()
    shop_product_two.refresh_from_db()
    assert shop_product_one.visibility == ShopProductVisibility.NOT_VISIBLE
    assert shop_product_two.visibility == ShopProductVisibility.ALWAYS_VISIBLE
    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop_one)
    VisibleMassAction().process(request, "all")
    shop_product_one.refresh_from_db()
    shop_product_two.refresh_from_db()
    assert shop_product_two.visibility == ShopProductVisibility.ALWAYS_VISIBLE
    assert shop_product_one.visibility == ShopProductVisibility.ALWAYS_VISIBLE
Ejemplo n.º 2
0
def test_mass_action_cache(rf, admin_user):
    shop = get_default_shop()
    cache.clear()
    product = create_product(printable_gibberish(),
                             shop=shop,
                             default_price=50)
    product2 = create_product(printable_gibberish(),
                              shop=shop,
                              default_price=100)

    shop_product = product.get_shop_instance(shop)
    shop_product2 = product2.get_shop_instance(shop)

    set_bump_cache_for_shop_product = mock.Mock(
        wraps=context_cache.bump_cache_for_shop_product)

    def bump_cache_for_shop_product(item):
        return set_bump_cache_for_shop_product(item)

    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)

    with mock.patch.object(context_cache,
                           "bump_cache_for_shop_product",
                           new=bump_cache_for_shop_product):
        assert set_bump_cache_for_shop_product.call_count == 0
        InvisibleMassAction().process(request,
                                      [shop_product.id, shop_product2.id])
        assert set_bump_cache_for_shop_product.call_count == 2

        VisibleMassAction().process(request,
                                    [shop_product.id, shop_product2.id])
        assert set_bump_cache_for_shop_product.call_count == 4