本文整理汇总了Python中shuup_tests.campaigns.initialize_test函数的典型用法代码示例。如果您正苦于以下问题:Python initialize_test函数的具体用法?Python initialize_test怎么用?Python initialize_test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了initialize_test函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basket_total_undiscounted_value_conditions
def test_basket_total_undiscounted_value_conditions(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product", shop, default_price="150", supplier=supplier)
discounted_product = create_product("Just-A-Second-Product", shop, default_price="200", supplier=supplier)
# CatalogCampaign
catalog_campaign = CatalogCampaign.objects.create(active=True, shop=shop, name="test", public_name="test")
# Limit catalog campaign to "discounted_product"
product_filter = ProductFilter.objects.create()
product_filter.products.add(discounted_product)
catalog_campaign.filters.add(product_filter)
basket.add_product(supplier=supplier, shop=shop, product=discounted_product, quantity=1)
condition = BasketTotalUndiscountedProductAmountCondition.objects.create()
condition.value = 1
condition.save()
assert not condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert condition.matches(basket, [])
# Too high amount for undiscounted value
condition.value = 151
condition.save()
assert not condition.matches(basket, [])
示例2: test_product_in_basket_condition_with_variation_parent
def test_product_in_basket_condition_with_variation_parent(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product(
"test-product", shop, default_price="200", supplier=supplier, mode=ProductMode.SIMPLE_VARIATION_PARENT)
child_products = []
for x in range(0, 3):
child_product = create_product("test-product-%s" % x, shop, default_price="10", supplier=supplier)
child_product.link_to_parent(product)
child_products.append(child_product)
condition = ProductsInBasketCondition.objects.create()
condition.values = [product]
condition.operator = ComparisonOperator.EQUALS
condition.quantity = 3
condition.save()
assert not condition.matches(basket, [])
for child_product in child_products:
basket.add_product(supplier=supplier, shop=shop, product=child_product, quantity=1)
assert condition.matches(basket, [])
示例3: test_price_cannot_be_under_zero
def test_price_cannot_be_under_zero(rf):
activate("en")
discount_amount = "200"
original_price = "199.20"
request, shop, group = initialize_test(rf, False)
cat = Category.objects.create(name="test")
rule1, rule2 = create_condition_and_filter(cat, request)
campaign = CatalogCampaign.objects.create(shop=shop, name="test", active=True)
campaign.conditions.add(rule1)
campaign.filters.add(rule2)
campaign.save()
ProductDiscountAmount.objects.create(campaign=campaign, discount_amount=discount_amount)
price = shop.create_price
product = create_product("Just-A-Product-Too", shop, default_price=original_price)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(cat)
shop_product.save()
assert product.get_price_info(request, quantity=1).price == price("0")
示例4: test_campaign_creation
def test_campaign_creation(rf):
activate("en")
request, shop, group = initialize_test(rf, False)
cat = Category.objects.create(name="test")
condition = ContactGroupCondition.objects.create()
condition.contact_groups = request.customer.groups.all()
condition.save()
assert condition.values.first() == request.customer.groups.first()
condition.values = request.customer.groups.all()
condition.save()
assert condition.values.first() == request.customer.groups.first()
category_filter = CategoryFilter.objects.create()
category_filter.categories.add(cat)
category_filter.save()
campaign = CatalogCampaign.objects.create(shop=shop, name="test", active=True)
campaign.conditions.add(condition)
campaign.filters.add(category_filter)
campaign.save()
ProductDiscountAmount.objects.create(campaign=campaign, discount_amount=20)
# Make sure disabling campaign disables it filters and conditions
assert campaign.filters.filter(active=True).exists()
assert campaign.conditions.filter(active=True).exists()
campaign.active = False
campaign.save()
assert not campaign.filters.filter(active=True).exists()
assert not campaign.conditions.filter(active=True).exists()
示例5: test_campaign_with_non_active_coupon
def test_campaign_with_non_active_coupon(rf):
initial_status = get_initial_order_status()
request, shop, group = initialize_test(rf, include_tax=False)
order = _get_order_with_coupon(request, initial_status)
coupon = order.coupon_usages.first().coupon
coupon.active = False
coupon.save()
modifier = UserFactory()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
assert order.customer != contact
state = _get_frontend_order_state(shop, contact)
assert order.shop.id == state["shop"]["selected"]["id"]
request = get_frontend_request_for_command(state, "finalize", modifier)
response = OrderEditView.as_view()(request, pk=order.pk)
assert_contains(response, "orderIdentifier")
data = json.loads(response.content.decode("utf8"))
edited_order = Order.objects.get(pk=order.pk)
assert edited_order.identifier == data["orderIdentifier"] == order.identifier
assert edited_order.pk == order.pk
assert edited_order.lines.count() == 3
assert OrderLineType.DISCOUNT not in [l.type for l in edited_order.lines.all()]
assert edited_order.coupon_usages.count() == 0
示例6: test_order_creation_adds_usage
def test_order_creation_adds_usage(rf, admin_user):
request, shop, group = initialize_test(rf, False)
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
source.add_line(
type=OrderLineType.OTHER,
quantity=1,
base_unit_price=source.create_price(10),
require_verification=True,
)
# add coupon
coupon = Coupon.objects.create(active=True, code="asdf")
campaign = BasketCampaign.objects.create(
active=True,
shop=shop,
name="test",
public_name="test",
coupon=coupon)
BasketDiscountPercentage.objects.create(campaign=campaign, discount_percentage="0.1")
source.add_code(coupon.code)
creator = OrderCreator()
creator.create_order(source)
assert CouponUsage.objects.count() == 1
示例7: test_coupon_uniqueness
def test_coupon_uniqueness(rf):
request, shop, group = initialize_test(rf, False)
first_campaign = BasketCampaign.objects.create(
active=True,
shop=shop,
name="test",
public_name="test",
coupon=None)
second_campaign = BasketCampaign.objects.create(
active=True,
shop=shop,
name="test1",
public_name="test1",
coupon=None)
BasketDiscountPercentage.objects.create(campaign=first_campaign, discount_percentage="0.1")
BasketDiscountPercentage.objects.create(campaign=second_campaign, discount_percentage="0.1")
coupon = Coupon.objects.create(active=True, code="test_code")
first_campaign.coupon = coupon
first_campaign.save()
first_form = BasketCampaignForm(instance=first_campaign, request=request)
assert len(first_form.fields["coupon"].choices) == 2 # coupon + empty
second_form = BasketCampaignForm(instance=second_campaign, request=request)
assert len(second_form.fields["coupon"].choices) == 1 # only empty
# Can't set coupon for second campaign since coupon is unique
with pytest.raises(IntegrityError):
second_campaign.coupon = coupon
second_campaign.save()
示例8: test_category_product_in_basket_condition
def test_category_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
category = get_default_category()
product = create_product("The Product", shop=shop, default_price="200", supplier=supplier)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
shop_product = product.get_shop_instance(shop)
assert category not in shop_product.categories.all()
condition = CategoryProductsBasketCondition.objects.create(
category=category, operator=ComparisonOperator.EQUALS, quantity=1)
# No match the product does not have the category
assert not condition.matches(basket, [])
shop_product.categories.add(category)
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
condition.operator = ComparisonOperator.GTE
condition.save()
assert condition.matches(basket, [])
示例9: test_percentage_campaign
def test_percentage_campaign(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires at least value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount_percentage = "0.1"
expected_discounted_price = price(product_price) - (price(product_price) * Decimal(discount_percentage))
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", active=True)
campaign.conditions.add(rule)
campaign.save()
BasketDiscountPercentage.objects.create(campaign=campaign, discount_percentage=discount_percentage)
assert len(basket.get_final_lines()) == 2
assert basket.product_count == 1
assert basket.total_price == expected_discounted_price
示例10: test_basket_total_amount_conditions
def test_basket_total_amount_conditions(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product-Too", shop, default_price="200")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
condition = BasketTotalAmountCondition.objects.create()
condition.value = 1
condition.save()
assert condition.value == 1
assert condition.matches(basket, [])
condition2 = BasketMaxTotalAmountCondition.objects.create()
condition2.value = 200
condition2.save()
assert condition2.matches(basket, [])
condition2.value = 199
condition2.save()
assert not condition2.matches(basket, [])
示例11: test_category_filter
def test_category_filter(rf):
request, shop, group = initialize_test(rf, False)
cat = get_default_category()
cat_filter = CategoryFilter.objects.create()
cat_filter.categories.add(cat)
cat_filter.save()
assert cat_filter.values.first() == cat
category = Category.objects.create(
parent=None,
identifier="testcat",
name="catcat",
)
cat_filter.values = [cat, category]
cat_filter.save()
assert cat_filter.values.count() == 2
product = create_product("Just-A-Product-Too", shop, default_price="200")
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(cat)
shop_product.save()
assert cat_filter.filter_queryset(ShopProduct.objects.all()).exists() # filter matches
示例12: test_only_cheapest_price_is_selected
def test_only_cheapest_price_is_selected(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount1 = "10"
discount2 = "20" # should be selected
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign1 = BasketCampaign.objects.create(shop=shop, public_name="test", name="test", active=True)
campaign1.conditions.add(rule)
campaign1.save()
BasketDiscountAmount.objects.create(discount_amount=discount1, campaign=campaign1)
campaign2 = BasketCampaign.objects.create(shop=shop, public_name="test", name="test", active=True)
campaign2.conditions.add(rule)
campaign2.save()
BasketDiscountAmount.objects.create(discount_amount=discount2, campaign=campaign2)
assert len(basket.get_final_lines()) == 2
line_types = [l.type for l in basket.get_final_lines()]
assert OrderLineType.DISCOUNT in line_types
for line in basket.get_final_lines():
if line.type == OrderLineType.DISCOUNT:
assert line.discount_amount == price(discount2)
示例13: test_campaign_all_rules_must_match1
def test_campaign_all_rules_must_match1(rf):
activate("en")
discount_amount = "20.53"
original_price = "199.20"
request, shop, group = initialize_test(rf, False)
cat = Category.objects.create(name="test")
rule1 = ContactGroupCondition.objects.create()
rule1.contact_groups = request.customer.groups.all()
rule1.save()
rule2 = CategoryFilter.objects.create()
rule2.categories.add(cat)
rule2.save()
campaign = CatalogCampaign.objects.create(shop=shop, name="test", active=True)
campaign.conditions.add(rule1)
campaign.filters.add(rule2)
campaign.save()
ProductDiscountAmount.objects.create(campaign=campaign, discount_amount=discount_amount)
product = create_product("Just-A-Product-Too", shop, default_price=original_price)
price = shop.create_price
# price should not be discounted because the request.category is faulty
assert product.get_price_info(request, quantity=1).price == price(original_price)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(cat)
shop_product.save()
# now the category is set, so both rules match, disconut should be given
assert product.get_price_info(request, quantity=1).price == (price(original_price) - price(discount_amount))
示例14: test_productfilter_works
def test_productfilter_works(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
product_price = "100"
discount_percentage = "0.30"
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
shop_product = product.get_shop_instance(shop)
# create catalog campaign
catalog_filter = ProductFilter.objects.create()
catalog_filter.products.add(product)
assert catalog_filter.matches(shop_product)
catalog_campaign = CatalogCampaign.objects.create(shop=shop, active=True, name="test")
catalog_campaign.filters.add(catalog_filter)
cdp = ProductDiscountPercentage.objects.create(campaign=catalog_campaign, discount_percentage=discount_percentage)
# add product to basket
basket = get_basket(request)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop)
basket.save()
expected_total = price(product_price) - (Decimal(discount_percentage) * price(product_price))
assert basket.total_price == expected_total
示例15: test_product_in_basket_condition
def test_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product-Too", shop, default_price="200")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
condition = ProductsInBasketCondition.objects.create()
condition.values = [product]
condition.save()
assert condition.values.first() == product
assert condition.matches(basket, [])
condition.quantity = 2
condition.save()
assert not condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert condition.matches(basket, [])
condition.operator = ComparisonOperator.EQUALS
condition.save()
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])