def test_product_price_get_quantity_with_display_unit(rf, decimals):
    shop = get_default_shop()
    product = create_product("sku", shop=shop)
    shop_product = product.get_shop_instance(shop)
    from shuup.core.models import SalesUnit, DisplayUnit
    sales_unit = SalesUnit.objects.create(identifier="random",
                                          decimals=decimals)
    product.sales_unit = sales_unit
    product.save()

    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(shop_product, input_value, expected_output):
        view.request.GET = dict(view.request.GET,
                                quantity=input_value,
                                unitType="not internal")
        result = view._get_quantity(shop_product)
        assert result == expected_output

    if not decimals:
        check(shop_product, '42.232323', 42)
    else:
        check(shop_product, '42.23232323', Decimal("42.23"))
def test_product_price_get_quantity(rf):
    shop = get_default_shop()
    product = create_product("sku", shop=shop)
    shop_product = product.get_shop_instance(shop)

    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(shop_product, input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value)
        result = view._get_quantity(shop_product)
        if expected_output is None:
            assert result is None
        else:
            assert isinstance(result, Decimal)
            assert result == expected_output

    check(shop_product, '42', 42)
    check(shop_product, '1.5', Decimal('1.5'))
    check(shop_product, '3.2441', Decimal('3.2441'))
    check(shop_product, '0.0000000001', Decimal('0.0000000001'))
    check(shop_product, '0.000000000001', Decimal('0.000000000001'))
    check(shop_product, '123456789123456789123456789',
          123456789123456789123456789)
    check(shop_product, '0', 0)
    check(shop_product, '-100', None)
    check(shop_product, '', None)
    check(shop_product, 'inf', None)
    check(shop_product, 'nan', None)
    check(shop_product, 'Hello', None)
    check(shop_product, '1.2.3', None)
    check(shop_product, '1.2.3.4', None)
    check(shop_product, '1-2', None)
    check(shop_product, '1 2 3', None)
    check(shop_product, '1e30', None)
    check(shop_product, '1,5', None)
    check(shop_product, 'mämmi', None)
    check(shop_product, '3€', None)
    check(shop_product, '\0', None)
    check(shop_product, '123\0', None)
    check(shop_product, '123\0456', None)
    check(shop_product, '\n', None)
Esempio n. 3
0
def test_product_price_get_quantity(rf):
    shop = get_default_shop()
    product = create_product("sku", shop=shop)
    shop_product = product.get_shop_instance(shop)

    view = ProductPriceView()
    view.request = rf.get("/")
    assert "quantity" not in view.request.GET

    def check(shop_product, input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value)
        result = view._get_quantity(shop_product)
        if expected_output is None:
            assert result is None
        else:
            assert isinstance(result, Decimal)
            assert result == expected_output

    check(shop_product, "42", 42)
    check(shop_product, "1.5", Decimal("1.5"))
    check(shop_product, "3.2441", Decimal("3.2441"))
    check(shop_product, "0.0000000001", Decimal("0.0000000001"))
    check(shop_product, "0.000000000001", Decimal("0.000000000001"))
    check(shop_product, "123456789123456789123456789",
          123456789123456789123456789)
    check(shop_product, "0", 0)
    check(shop_product, "-100", None)
    check(shop_product, "", None)
    check(shop_product, "inf", None)
    check(shop_product, "nan", None)
    check(shop_product, "Hello", None)
    check(shop_product, "1.2.3", None)
    check(shop_product, "1.2.3.4", None)
    check(shop_product, "1-2", None)
    check(shop_product, "1 2 3", None)
    check(shop_product, "1e30", None)
    check(shop_product, "1,5", None)
    check(shop_product, "mämmi", None)
    check(shop_product, "3€", None)
    check(shop_product, "\0", None)
    check(shop_product, "123\0", None)
    check(shop_product, "123\0456", None)
    check(shop_product, "\n", None)
Esempio n. 4
0
def test_product_price_get_quantity(rf):
    shop = get_default_shop()
    product = create_product("sku", shop=shop)
    shop_product = product.get_shop_instance(shop)

    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(shop_product, input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value)
        result = view._get_quantity(shop_product)
        if expected_output is None:
            assert result is None
        else:
            assert isinstance(result, Decimal)
            assert result == expected_output

    check(shop_product, '42', 42)
    check(shop_product, '1.5', Decimal('1.5'))
    check(shop_product, '3.2441', Decimal('3.2441'))
    check(shop_product, '0.0000000001', Decimal('0.0000000001'))
    check(shop_product, '0.000000000001', Decimal('0.000000000001'))
    check(shop_product, '123456789123456789123456789', 123456789123456789123456789)
    check(shop_product, '0', 0)
    check(shop_product, '-100', None)
    check(shop_product, '', None)
    check(shop_product, 'inf', None)
    check(shop_product, 'nan', None)
    check(shop_product, 'Hello', None)
    check(shop_product, '1.2.3', None)
    check(shop_product, '1.2.3.4', None)
    check(shop_product, '1-2', None)
    check(shop_product, '1 2 3', None)
    check(shop_product, '1e30', None)
    check(shop_product, '1,5', None)
    check(shop_product, 'mämmi', None)
    check(shop_product, '3€', None)
    check(shop_product, '\0', None)
    check(shop_product, '123\0', None)
    check(shop_product, '123\0456', None)
    check(shop_product, '\n', None)
Esempio n. 5
0
def test_product_price_get_quantity_with_display_unit(rf, decimals):
    shop = get_default_shop()
    product = create_product("sku", shop=shop)
    shop_product = product.get_shop_instance(shop)
    from shuup.core.models import SalesUnit, DisplayUnit
    sales_unit = SalesUnit.objects.create(identifier="random", decimals=decimals)
    product.sales_unit = sales_unit
    product.save()

    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(shop_product, input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value, unitType="not internal")
        result = view._get_quantity(shop_product)
        assert result == expected_output

    if not decimals:
        check(shop_product, '42.232323', 42)
    else:
        check(shop_product, '42.23232323', Decimal("42.23"))
Esempio n. 6
0
def test_product_price_get_quantity(rf):
    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value)
        result = view._get_quantity()
        if expected_output is None:
            assert result is None
        else:
            assert isinstance(result, Decimal)
            assert result == expected_output

    check('42', 42)
    check('1.5', Decimal('1.5'))
    check('3.2441', Decimal('3.2441'))
    check('0.0000000001', Decimal('0.0000000001'))
    check('0.000000000001', Decimal('0.000000000001'))
    check('123456789123456789123456789', 123456789123456789123456789)
    check('0', 0)
    check('-100', None)
    check('', None)
    check('inf', None)
    check('nan', None)
    check('Hello', None)
    check('1.2.3', None)
    check('1.2.3.4', None)
    check('1-2', None)
    check('1 2 3', None)
    check('1e30', None)
    check('1,5', None)
    check('mämmi', None)
    check('3€', None)
    check('\0', None)
    check('123\0', None)
    check('123\0456', None)
    check('\n', None)
Esempio n. 7
0
def test_product_price_get_quantity(rf):
    view = ProductPriceView()
    view.request = rf.get('/')
    assert 'quantity' not in view.request.GET

    def check(input_value, expected_output):
        view.request.GET = dict(view.request.GET, quantity=input_value)
        result = view._get_quantity()
        if expected_output is None:
            assert result is None
        else:
            assert isinstance(result, Decimal)
            assert result == expected_output

    check('42', 42)
    check('1.5', Decimal('1.5'))
    check('3.2441', Decimal('3.2441'))
    check('0.0000000001', Decimal('0.0000000001'))
    check('0.000000000001', Decimal('0.000000000001'))
    check('123456789123456789123456789', 123456789123456789123456789)
    check('0', 0)
    check('-100', None)
    check('', None)
    check('inf', None)
    check('nan', None)
    check('Hello', None)
    check('1.2.3', None)
    check('1.2.3.4', None)
    check('1-2', None)
    check('1 2 3', None)
    check('1e30', None)
    check('1,5', None)
    check('mämmi', None)
    check('3€', None)
    check('\0', None)
    check('123\0', None)
    check('123\0456', None)
    check('\n', None)