本文整理汇总了Python中shuup.testing.factories.create_empty_order函数的典型用法代码示例。如果您正苦于以下问题:Python create_empty_order函数的具体用法?Python create_empty_order怎么用?Python create_empty_order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_empty_order函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_by_identifier
def test_get_by_identifier(admin_user):
shop = get_default_shop()
for i in range(1,10):
order = create_empty_order(shop=shop)
order.save()
order = create_empty_order(shop=shop)
order.save()
client = _get_client(admin_user)
response = client.get("/api/shuup/order/", data={"identifier": order.identifier})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert order_data[0].get("id") == order.id
assert order_data[0].get("identifier") == order.identifier
示例2: test_process_payment_return_request
def test_process_payment_return_request(rf):
"""
Order payment with default payment method with ``CustomPaymentProcessor``
should be deferred.
Payment can't be processed if method doesn't have provider or provider
is not enabled or payment method is not enabled.
"""
pm = PaymentMethod.objects.create(
shop=get_default_shop(), name="Test method", enabled=False, tax_class=get_default_tax_class())
order = create_empty_order()
order.payment_method = pm
order.save()
assert order.payment_status == PaymentStatus.NOT_PAID
with pytest.raises(ValueError): # Can't process payment with unusable method
order.payment_method.process_payment_return_request(order, rf.get("/"))
assert order.payment_status == PaymentStatus.NOT_PAID
pm.payment_processor = get_custom_payment_processor()
pm.payment_processor.enabled = False
pm.save()
with pytest.raises(ValueError): # Can't process payment with unusable method
order.payment_method.process_payment_return_request(order, rf.get("/"))
assert order.payment_status == PaymentStatus.NOT_PAID
pm.payment_processor.enabled = True
pm.save()
with pytest.raises(ValueError): # Can't process payment with unusable method
order.payment_method.process_payment_return_request(order, rf.get("/"))
assert order.payment_status == PaymentStatus.NOT_PAID
pm.enabled = True
pm.save()
order.payment_method.process_payment_return_request(order, rf.get("/"))
assert order.payment_status == PaymentStatus.DEFERRED
示例3: test_complex_order_tax
def test_complex_order_tax(include_taxes):
tax = get_default_tax()
quantities = [44, 23, 65]
product = get_default_product()
supplier = get_default_supplier()
shop = get_default_shop()
shop.prices_include_tax = include_taxes
shop.save()
order = create_empty_order(shop=shop)
order.full_clean()
order.save()
pricing_context = get_pricing_module().get_context_from_data(
shop=shop,
customer=order.customer or AnonymousContact(),
)
total_price = Decimal("0")
price = Decimal("50")
for quantity in quantities:
total_price += quantity * price
add_product_to_order(order, supplier, product, quantity, price, tax.rate, pricing_context)
order.cache_prices()
order.save()
currency = "EUR"
summary = order.get_tax_summary()[0]
assert summary.tax_rate == tax.rate
assert summary.based_on == Money(total_price, currency)
assert summary.tax_amount == Money(total_price * tax.rate, currency)
assert summary.taxful == summary.based_on + summary.tax_amount
assert order.get_total_tax_amount() == Money(total_price * tax.rate, currency)
示例4: test_order_customer_name_from_shipping_address
def test_order_customer_name_from_shipping_address():
order = create_empty_order()
assert order.customer_id is None
assert order.orderer_id is None
order.billing_address = None
order.save()
order.refresh_from_db()
assert order.get_customer_name() == order.shipping_address.name
示例5: test_refno_generation
def test_refno_generation(method):
for attempt in range(10):
with override_settings(SHUUP_REFERENCE_NUMBER_METHOD=method):
order = create_empty_order()
order.save()
assert order.reference_number
with pytest.raises(ValueError):
get_reference_number(order)
示例6: test_complete_order
def test_complete_order(admin_user):
shop = get_default_shop()
order = create_empty_order(shop=shop)
order.save()
client = _get_client(admin_user)
response = client.post("/api/shuup/order/%s/complete/" % order.pk)
assert response.status_code == 200
response = client.post("/api/shuup/order/%s/complete/" % order.pk)
assert response.status_code == 400
示例7: test_order_customer_name_from_billing_address
def test_order_customer_name_from_billing_address():
person = create_random_person()
order = create_empty_order()
order.orderer = person
order.save()
order.refresh_from_db()
assert order.customer_id is None
assert order.orderer_id is not None
assert order.get_customer_name() == order.billing_address.name
assert order.shipping_address_id is not None
示例8: test_get_by_id
def test_get_by_id(admin_user):
shop = get_default_shop()
order = create_empty_order(shop=shop)
order.save()
client = _get_client(admin_user)
response = client.get("/api/shuup/order/%s/" % order.id)
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert order_data.get("id") == order.id
示例9: test_orders_list_view
def test_orders_list_view(browser, admin_user, live_server):
shop = get_default_shop()
for i in range(0, 10):
order = create_empty_order(shop=shop)
order.save()
# Set last one canceled
Order.objects.last().set_canceled()
initialize_admin_browser_test(browser, live_server)
_visit_orders_list_view(browser, live_server)
_test_status_filter(browser) # Will set three orders from end canceled
示例10: test_custom_refno_generation
def test_custom_refno_generation():
methods = (
custom_refno_gen,
"%s.%s" % (__name__, custom_refno_gen.__name__)
)
for method in methods:
with override_settings(SHUUP_REFERENCE_NUMBER_METHOD=method):
order = create_empty_order()
order.save()
assert order.reference_number == custom_refno_gen(order)
with pytest.raises(ValueError):
get_reference_number(order)
示例11: test_custom_ident_generation
def test_custom_ident_generation():
methods = (
custom_ident_gen,
"%s.%s" % (__name__, custom_ident_gen.__name__)
)
for method in methods:
with override_settings(SHUUP_ORDER_IDENTIFIER_METHOD=method):
order = create_empty_order()
order.save()
assert order.identifier == custom_ident_gen(order)
with pytest.raises(ValueError):
get_order_identifier(order)
示例12: test_get_by_status
def test_get_by_status(admin_user):
create_default_order_statuses()
shop = get_default_shop()
cancelled_status = OrderStatus.objects.get_default_canceled()
for i in range(1, 10):
order = create_empty_order(shop=shop)
order.status = cancelled_status
order.save()
order = create_empty_order(shop=shop)
order.save()
client = _get_client(admin_user)
response = client.get("/api/shuup/order/", data={"status": order.status.id})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 1
assert order_data[0].get("id") == order.id
assert order_data[0].get("identifier") == order.identifier
response = client.get("/api/shuup/order/", data={"status": cancelled_status.id})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 9
assert order.can_set_complete()
old_status = order.status
order.status = OrderStatus.objects.get_default_complete()
order.save()
assert old_status != order.status
response = client.get("/api/shuup/order/", data={"status": old_status.id})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 0
response = client.get("/api/shuup/order/", data={"status": order.status.id})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 1
示例13: test_shipment_creation_with_invalid_unsaved_shipment
def test_shipment_creation_with_invalid_unsaved_shipment():
shop = get_default_shop()
supplier = get_default_supplier()
order = _get_order(shop, supplier)
second_order = create_empty_order(shop=shop)
second_order.full_clean()
second_order.save()
product_lines = order.lines.exclude(product_id=None)
for line in product_lines:
for i in range(0, int(line.quantity)):
with pytest.raises(AssertionError):
unsaved_shipment = Shipment(supplier=supplier, order=second_order)
order.create_shipment({line.product: 1}, shipment=unsaved_shipment)
assert order.shipments.count() == 0
示例14: test_editing_existing_order
def test_editing_existing_order(rf, admin_user):
modifier = UserFactory()
get_initial_order_status() # Needed for the API
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
state = get_frontend_order_state(contact=contact)
shop = get_default_shop()
order = create_empty_order(shop=shop)
order.payment_data = {"payment_data": True}
order.shipping_data = {"shipping_data": True}
order.extra_data = {"external_id": "123"}
order.save()
assert order.lines.count() == 0
assert order.pk is not None
assert order.modified_by == order.creator
request = get_frontend_request_for_command(state, "finalize", modifier)
response = OrderEditView.as_view()(request, pk=order.pk)
assert_contains(response, "orderIdentifier") # this checks for status codes as a side effect
data = json.loads(response.content.decode("utf8"))
edited_order = Order.objects.get(pk=order.pk) # Re fetch the initial order
# Check that identifiers has not changed
assert edited_order.identifier == data["orderIdentifier"] == order.identifier
assert edited_order.pk == order.pk
# Check that the product content is updated based on state
assert edited_order.lines.count() == 5
assert edited_order.customer == contact
# Check that product line have right taxes
for line in edited_order.lines.all():
if line.type == OrderLineType.PRODUCT:
assert [line_tax.tax.code for line_tax in line.taxes.all()] == ["test_code"]
assert line.taxful_price.amount > line.taxless_price.amount
# Make sure order modification information is correct
assert edited_order.modified_by != order.modified_by
assert edited_order.modified_by == modifier
assert edited_order.modified_on > order.modified_on
# Make sure all non handled attributes is preserved from original order
assert edited_order.creator == order.creator
assert edited_order.ip_address == order.ip_address
assert edited_order.orderer == order.orderer
assert edited_order.customer_comment == order.customer_comment
assert edited_order.marketing_permission == order.marketing_permission
assert edited_order.order_date == order.order_date
assert edited_order.status == order.status
assert edited_order.payment_data == order.payment_data
assert edited_order.shipping_data == order.shipping_data
assert edited_order.extra_data == order.extra_data
示例15: test_get_by_order_date
def test_get_by_order_date(admin_user):
shop = get_default_shop()
today = dt.today()
yesterday = dt.today() - datetime.timedelta(days=1)
for i in range(1, 10):
order = create_empty_order(shop=shop)
order.order_date = yesterday
order.save()
order = create_empty_order(shop=shop)
order.save()
client = _get_client(admin_user)
response = client.get("/api/shuup/order/", data={"date": today})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 1
assert order_data[0].get("id") == order.id
assert order_data[0].get("identifier") == order.identifier
response = client.get("/api/shuup/order/", data={"date": yesterday})
assert response.status_code == status.HTTP_200_OK
order_data = json.loads(response.content.decode("utf-8"))
assert len(order_data) == 9