def test_clear_prices(): product = _get_test_product() # We can clear the prices out, can't we? form_data = {} frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert not SimpleProductPrice.objects.filter(product=product).exists()
def test_basic_form_sanity(): shop = get_default_shop() group = get_default_customer_group() product = _get_test_product() frm = SimplePricingForm(product=product, empty_permitted=True) assert len(frm.groups) == ContactGroup.objects.count() assert len(frm.shops) == Shop.objects.count() assert "s_%d_g_%d" % (shop.id, group.id) in frm.fields
def test_no_changes_into_form(): product = _get_test_product() shop = get_default_shop() frm = SimplePricingForm(product=product, empty_permitted=True) # No changes made, right? form_data = get_form_data(frm, prepared=True) frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=shop).price == 250
def test_basic_form_sanity(): shop = get_default_shop() group = get_default_customer_group() product = _get_test_product() frm = SimplePricingForm(product=product, empty_permitted=True) assert len(frm.groups) == 1 + ContactGroup.objects.count() assert len(frm.shops) == 1 + Shop.objects.count() for shop_id in (0, shop.id): for group_id in (0, group.id): assert "s_%d_g_%d" % (shop_id, group_id) in frm.fields form_data = get_form_data(frm) assert form_data["s_%d_g_0" % shop.id] == 250 assert form_data["s_0_g_0"] == 200
def test_no_changes_into_form(): product = _get_test_product() shop = get_default_shop() frm = SimplePricingForm(product=product, empty_permitted=True) # No changes made, right? form_data = get_form_data(frm, prepared=True) frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=shop).price.value == 250
def test_change_shop_price(): product = _get_test_product() shop = get_default_shop() group = get_default_customer_group() form_field = "s_%d_g_%d" % (shop.id, group.id) frm = SimplePricingForm(product=product, empty_permitted=True) form_data = get_form_data(frm, prepared=True) # Price hike time! form_data[form_field] = "4000" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=shop, group=group).price == 4000 # Never mind actually, same price for all shops form_data[form_field] = "" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert not SimpleProductPrice.objects.filter( product=product, shop=shop, group=group).exists()
def test_change_shop_price(): product = _get_test_product() shop = get_default_shop() group = get_default_customer_group() price = shop.create_price form_field = "s_%d_g_%d" % (shop.id, group.id) frm = SimplePricingForm(product=product, empty_permitted=True) form_data = get_form_data(frm, prepared=True) # Price hike time! form_data[form_field] = "4000" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=shop, group=group).price == price(4000) # Never mind actually, same price for all shops form_data[form_field] = "" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert not SimpleProductPrice.objects.filter(product=product, shop=shop, group=group).exists()
def test_change_shop_price(): product = _get_test_product() shop = get_default_shop() frm = SimplePricingForm(product=product, empty_permitted=True) form_data = get_form_data(frm, prepared=True) # Price hike time! form_data["s_%d_g_0" % shop.id] = "4000" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=None).price == 200 assert SimpleProductPrice.objects.get(product=product, shop=shop).price == 4000 # Never mind actually, same price for all shops form_data["s_%d_g_0" % shop.id] = "" frm = SimplePricingForm(product=product, data=form_data, empty_permitted=True) frm.full_clean() frm.save() assert SimpleProductPrice.objects.get(product=product, shop=None).price == 200 assert not SimpleProductPrice.objects.filter(product=product, shop=shop).exists()