本文整理汇总了Python中shuup.testing.factories.get_default_product函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_product函数的具体用法?Python get_default_product怎么用?Python get_default_product使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_product函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_order_creator_account_manager
def test_order_creator_account_manager():
company = create_random_company()
shop = get_shop(identifier="random-shop", enabled=True)
source = seed_source(create_random_user(), shop)
source.customer = company
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is None # Company contact doesn't have account manager field
person = create_random_person()
person.account_manager = create_random_person()
person.save()
source = seed_source(create_random_user(), shop)
source.customer = person
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is not None
assert order.account_manager == person.account_manager
with pytest.raises(ProtectedError):
person.account_manager.delete()
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_order_creator.py
示例2: test_parallel_baskets
def test_parallel_baskets(rf):
request = get_request_with_basket()
shop = get_default_shop()
customer = create_random_person()
request = rf.get("/")
request.shop = shop
apply_request_middleware(request)
request.customer = customer
basket_one = get_basket(request, basket_name="basket_one")
basket_two = get_basket(request, basket_name="basket_two")
product_one = get_default_product()
product_two = get_default_product()
product_two.sku = "derpy-hooves"
sales_unit = SalesUnit.objects.create(identifier="test-sales-partial", decimals=2, name="Partial unit")
product_two.sales_unit = sales_unit # Set the sales unit for the product
product_two.save()
basket_commands.handle_add(request, basket_one, product_id=product_one.pk, quantity=1)
basket_commands.handle_add(request, basket_two, product_id=product_two.pk, quantity=3.5)
assert basket_one.product_count == 1
assert basket_two.product_count == 3.5
开发者ID:suutari-ai,项目名称:shuup,代码行数:25,代码来源:test_basket_commands.py
示例3: get_initialized_test_event
def get_initialized_test_event():
get_default_product()
customer = create_random_person()
order = create_random_order(customer)
return ATestEvent(
order_language=order.language,
order=order,
just_some_text=random_title()
)
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:fixtures.py
示例4: test_refunds
def test_refunds(browser, admin_user, live_server, settings):
order = create_order_with_product(
get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
shop=get_default_shop())
order2 = create_order_with_product(
get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
shop=get_default_shop())
order2.create_payment(order2.taxful_total_price)
initialize_admin_browser_test(browser, live_server, settings)
_test_toolbar_visibility(browser, live_server, order)
_test_create_full_refund(browser, live_server, order)
_test_refund_view(browser, live_server, order2)
开发者ID:suutari,项目名称:shoop,代码行数:12,代码来源:test_refunds.py
示例5: test_broken_order_lines
def test_broken_order_lines():
with pytest.raises(ValidationError):
OrderLine(type=OrderLineType.PRODUCT).save()
with pytest.raises(ValidationError):
OrderLine(product=get_default_product(), type=OrderLineType.PRODUCT, supplier=None).save()
with pytest.raises(ValidationError):
OrderLine(product=get_default_product(), type=OrderLineType.OTHER).save()
with pytest.raises(ValidationError):
OrderLine(product=get_default_product(), type=OrderLineType.OTHER).save()
开发者ID:ruqaiya,项目名称:shuup,代码行数:12,代码来源:test_orders.py
示例6: test_order_received
def test_order_received(rf, regular_user):
activate("en")
get_default_product()
get_default_supplier()
get_test_script("test script", "order_received")
template_data = STEP_DATA[0]["actions"][0]["template_data"]
for lang in ["en", "fi"]:
n_outbox_pre = len(mail.outbox)
customer = create_random_person(locale=lang)
create_random_order(customer)
assert (len(mail.outbox) == n_outbox_pre + 1), "Sending email failed"
latest_mail = mail.outbox[-1]
assert latest_mail.subject == template_data[lang]["subject"], "Subject doesn't match"
assert latest_mail.body == template_data[lang]["body"], "Body doesn't match"
开发者ID:ruqaiya,项目名称:shuup,代码行数:15,代码来源:test_order_notifications.py
示例7: test_applied_attributes
def test_applied_attributes():
product = get_default_product()
for spec in ATTR_SPECS: # This loop sets each attribute twice. That's okay.
attr = Attribute.objects.get(identifier=spec["identifier"])
pa, _ = ProductAttribute.objects.get_or_create(product=product, attribute=attr)
_populate_applied_attribute(pa)
pa.save()
if not attr.is_translated:
product.set_attribute_value(attr.identifier, pa.value)
assert product.get_attribute_value("bogomips") == 320, "integer attribute loaded neatly"
product.set_attribute_value("bogomips", 480)
assert product.get_attribute_value("bogomips") == 480, "integer attribute updated neatly"
Product.cache_attributes_for_targets(
applied_attr_cls=ProductAttribute,
targets=[product],
attribute_identifiers=[a["identifier"] for a in ATTR_SPECS],
language=get_language()
)
assert (get_language(), "bogomips",) in product._attr_cache, "integer attribute in cache"
assert product.get_attribute_value("bogomips") == 480, "integer attribute value in cache"
assert product.get_attribute_value("ba:gelmips", default="Britta") == "Britta", "non-existent attributes return default value"
assert product._attr_cache[(get_language(), "ba:gelmips")] is NoSuchAttributeHere, "cache miss saved"
attr_info = product.get_all_attribute_info(language=get_language(), visibility_mode=AttributeVisibility.SHOW_ON_PRODUCT_PAGE)
assert set(attr_info.keys()) <= set(a["identifier"] for a in ATTR_SPECS), "get_all_attribute_info gets all attribute info"
开发者ID:suutari-ai,项目名称:shuup,代码行数:25,代码来源:test_attributes.py
示例8: test_add_and_remove_and_clear
def test_add_and_remove_and_clear():
product = get_default_product()
supplier = get_default_supplier()
request = get_request_with_basket()
basket = request.basket
with pytest.raises(ValidationError):
basket_commands.handle_add(request, basket, product_id=product.pk, quantity=-3) # Ordering antimatter is not supported
# These will get merged into one line...
basket_commands.handle_add(request, basket, **{"product_id": product.pk, "quantity": 1, "supplier_id": supplier.pk})
basket_commands.handle_add(request, basket, **{"product_id": product.pk, "quantity": 2})
# ... so there will be 3 products but one line
assert basket.product_count == 3
lines = basket.get_lines()
assert len(lines) == 1
# ... and deleting that line will clear the basket...
basket_commands.handle_del(request, basket, lines[0].line_id)
assert basket.product_count == 0
# ... and adding another product will create a new line...
basket_commands.handle_add(request, basket, product_id=product.pk, quantity=1)
assert basket.product_count == 1
# ... that can be cleared.
basket_commands.handle_clear(request, basket)
assert basket.product_count == 0
开发者ID:suutari-ai,项目名称:shuup,代码行数:25,代码来源:test_basket_commands.py
示例9: test_report_writers
def test_report_writers():
"""
Just check whether something breaks while writing differnt types of data
"""
shop = get_default_shop()
product = get_default_product()
supplier = get_default_supplier()
order = create_order_with_product(
product=product, supplier=supplier, quantity=1, taxless_base_unit_price=10, tax_rate=0, n_lines=2, shop=shop)
order.create_payment(order.taxful_total_price.amount)
data = {
"report": SalesTestReport.get_name(),
"shop": shop.pk,
"date_range": DateRangeChoices.THIS_YEAR,
"writer": "html",
"force_download": 1,
}
report = SalesTestReport(**data)
for writer_cls in [ExcelReportWriter, PDFReportWriter, PprintReportWriter, HTMLReportWriter, JSONReportWriter]:
writer = writer_cls()
report_data = [
{
"date": order,
"order_count": Decimal(2),
"product_count": int(3),
"taxless_total": lazy(lambda: order.taxless_total_price_value),
"taxful_total": order.taxful_total_price,
}
]
writer.write_data_table(report, report_data)
assert writer.get_rendered_output()
开发者ID:ruqaiya,项目名称:shuup,代码行数:33,代码来源:test_reports.py
示例10: test_basket_partial_quantity_update
def test_basket_partial_quantity_update():
request = get_request_with_basket()
basket = request.basket
product = get_default_product()
sales_unit = SalesUnit.objects.create(identifier="test-sales-partial", decimals=2, name="Partial unit")
product.sales_unit = sales_unit # Set the sales unit for the product
product.save()
basket_commands.handle_add(request, basket, product_id=product.pk, quantity=1.5)
assert basket.product_count == 1.5
line_id = basket.get_lines()[0].line_id
basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "1.5"})
assert basket.product_count == 1.5
basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "3.5"})
assert basket.product_count == 3.5
basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "3.0"})
assert basket.product_count == 3.0
basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "4"})
assert basket.product_count == 4
basket_commands.handle_update(request, basket, **{"delete_%s" % line_id: "1"})
assert basket.product_count == 0
开发者ID:suutari-ai,项目名称:shuup,代码行数:26,代码来源:test_basket_commands.py
示例11: test_processor_orderability
def test_processor_orderability(admin_user):
source = OrderSource(Shop())
processor = OrderProcessor()
line = source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
shop=get_default_shop(),
base_unit_price=source.create_price(10),
)
line.order = Order(shop=get_default_shop())
assert processor._check_orderability(line) is None
unorderable_line = source.add_line(
type=OrderLineType.PRODUCT,
product=create_product("no-shop"),
supplier=get_default_supplier(),
quantity=1,
shop=get_default_shop(),
base_unit_price=source.create_price(20),
)
unorderable_line.order = Order(shop=get_default_shop())
with pytest.raises(ValidationError) as exc:
processor._check_orderability(unorderable_line)
assert "Not available in" in exc.value.message
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:test_order_creator.py
示例12: test_edit_view_adding_messages_to_form_group
def test_edit_view_adding_messages_to_form_group(rf, admin_user):
get_default_shop() # obvious prerequisite
product = get_default_product()
view = ProductEditView.as_view()
request = apply_request_middleware(rf.get("/"), user=admin_user)
response = view(request, pk=product.pk)
response.render()
assert 200 <= response.status_code < 300
assert ProductEditView.add_form_errors_as_messages
content = force_text(response.content)
post = extract_form_fields(BeautifulSoup(content))
post_data = {
# Error in the base form part
"base-name__en": "",
}
post.update(post_data)
request = apply_request_middleware(rf.post("/", post), user=admin_user)
response = view(request, pk=product.pk)
errors = response.context_data["form"].errors
assert "base" in errors
assert "name__en" in errors["base"]
开发者ID:gurch101,项目名称:shuup,代码行数:25,代码来源:test_views.py
示例13: test_custom_payment_processor_cash_service
def test_custom_payment_processor_cash_service(choice_identifier, expected_payment_status):
shop = get_default_shop()
product = get_default_product()
supplier = get_default_supplier()
processor = CustomPaymentProcessor.objects.create()
payment_method = PaymentMethod.objects.create(
shop=shop,
payment_processor=processor,
choice_identifier=choice_identifier,
tax_class=get_default_tax_class())
order = create_order_with_product(
product=product,
supplier=supplier,
quantity=1,
taxless_base_unit_price=Decimal('5.55'),
shop=shop)
order.taxful_total_price = TaxfulPrice(Decimal('5.55'), u'EUR')
order.payment_method = payment_method
order.save()
assert order.payment_status == PaymentStatus.NOT_PAID
processor.process_payment_return_request(choice_identifier, order, None)
assert order.payment_status == expected_payment_status
processor.process_payment_return_request(choice_identifier, order, None)
assert order.payment_status == expected_payment_status
开发者ID:suutari,项目名称:shoop,代码行数:26,代码来源:test_custom_payment_processor.py
示例14: test_tracking_codes
def test_tracking_codes():
product = get_default_product()
supplier = get_default_supplier()
order = create_order_with_product(
product,
supplier=supplier,
quantity=1,
taxless_base_unit_price=10,
tax_rate=decimal.Decimal("0.5")
)
_add_product_to_order(order, "duck-tape-1", 3, order.shop, supplier)
_add_product_to_order(order, "water-1", 2, order.shop, supplier)
order.cache_prices()
order.check_all_verified()
order.save()
# Create shipment with tracking code for every product line.
product_lines = order.lines.exclude(product_id=None)
assert len(product_lines) == 3
for line in product_lines:
shipment = order.create_shipment({line.product: line.quantity}, supplier=supplier)
if line.quantity != 3:
shipment.tracking_code = "123FI"
shipment.save()
tracking_codes = order.get_tracking_codes()
code_count = (len(product_lines)-1) # We skipped that one
assert len(tracking_codes) == code_count
assert len([tracking_code for tracking_code in tracking_codes if tracking_code == "123FI"]) == code_count
开发者ID:gurch101,项目名称:shuup,代码行数:30,代码来源:test_tracking_codes.py
示例15: 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
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:35,代码来源:test_basket_campaigns.py
示例16: test_delete_payment
def test_delete_payment(admin_user, rf):
product = get_default_product()
shop_product = product.get_shop_instance(get_default_shop())
shop_product.default_price_value = 20
shop_product.save()
order = create_random_order(customer=create_random_person(), products=(product,), completion_probability=0)
payment_amount = order.taxful_total_price_value
# create a payment
view = OrderCreatePaymentView.as_view()
request = apply_request_middleware(rf.post("/", {"amount": payment_amount}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code == 302
order.refresh_from_db()
assert order.is_paid()
# delete the payment
payment = order.payments.last()
view = OrderDeletePaymentView.as_view()
request = apply_request_middleware(rf.post("/", {"payment": payment.pk}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code == 302
order.refresh_from_db()
assert order.is_not_paid()
开发者ID:ruqaiya,项目名称:shuup,代码行数:27,代码来源:test_order_module.py
示例17: test_order_modifier
def test_order_modifier(rf, admin_user):
order, source = get_order_and_source(admin_user, get_default_product())
# get original values
taxful_total_price = order.taxful_total_price_value
taxless_total_price = order.taxless_total_price_value
original_line_count = order.lines.count()
# modify source
source.billing_address = MutableAddress.objects.create(name="New Billing")
source.shipping_address = MutableAddress.objects.create(name="New Shipping")
modifier = OrderModifier()
modifier.update_order_from_source(source, order) # new param to edit order from source
assert Order.objects.count() == 1
order = Order.objects.first()
assert order.billing_address.name == "New Billing"
assert order.shipping_address.name == "New Shipping"
assert order.taxful_total_price_value == taxful_total_price
assert order.taxless_total_price_value == taxless_total_price
# add new line to order source
source.add_line(
type=OrderLineType.OTHER,
quantity=1,
base_unit_price=source.create_price(10),
require_verification=True,
)
modifier.update_order_from_source(source, order)
assert order.lines.count() == original_line_count + 1
开发者ID:NamiStudio,项目名称:shuup,代码行数:34,代码来源:test_order_modifier.py
示例18: test_order_creator
def test_order_creator(rf, admin_user):
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,
)
creator = OrderCreator()
order = creator.create_order(source)
assert get_data_dict(source.billing_address) == get_data_dict(order.billing_address)
assert get_data_dict(source.shipping_address) == get_data_dict(order.shipping_address)
customer = source.customer
assert customer == order.customer
assert customer.groups.count() == 1
assert customer.groups.first() == order.customer_groups.first()
assert customer.tax_group is not None
assert customer.tax_group == order.tax_group
assert source.payment_method == order.payment_method
assert source.shipping_method == order.shipping_method
assert order.pk
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:test_order_creator.py
示例19: test_order_statuses
def test_order_statuses(admin_user):
create_default_order_statuses()
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,
)
creator = OrderCreator()
order = creator.create_order(source)
# new order, status/role is new/initial
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
# FUTURE: order gets payment the status changes to processing/processing
total = order.taxful_total_price.amount
order.create_payment(total)
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
# FUTURE: order is fully shipped the status changes to complete/complete
order.create_shipment_of_all_products()
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
开发者ID:suutari,项目名称:shoop,代码行数:35,代码来源:test_order_statuses.py
示例20: test_simple_search_get_ids_works
def test_simple_search_get_ids_works(rf):
cache.clear()
prod = get_default_product()
bit = prod.name[:5]
request = apply_request_middleware(rf.get("/"))
assert prod.pk in get_search_product_ids(request, bit)
assert prod.pk in get_search_product_ids(request, bit) # Should use cache
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:test_simple_search.py
注:本文中的shuup.testing.factories.get_default_product函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论