Ejemplo n.º 1
0
def test_configuration_set_and_get():
    cache.clear()
    shop = get_default_shop()
    test_conf_data = {"data": "test"}
    configuration.set(shop, "key", test_conf_data)

    # Get the configuration via configuration API
    assert configuration.get(shop, "key") == test_conf_data
    # Check that configuration is saved to database
    assert ConfigurationItem.objects.get(shop=shop, key="key").value == test_conf_data
Ejemplo n.º 2
0
def test_configuration_set_and_get():
    cache.clear()
    shop = get_default_shop()
    test_conf_data = {"data": "test"}
    configuration.set(shop, "key", test_conf_data)

    # Get the configuration via configuration API
    assert configuration.get(shop, "key") == test_conf_data
    # Check that configuration is saved to database
    assert ConfigurationItem.objects.get(shop=shop,
                                         key="key").value == test_conf_data
Ejemplo n.º 3
0
def test_configuration_cache():
    cache.clear()
    shop = get_default_shop()
    configuration.set(None, "key1", "test1")
    configuration.set(shop, "key2", "test2")

    # Shop configurations cache should be bumped
    assert cache.get(configuration._get_cache_key(shop)) is None
    configuration.get(shop, "key1")
    # Now shop configurations and key2 should found from cache
    assert cache.get(configuration._get_cache_key(shop)).get("key2") == "test2"
Ejemplo n.º 4
0
def test_configuration_cache():
    cache.clear()
    shop = get_default_shop()
    configuration.set(None, "key1", "test1")
    configuration.set(shop, "key2", "test2")

    # Shop configurations cache should be bumped
    assert cache.get(configuration._get_cache_key(shop)) is None
    configuration.get(shop, "key1")
    # Now shop configurations and key2 should found from cache
    assert cache.get(configuration._get_cache_key(shop)).get("key2") == "test2"
Ejemplo n.º 5
0
def test_configuration_update():
    cache.clear()
    shop = get_default_shop()
    configuration.set(shop, "key1", {"data": "test1"})
    configuration.set(shop, "key2", {"data": "test2"})
    configuration.set(shop, "key3", {"data": "test3"})
    assert configuration.get(shop, "key1").get("data") == "test1"
    assert configuration.get(shop, "key3").get("data") == "test3"

    # Update configuration
    configuration.set(shop, "key3", {"data": "test_bump"})
    assert configuration.get(shop, "key3").get("data") == "test_bump"
Ejemplo n.º 6
0
def test_configuration_update():
    cache.clear()
    shop = get_default_shop()
    configuration.set(shop, "key1", {"data": "test1"})
    configuration.set(shop, "key2", {"data": "test2"})
    configuration.set(shop, "key3", {"data": "test3"})
    assert configuration.get(shop, "key1").get("data") == "test1"
    assert configuration.get(shop, "key3").get("data") == "test3"

    # Update configuration
    configuration.set(shop, "key3", {"data": "test_bump"})
    assert configuration.get(shop, "key3").get("data") == "test_bump"
def test_get_best_selling_products():
    context = get_jinja_context()
    cache.clear()
    # No products sold
    assert len(list(general.get_best_selling_products(context, n_products=2))) == 0

    supplier = get_default_supplier()
    shop = get_default_shop()
    product = get_default_product()
    create_order_with_product(product, supplier, quantity=1, taxless_base_unit_price=10, shop=shop)
    cache.clear()
    # One product sold
    assert len(list(general.get_best_selling_products(context, n_products=2))) == 1
def test_get_best_selling_products():
    context = get_jinja_context()
    cache.clear()
    # No products sold
    assert len(list(general.get_best_selling_products(context,
                                                      n_products=2))) == 0

    supplier = get_default_supplier()
    shop = get_default_shop()
    product = get_default_product()
    create_order_with_product(product,
                              supplier,
                              quantity=1,
                              taxless_base_unit_price=10,
                              shop=shop)
    cache.clear()
    # One product sold
    assert len(list(general.get_best_selling_products(context,
                                                      n_products=2))) == 1
def test_best_selling_products_with_multiple_orders():
    context = get_jinja_context()
    supplier = get_default_supplier()
    shop = get_default_shop()
    n_products = 2
    price = 10

    product_1 = create_product("test-sku-1", supplier=supplier, shop=shop)
    product_2 = create_product("test-sku-2", supplier=supplier, shop=shop)
    create_order_with_product(product_1, supplier, quantity=1, taxless_base_unit_price=price, shop=shop)
    create_order_with_product(product_2, supplier, quantity=1, taxless_base_unit_price=price, shop=shop)
    cache.clear()
    # Two initial products sold
    assert product_1 in general.get_best_selling_products(context, n_products=n_products)
    assert product_2 in general.get_best_selling_products(context, n_products=n_products)

    product_3 = create_product("test-sku-3", supplier=supplier, shop=shop)
    create_order_with_product(product_3, supplier, quantity=2, taxless_base_unit_price=price, shop=shop)
    cache.clear()
    # Third product sold in greater quantity
    assert product_3 in general.get_best_selling_products(context, n_products=n_products)

    create_order_with_product(product_1, supplier, quantity=4, taxless_base_unit_price=price, shop=shop)
    create_order_with_product(product_2, supplier, quantity=4, taxless_base_unit_price=price, shop=shop)
    cache.clear()
    # Third product outsold by first two products
    assert product_3 not in general.get_best_selling_products(context, n_products=n_products)
Ejemplo n.º 10
0
def test_global_configurations():
    cache.clear()
    shop = get_default_shop()
    configuration.set(None, "key1", {"data": "test1"})
    configuration.set(shop, "key2", {"data": "test2"})

    # key1 from shop should come from global configuration
    assert configuration.get(shop, "key1").get("data") == "test1"
    # key2 shouldn't be in global configurations
    assert configuration.get(None, "key2") is None

    # Update global configuration
    configuration.set(None, "key1", {"data": "test_bump"})
    assert configuration.get(shop, "key1").get("data") == "test_bump"

    # Override shop data for global key1
    configuration.set(shop, "key1", "test_data")
    assert configuration.get(shop, "key1") == "test_data"

    # Update shop configuration for global key1
    configuration.set(shop, "key1", "test_data1")
    assert configuration.get(shop, "key1") == "test_data1"
Ejemplo n.º 11
0
def test_global_configurations():
    cache.clear()
    shop = get_default_shop()
    configuration.set(None, "key1", {"data": "test1"})
    configuration.set(shop, "key2", {"data": "test2"})

    # key1 from shop should come from global configuration
    assert configuration.get(shop, "key1").get("data") == "test1"
    # key2 shouldn't be in global configurations
    assert configuration.get(None, "key2") is None

    # Update global configuration
    configuration.set(None, "key1", {"data": "test_bump"})
    assert configuration.get(shop, "key1").get("data") == "test_bump"

    # Override shop data for global key1
    configuration.set(shop, "key1", "test_data")
    assert configuration.get(shop, "key1") == "test_data"

    # Update shop configuration for global key1
    configuration.set(shop, "key1", "test_data1")
    assert configuration.get(shop, "key1") == "test_data1"
Ejemplo n.º 12
0
def test_best_selling_products_with_multiple_orders():
    context = get_jinja_context()
    supplier = get_default_supplier()
    shop = get_default_shop()
    n_products = 2
    price = 10

    product_1 = create_product("test-sku-1", supplier=supplier, shop=shop)
    product_2 = create_product("test-sku-2", supplier=supplier, shop=shop)
    create_order_with_product(product_1,
                              supplier,
                              quantity=1,
                              taxless_base_unit_price=price,
                              shop=shop)
    create_order_with_product(product_2,
                              supplier,
                              quantity=1,
                              taxless_base_unit_price=price,
                              shop=shop)
    cache.clear()
    # Two initial products sold
    assert product_1 in general.get_best_selling_products(
        context, n_products=n_products)
    assert product_2 in general.get_best_selling_products(
        context, n_products=n_products)

    product_3 = create_product("test-sku-3", supplier=supplier, shop=shop)
    create_order_with_product(product_3,
                              supplier,
                              quantity=2,
                              taxless_base_unit_price=price,
                              shop=shop)
    cache.clear()
    # Third product sold in greater quantity
    assert product_3 in general.get_best_selling_products(
        context, n_products=n_products)

    create_order_with_product(product_1,
                              supplier,
                              quantity=4,
                              taxless_base_unit_price=price,
                              shop=shop)
    create_order_with_product(product_2,
                              supplier,
                              quantity=4,
                              taxless_base_unit_price=price,
                              shop=shop)
    cache.clear()
    # Third product outsold by first two products
    assert product_3 not in general.get_best_selling_products(
        context, n_products=n_products)