本文整理汇总了Python中shoop_tests.campaigns.initialize_test函数的典型用法代码示例。如果您正苦于以下问题:Python initialize_test函数的具体用法?Python initialize_test怎么用?Python initialize_test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了initialize_test函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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")
开发者ID:00WhengWheng,项目名称:shuup,代码行数:25,代码来源:test_catalog_campaigns.py
示例2: 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 atleast 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", discount_percentage=discount_percentage, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2
assert basket.product_count == 1
assert basket.total_price == expected_discounted_price
开发者ID:luizgustavo90,项目名称:shoop,代码行数:27,代码来源:test_basket_campaigns.py
示例3: 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", discount_percentage="0.1", coupon=coupon
)
source.add_code(coupon.code)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = creator.create_order(source)
assert CouponUsage.objects.count() == 1
开发者ID:luizgustavo90,项目名称:shoop,代码行数:29,代码来源:test_basket_campaigns.py
示例4: test_only_best_price_affects
def test_only_best_price_affects(rf):
activate("en")
discount_amount = "20.53"
original_price = "199.20"
best_discount_amount = "40.00"
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", discount_amount_value=discount_amount, active=True)
campaign.conditions.add(rule1)
campaign.filters.add(rule2)
campaign.save()
rule3, rule4 = create_condition_and_filter(cat, request)
campaign = CatalogCampaign.objects.create(shop=shop, name="test", discount_amount_value=best_discount_amount, active=True)
campaign.conditions.add(rule3)
campaign.filters.add(rule4)
campaign.save()
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, discount should be given
assert product.get_price_info(request, quantity=1).price == (price(original_price) - price(best_discount_amount))
开发者ID:MIKNOTAURO,项目名称:shoop,代码行数:35,代码来源:test_catalog_campaigns.py
示例5: test_percentage_campaigns
def test_percentage_campaigns(rf):
activate("en")
discount_percentage = "0.14"
original_price = "123.47"
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()
cdp = ProductDiscountPercentage.objects.create(campaign=campaign, discount_percentage=discount_percentage)
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, discount should be given
discounted_price = price(original_price) - (price(original_price) * Decimal(cdp.value))
assert product.get_price_info(request, quantity=1).price == discounted_price
开发者ID:00WhengWheng,项目名称:shuup,代码行数:33,代码来源:test_catalog_campaigns.py
示例6: test_minimum_price_is_forced
def test_minimum_price_is_forced(rf):
activate("en")
discount_amount = "20.53"
original_price = "199.20"
allowed_minimum_price = "190.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.minimum_price = price(allowed_minimum_price)
shop_product.save()
# 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.categories.add(cat)
shop_product.save()
# now the category is set, so both rules match, discount should be given
assert product.get_price_info(request, quantity=1).price == shop_product.minimum_price
开发者ID:00WhengWheng,项目名称:shuup,代码行数:30,代码来源:test_catalog_campaigns.py
示例7: 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
开发者ID:00WhengWheng,项目名称:shuup,代码行数:25,代码来源:test_filters.py
示例8: 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))
开发者ID:00WhengWheng,项目名称:shuup,代码行数:34,代码来源:test_catalog_campaigns.py
示例9: 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",
discount_percentage="0.1",
coupon=None)
second_campaign = BasketCampaign.objects.create(
active=True,
shop=shop,
name="test1",
public_name="test1",
discount_percentage="0.1",
coupon=None)
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()
开发者ID:NARESHARADHYULA,项目名称:shoop,代码行数:32,代码来源:test_basket_campaigns.py
示例10: test_basket_campaign_module_case1
def test_basket_campaign_module_case1(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = "50"
discount_amount_value = "10"
# create basket rule that requires 2 products in basket
basket_rule1 = BasketTotalProductAmountCondition.objects.create(value="2")
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert basket.product_count == 1
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount_amount_value, active=True)
campaign.conditions.add(basket_rule1)
campaign.save()
assert len(basket.get_final_lines()) == 1 # case 1
assert basket.total_price == price(single_product_price) # case 1
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert len(basket.get_final_lines()) == 2 # case 1
assert basket.product_count == 2
assert basket.total_price == (price(single_product_price) * basket.product_count - price(discount_amount_value))
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
开发者ID:NARESHARADHYULA,项目名称:shoop,代码行数:35,代码来源:test_basket_campaigns.py
示例11: 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)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount1, active=True
)
campaign.conditions.add(rule)
campaign.save()
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount2, active=True
)
campaign.conditions.add(rule)
campaign.save()
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)
开发者ID:luizgustavo90,项目名称:shoop,代码行数:35,代码来源:test_basket_campaigns.py
示例12: 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
开发者ID:NinaWelch,项目名称:shoop,代码行数:25,代码来源:test_order_edit_with_coupons.py
示例13: test_campaign_save_validation
def test_campaign_save_validation(rf):
# Discount percentage, or Discount amount in shop currency
request, shop, group = initialize_test(rf, False)
with pytest.raises(ValidationError):
campaign = CatalogCampaign.objects.create(shop=shop, name="test", discount_amount_value="20", discount_percentage="0.20")
with pytest.raises(ValidationError):
campaign = CatalogCampaign.objects.create(shop=shop, name="test")
开发者ID:MIKNOTAURO,项目名称:shoop,代码行数:8,代码来源:test_catalog_campaigns.py
示例14: test_condition_doesnt_match
def test_condition_doesnt_match(rf):
activate("en")
request, shop, group = initialize_test(rf, False)
condition = ContactGroupCondition.objects.create()
condition.contact_groups = [get_default_customer_group()]
condition.save()
request.customer = None
assert not condition.matches(request)
开发者ID:00WhengWheng,项目名称:shuup,代码行数:10,代码来源:test_catalog_campaigns.py
示例15: test_start_end_dates
def test_start_end_dates(rf):
activate("en")
original_price = "180"
discounted_price = "160"
request, shop, group = initialize_test(rf, False)
cat = Category.objects.create(name="test")
rule1, rule2 = create_condition_and_filter(cat, request)
discount_amount = 20
campaign = CatalogCampaign.objects.create(shop=shop, name="test", active=True)
campaign.conditions.add(rule1)
campaign.save()
ProductDiscountAmount.objects.create(discount_amount=discount_amount, campaign=campaign)
price = shop.create_price
product = create_product("Just-A-Product-Too", shop, default_price=original_price)
today = now()
# starts in future
campaign.start_datetime = (today + datetime.timedelta(days=2))
campaign.save()
assert not campaign.is_available()
assert product.get_price_info(request, quantity=1).price == price(original_price)
# has already started
campaign.start_datetime = (today - datetime.timedelta(days=2))
campaign.save()
assert product.get_price_info(request, quantity=1).price == price(discounted_price)
# already ended
campaign.end_datetime = (today - datetime.timedelta(days=1))
campaign.save()
assert not campaign.is_available()
assert product.get_price_info(request, quantity=1).price == price(original_price)
# not ended yet
campaign.end_datetime = (today + datetime.timedelta(days=1))
campaign.save()
assert product.get_price_info(request, quantity=1).price == price(discounted_price)
# no start datetime
campaign.start_datetime = None
campaign.save()
assert product.get_price_info(request, quantity=1).price == price(discounted_price)
# no start datetime but ended
campaign.end_datetime = (today - datetime.timedelta(days=1))
campaign.save()
assert not campaign.is_available()
assert product.get_price_info(request, quantity=1).price == price(original_price)
开发者ID:00WhengWheng,项目名称:shuup,代码行数:54,代码来源:test_catalog_campaigns.py
示例16: test_availability
def test_availability(rf):
activate("en")
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", discount_amount_value="20", active=False)
campaign.conditions.add(rule1)
campaign.save()
assert not campaign.is_available()
开发者ID:MIKNOTAURO,项目名称:shoop,代码行数:11,代码来源:test_catalog_campaigns.py
示例17: test_basket_total_amount_condition
def test_basket_total_amount_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 = BasketTotalAmountCondition.objects.create()
condition.value = 1
condition.save()
assert condition.value == 1
assert condition.matches(basket, [])
开发者ID:monokrome,项目名称:shuup,代码行数:14,代码来源:test_basket_product_conditions.py
示例18: test_basket_total_value_condition
def test_basket_total_value_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 = BasketTotalProductAmountCondition.objects.create()
condition.value = 1
condition.save()
assert condition.value == 1
assert condition.matches(basket, [])
assert "basket has at least the product count entered here" in force_text(condition.description)
开发者ID:monokrome,项目名称:shuup,代码行数:15,代码来源:test_basket_product_conditions.py
示例19: 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, [])
开发者ID:monokrome,项目名称:shuup,代码行数:16,代码来源:test_basket_product_conditions.py
示例20: test_basket_campaign_case2
def test_basket_campaign_case2(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")
single_product_price = "50"
discount_amount_value = "10"
unique_shipping_method = ShippingMethod(tax_class=get_default_tax_class(), module_data={"price": 50})
unique_shipping_method.save()
for x in range(3):
product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price
)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert basket.product_count == 3
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount_amount_value, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 3
assert basket.total_price == price(single_product_price) * basket.product_count
# check that shipping method affects campaign
basket.shipping_method = unique_shipping_method
basket.save()
basket.uncache()
assert len(basket.get_final_lines()) == 4 # Shipping should not affect the rule being triggered
line_types = [l.type for l in basket.get_final_lines()]
assert OrderLineType.DISCOUNT not in line_types
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert len(basket.get_final_lines()) == 6 # Discount included
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
开发者ID:luizgustavo90,项目名称:shoop,代码行数:47,代码来源:test_basket_campaigns.py
注:本文中的shoop_tests.campaigns.initialize_test函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论