コード例 #1
0
ファイル: test_money.py プロジェクト: gurch101/shuup
def test_as_rounded_values(currency, digits):
    set_precision_provider(babel_precision_provider.get_precision)

    amounts = [
        '1', '2', '3', '4',
        '1.23223', '12.24442', '42.26233',
        '1223.46636', '13.24655', '411.234554',
        '101.74363', '12.99346', '4222.57422',
        '112.93549', '199.2446', '422.29234',
        '1994.49654', '940.23452', '425.24566',
        '1994.496541234566', '940.2345298765', '425.2456612334',
    ]

    for amount in amounts:
        precision = Decimal('0.1') ** digits

        rounded = Decimal(amount).quantize(precision)
        rounded2 = Decimal(amount).quantize(Decimal('0.01'))
        rounded3 = Decimal(amount).quantize(Decimal('0.001'))

        # test using the currency
        assert Money(amount, currency).as_rounded().value == rounded

        # test using digits
        assert Money(amount, currency).as_rounded(3).value == rounded3

        # test using not existent currency code
        assert Money(amount, "XTS").as_rounded().value == rounded2
コード例 #2
0
def test_as_rounded_values(currency, digits):
    set_precision_provider(babel_precision_provider.get_precision)

    amounts = [
        '1', '2', '3', '4',
        '1.23223', '12.24442', '42.26233',
        '1223.46636', '13.24655', '411.234554',
        '101.74363', '12.99346', '4222.57422',
        '112.93549', '199.2446', '422.29234',
        '1994.49654', '940.23452', '425.24566',
        '1994.496541234566', '940.2345298765', '425.2456612334',
    ]

    for amount in amounts:
        precision = Decimal('0.1') ** digits

        rounded = Decimal(amount).quantize(precision)
        rounded2 = Decimal(amount).quantize(Decimal('0.01'))
        rounded3 = Decimal(amount).quantize(Decimal('0.001'))

        # test using the currency
        assert Money(amount, currency).as_rounded().value == rounded

        # test using digits
        assert Money(amount, currency).as_rounded(3).value == rounded3

        # test using not existent currency code
        assert Money(amount, "XTS").as_rounded().value == rounded2
コード例 #3
0
def setup_module(module):
    # uses the get_precision to avoid db hits
    set_precision_provider(babel_precision_provider.get_precision)

    global settings_overrider
    settings_overrider = override_settings(
        SHUUP_CALCULATE_TAXES_AUTOMATICALLY_IF_POSSIBLE=False)
    settings_overrider.__enter__()
コード例 #4
0
def setup_module(module):
    # uses the get_precision to avoid db hits
    set_precision_provider(babel_precision_provider.get_precision)

    global settings_overrider
    settings_overrider = override_settings(
        SHUUP_CALCULATE_TAXES_AUTOMATICALLY_IF_POSSIBLE=False)
    settings_overrider.__enter__()
コード例 #5
0
ファイル: test_money.py プロジェクト: gurch101/shuup
def test_as_rounded_returns_same_type():
    set_precision_provider(babel_precision_provider.get_precision)

    class CoolMoney(Money):
        is_cool = True

    amount = CoolMoney('0.4939389', 'USD')
    assert type(amount.as_rounded()) == CoolMoney
    assert amount.as_rounded().is_cool
コード例 #6
0
def test_set_precision_provider():
    def get_precision(currency):
        return None

    set_precision_provider(get_precision)
    assert money._precision_provider == get_precision

    set_precision_provider(babel_precision_provider.get_precision)
    assert money._precision_provider == babel_precision_provider.get_precision
コード例 #7
0
ファイル: test_money.py プロジェクト: gurch101/shuup
def test_set_precision_provider():
    def get_precision(currency):
        return None

    set_precision_provider(get_precision)
    assert money._precision_provider == get_precision

    set_precision_provider(babel_precision_provider.get_precision)
    assert money._precision_provider == babel_precision_provider.get_precision
コード例 #8
0
def test_as_rounded_returns_same_type():
    set_precision_provider(babel_precision_provider.get_precision)

    class CoolMoney(Money):
        is_cool = True

    amount = CoolMoney('0.4939389', 'USD')
    assert type(amount.as_rounded()) == CoolMoney
    assert amount.as_rounded().is_cool
コード例 #9
0
ファイル: __init__.py プロジェクト: saravanan993/ivykart
    def ready(self):
        from django.conf import settings
        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException(
                "PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision
        money.set_precision_provider(get_currency_precision)
コード例 #10
0
ファイル: __init__.py プロジェクト: suutari/shoop
    def ready(self):
        from django.conf import settings

        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException("PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision

        money.set_precision_provider(get_currency_precision)
コード例 #11
0
ファイル: __init__.py プロジェクト: ruqaiya/shuup
    def ready(self):
        from django.conf import settings
        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException("PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision
        money.set_precision_provider(get_currency_precision)

        if django.conf.settings.SHUUP_ERROR_PAGE_HANDLERS_SPEC:
            from .error_handling import install_error_handlers
            install_error_handlers()

        # connect signals
        import shuup.core.signal_handers    # noqa: F401
コード例 #12
0
    def ready(self):
        from django.conf import settings
        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException("PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision
        money.set_precision_provider(get_currency_precision)

        if django.conf.settings.SHUUP_ERROR_PAGE_HANDLERS_SPEC:
            from .error_handling import install_error_handlers
            install_error_handlers()

        # connect signals
        import shuup.core.signal_handers    # noqa: F401
コード例 #13
0
ファイル: test_money.py プロジェクト: gurch101/shuup
def test_as_rounded_rounding_mode():
    set_precision_provider(babel_precision_provider.get_precision)

    prec2 = Decimal('0.01')
    m1 = Money('2.345', 'EUR')
    m2 = Money('2.344', 'EUR')

    assert m1.as_rounded(2).value == Decimal('2.34')
    assert m2.as_rounded(2).value == Decimal('2.34')

    from decimal import ROUND_HALF_DOWN, ROUND_HALF_UP, ROUND_FLOOR

    assert m1.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal('2.34')
    assert m2.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal('2.34')
    assert m1.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal('2.35')
    assert m2.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal('2.34')
    assert m1.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal('2.34')
    assert m2.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal('2.34')
コード例 #14
0
ファイル: test_money.py プロジェクト: suutari/shoop
def test_as_rounded_rounding_mode():
    set_precision_provider(babel_precision_provider.get_precision)

    prec2 = Decimal("0.01")
    m1 = Money("2.345", "EUR")
    m2 = Money("2.344", "EUR")

    assert m1.as_rounded(2).value == Decimal("2.34")
    assert m2.as_rounded(2).value == Decimal("2.34")

    from decimal import ROUND_HALF_DOWN, ROUND_HALF_UP, ROUND_FLOOR

    assert m1.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal("2.34")
    assert m2.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal("2.34")
    assert m1.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal("2.35")
    assert m2.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal("2.34")
    assert m1.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal("2.34")
    assert m2.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal("2.34")
コード例 #15
0
def test_as_rounded_rounding_mode():
    set_precision_provider(babel_precision_provider.get_precision)

    prec2 = Decimal('0.01')
    m1 = Money('2.345', 'EUR')
    m2 = Money('2.344', 'EUR')

    assert m1.as_rounded(2).value == Decimal('2.34')
    assert m2.as_rounded(2).value == Decimal('2.34')

    from decimal import ROUND_HALF_DOWN, ROUND_HALF_UP, ROUND_FLOOR

    assert m1.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal('2.34')
    assert m2.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal('2.34')
    assert m1.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal('2.35')
    assert m2.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal('2.34')
    assert m1.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal('2.34')
    assert m2.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal('2.34')
コード例 #16
0
def test_as_rounded_rounding_mode():
    set_precision_provider(babel_precision_provider.get_precision)

    prec2 = Decimal("0.01")
    m1 = Money("2.345", "EUR")
    m2 = Money("2.344", "EUR")

    assert m1.as_rounded(2).value == Decimal("2.34")
    assert m2.as_rounded(2).value == Decimal("2.34")

    from decimal import ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_UP

    assert m1.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal("2.34")
    assert m2.as_rounded(2, rounding=ROUND_HALF_DOWN).value == Decimal("2.34")
    assert m1.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal("2.35")
    assert m2.as_rounded(2, rounding=ROUND_HALF_UP).value == Decimal("2.34")
    assert m1.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal("2.34")
    assert m2.as_rounded(2, rounding=ROUND_FLOOR).value == Decimal("2.34")
コード例 #17
0
def test_as_rounded_values(currency, digits):
    set_precision_provider(babel_precision_provider.get_precision)

    amounts = [
        "1",
        "2",
        "3",
        "4",
        "1.23223",
        "12.24442",
        "42.26233",
        "1223.46636",
        "13.24655",
        "411.234554",
        "101.74363",
        "12.99346",
        "4222.57422",
        "112.93549",
        "199.2446",
        "422.29234",
        "1994.49654",
        "940.23452",
        "425.24566",
        "1994.496541234566",
        "940.2345298765",
        "425.2456612334",
    ]

    for amount in amounts:
        precision = Decimal("0.1")**digits

        rounded = Decimal(amount).quantize(precision)
        rounded2 = Decimal(amount).quantize(Decimal("0.01"))
        rounded3 = Decimal(amount).quantize(Decimal("0.001"))

        # test using the currency
        assert Money(amount, currency).as_rounded().value == rounded

        # test using digits
        assert Money(amount, currency).as_rounded(3).value == rounded3

        # test using not existent currency code
        assert Money(amount, "XTS").as_rounded().value == rounded2
コード例 #18
0
ファイル: test_money.py プロジェクト: suutari/shoop
def test_as_rounded_values(currency, digits):
    set_precision_provider(babel_precision_provider.get_precision)

    amounts = [
        "1",
        "2",
        "3",
        "4",
        "1.23223",
        "12.24442",
        "42.26233",
        "1223.46636",
        "13.24655",
        "411.234554",
        "101.74363",
        "12.99346",
        "4222.57422",
        "112.93549",
        "199.2446",
        "422.29234",
        "1994.49654",
        "940.23452",
        "425.24566",
        "1994.496541234566",
        "940.2345298765",
        "425.2456612334",
    ]

    for amount in amounts:
        precision = Decimal("0.1") ** digits

        rounded = Decimal(amount).quantize(precision)
        rounded2 = Decimal(amount).quantize(Decimal("0.01"))
        rounded3 = Decimal(amount).quantize(Decimal("0.001"))

        # test using the currency
        assert Money(amount, currency).as_rounded().value == rounded

        # test using digits
        assert Money(amount, currency).as_rounded(3).value == rounded3

        # test using not existent currency code
        assert Money(amount, "XTS").as_rounded().value == rounded2
コード例 #19
0
ファイル: __init__.py プロジェクト: suutari-ai/shuup
    def ready(self):
        from django.conf import settings
        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException("PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision
        money.set_precision_provider(get_currency_precision)

        if django.conf.settings.SHUUP_ERROR_PAGE_HANDLERS_SPEC:
            from .error_handling import install_error_handlers
            install_error_handlers()

        from shuup.core.utils.context_cache import (
            bump_product_signal_handler, bump_shop_product_signal_handler
        )
        from shuup.core.models import Product, ShopProduct
        from django.db.models.signals import m2m_changed
        m2m_changed.connect(
            bump_shop_product_signal_handler,
            sender=ShopProduct.categories.through,
            dispatch_uid="shop_product:clear_shop_product_cache"
        )
        from django.db.models.signals import post_save
        post_save.connect(
            bump_product_signal_handler,
            sender=Product,
            dispatch_uid="product:bump_product_cache"
        )
        post_save.connect(
            bump_shop_product_signal_handler,
            sender=ShopProduct,
            dispatch_uid="shop_product:bump_shop_product_cache"
        )

        # extends SQLite with necessary functions
        from django.db.backends.signals import connection_created
        from shuup.core.utils.db import extend_sqlite_functions
        connection_created.connect(extend_sqlite_functions)
コード例 #20
0
    def ready(self):
        from django.conf import settings
        if not getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None):
            raise MissingSettingException(
                "PARLER_DEFAULT_LANGUAGE_CODE must be set.")
        if not getattr(settings, "PARLER_LANGUAGES", None):
            raise MissingSettingException("PARLER_LANGUAGES must be set.")

        # set money precision provider function
        from .models import get_currency_precision
        money.set_precision_provider(get_currency_precision)

        if django.conf.settings.SHUUP_ERROR_PAGE_HANDLERS_SPEC:
            from .error_handling import install_error_handlers
            install_error_handlers()

        from shuup.core.utils.context_cache import (
            bump_product_signal_handler, bump_shop_product_signal_handler)
        from shuup.core.models import Product, ShopProduct
        from django.db.models.signals import m2m_changed
        m2m_changed.connect(
            bump_shop_product_signal_handler,
            sender=ShopProduct.categories.through,
            dispatch_uid="shop_product:clear_shop_product_cache")
        from django.db.models.signals import post_save
        post_save.connect(bump_product_signal_handler,
                          sender=Product,
                          dispatch_uid="product:bump_product_cache")
        post_save.connect(bump_shop_product_signal_handler,
                          sender=ShopProduct,
                          dispatch_uid="shop_product:bump_shop_product_cache")

        # extends SQLite with necessary functions
        from django.db.backends.signals import connection_created
        from shuup.core.utils.db import extend_sqlite_functions
        connection_created.connect(extend_sqlite_functions)
コード例 #21
0
ファイル: test_currencies.py プロジェクト: ruqaiya/shuup
def test_currency_precision_provider_is_acceptable():
    money.set_precision_provider(get_currency_precision)
コード例 #22
0
def test_set_precision_provider_with_non_callable():
    with pytest.raises(AssertionError):
        set_precision_provider(3)
コード例 #23
0
ファイル: test_money.py プロジェクト: gurch101/shuup
def test_set_precision_provider_with_non_callable():
    with pytest.raises(AssertionError):
        set_precision_provider(3)
コード例 #24
0
def setup_module(module):
    # uses the get_precision to avoiding db hits
    set_precision_provider(babel_precision_provider.get_precision)
コード例 #25
0
def setup_module(module):
    settings.SHUUP_TAX_MODULE = "dummy_tax_module"
    tax_mod_overrider.__enter__()

    # uses the get_precision to avoid db hits
    set_precision_provider(babel_precision_provider.get_precision)
コード例 #26
0
ファイル: test_utils_prices.py プロジェクト: gurch101/shuup
def setup_module(module):
    settings.SHUUP_TAX_MODULE = "dummy_tax_module"
    tax_mod_overrider.__enter__()

    # uses the get_precision to avoid db hits
    set_precision_provider(babel_precision_provider.get_precision)
コード例 #27
0
def test_currency_precision_provider_is_acceptable():
    money.set_precision_provider(get_currency_precision)
コード例 #28
0
ファイル: test_priceful.py プロジェクト: ruqaiya/shuup
def setup_module(module):
    # uses the get_precision to avoiding db hits
    set_precision_provider(babel_precision_provider.get_precision)