Exemple #1
0
def test_protected_fields():
    activate("en")
    shop = Shop.objects.create(
        name="testshop",
        identifier="testshop",
        status=ShopStatus.ENABLED,
        public_name="test shop",
        domain="derp",
        currency="EUR"
    )
    get_currency("EUR")
    get_currency("USD")
    assert shop.name == "testshop"
    assert shop.currency == "EUR"
    assert not ConfigurationItem.objects.filter(shop=shop, key="languages").exists()
    shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES)
    assert not shop_form._get_protected_fields()  # No protected fields just yet, right?
    data = get_form_data(shop_form, prepared=True)
    shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
    _test_cleanliness(shop_form)
    shop_form.save()

    # Now let's make it protected!
    create_product(printable_gibberish(), shop=shop, supplier=get_default_supplier())
    order = create_random_order(customer=create_random_person(), shop=shop)
    assert order.shop == shop

    # And try again...
    data["currency"] = "USD"
    shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
    assert shop_form._get_protected_fields()  # So protected!
    _test_cleanliness(shop_form)
    shop = shop_form.save()
    assert shop.currency == "EUR"  # But the shop form ignored the change . . .
Exemple #2
0
def test_shop_wizard_pane(rf, admin_user, settings):
    settings.SHUUP_SETUP_WIZARD_PANE_SPEC = [
        "shuup.admin.modules.shops.views:ShopWizardPane"
    ]
    shop = Shop.objects.create()
    get_currency("USD")
    assert not shop.contact_address
    assert not TaxClass.objects.exists()
    fields = _extract_fields(rf, admin_user)
    fields["shop-logo"] = ""  # Correct init value for this is not None, but empty string
    request = apply_request_middleware(rf.post("/", data=fields), user=admin_user)
    response = WizardView.as_view()(request)
    # fields are missing
    assert response.status_code == 400
    fields["shop-public_name__fi"] = "test shop"
    fields["shop-currency"] = "USD"
    fields["address-name"] = "TEST"
    fields["address-city"] = "TEST"
    fields["address-region_code"] = "CA"
    fields["address-street"] = "test"
    fields["address-country"] = "US"

    request = apply_request_middleware(rf.post("/", data=fields), user=admin_user)
    response = WizardView.as_view()(request)
    assert response.status_code == 200
    shop.refresh_from_db()
    shop.set_current_language("fi")
    assert shop.name == "test shop"
    assert shop.public_name == "test shop"
    assert shop.logo is None
    assert shop.contact_address
    assert shop.currency == "USD"
    assert TaxClass.objects.exists()
    assert_redirect_to_dashboard(rf)
Exemple #3
0
def test_protected_fields():
    activate("en")
    shop = Shop.objects.create(
        name="testshop",
        identifier="testshop",
        status=ShopStatus.ENABLED,
        public_name="test shop",
        domain="derp",
        currency="EUR"
    )
    get_currency("EUR")
    get_currency("USD")
    assert shop.name == "testshop"
    assert shop.currency == "EUR"
    assert not ConfigurationItem.objects.filter(shop=shop, key="languages").exists()
    shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES)
    assert not shop_form._get_protected_fields()  # No protected fields just yet, right?
    data = get_form_data(shop_form, prepared=True)
    shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
    _test_cleanliness(shop_form)
    shop_form.save()

    # Now let's make it protected!
    create_product(printable_gibberish(), shop=shop, supplier=get_default_supplier())
    order = create_random_order(customer=create_random_person(), shop=shop)
    assert order.shop == shop

    # And try again...
    data["currency"] = "USD"
    shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
    assert shop_form._get_protected_fields()  # So protected!
    _test_cleanliness(shop_form)
    shop = shop_form.save()
    assert shop.currency == "EUR"  # But the shop form ignored the change . . .
Exemple #4
0
def test_currency_precision_provider_override():
    currency_usd = get_currency("USD")
    currency_usd.decimal_places = 6
    currency_usd.save()
    assert get_currency_precision('USD') == Decimal('0.000001')
    assert currency_usd.decimal_places == 6

    # change it and check if the precision provider has updated
    currency_usd.decimal_places = 2
    currency_usd.save()
    assert get_currency_precision('USD') == Decimal('0.01')
Exemple #5
0
def test_currency_precision_provider_override():
    currency_usd = get_currency("USD")
    currency_usd.decimal_places = 6
    currency_usd.save()
    assert get_currency_precision('USD') == Decimal('0.000001')
    assert currency_usd.decimal_places == 6

    # change it and check if the precision provider has updated
    currency_usd.decimal_places = 2
    currency_usd.save()
    assert get_currency_precision('USD') == Decimal('0.01')
Exemple #6
0
def test_currency_precision_provider_basics():
    get_currency('USD', 2)
    get_currency('EUR', 2)
    get_currency('JPY', 0)
    assert get_currency_precision('USD') == Decimal('0.01')
    assert get_currency_precision('EUR') == Decimal('0.01')
    assert get_currency_precision('JPY') == Decimal('1')
Exemple #7
0
def test_currency_precision_provider_basics():
    get_currency('USD', 2)
    get_currency('EUR', 2)
    get_currency('JPY', 0)
    assert get_currency_precision('USD') == Decimal('0.01')
    assert get_currency_precision('EUR') == Decimal('0.01')
    assert get_currency_precision('JPY') == Decimal('1')
Exemple #8
0
def test_currency_precision_provider_basics():
    get_currency("USD", 2)
    get_currency("EUR", 2)
    get_currency("JPY", 0)
    assert get_currency_precision("USD") == Decimal("0.01")
    assert get_currency_precision("EUR") == Decimal("0.01")
    assert get_currency_precision("JPY") == Decimal("1")