本文整理汇总了Python中shuup.testing.factories.create_random_order函数的典型用法代码示例。如果您正苦于以下问题:Python create_random_order函数的具体用法?Python create_random_order怎么用?Python create_random_order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_random_order函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mass_edit_orders3
def test_mass_edit_orders3(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
contact1 = create_random_person()
product1 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
product2 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="501")
order1 = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
order2 = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
assert order1.status.role != OrderStatusRole.CANCELED
assert order2.status.role != OrderStatusRole.CANCELED
payload = {
"action": OrderConfirmationPdfAction().identifier,
"values": [order1.pk, order2.pk]
}
request = apply_request_middleware(rf.post(
"/",
user=admin_user,
))
request._body = json.dumps(payload).encode("UTF-8")
view = OrderListView.as_view()
response = view(request=request)
assert response.status_code == 200
if weasyprint:
assert response['Content-Disposition'] == 'attachment; filename=order_confirmation_pdf.zip'
else:
assert response["content-type"] == "application/json"
示例2: test_list_orders
def test_list_orders(admin_user):
shop = get_default_shop()
product = create_product("test", shop, get_default_supplier())
order = create_random_order(get_person_contact(admin_user), [product])
order2 = create_random_order(create_random_person(), [product])
client = _get_client(admin_user)
response = client.get("/api/shuup/front/orders/")
response_data = json.loads(response.content.decode("utf-8"))
assert response.status_code == status.HTTP_200_OK
assert len(response_data) == 1
assert "shop" in response_data[0]
assert "contact_address" in response_data[0]["shop"]
示例3: test_get_shipments
def test_get_shipments(admin_user):
client = _get_client(admin_user)
shop1 = get_shop(True)
shop2 = get_shop(True)
customer1 = create_random_person()
customer2 = create_random_person()
order1 = create_random_order(customer1, shop=shop1, completion_probability=1)
order2 = create_random_order(customer2, shop=shop1, completion_probability=1)
order3 = create_random_order(customer1, shop=shop2, completion_probability=1)
order4 = create_random_order(customer2, shop=shop1, completion_probability=1)
# list shipments
response = client.get("/api/shuup/shipment/")
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
assert len(shipment_data) == 4
assert shipment_data[0]["id"] == order1.shipments.first().pk
assert shipment_data[1]["id"] == order2.shipments.first().pk
assert shipment_data[2]["id"] == order3.shipments.first().pk
assert shipment_data[3]["id"] == order4.shipments.first().pk
# get shipment by id
response = client.get("/api/shuup/shipment/%s/" % order1.shipments.first().pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
assert shipment_data["id"] == order1.shipments.first().pk
assert shipment_data["order"] == order1.pk
# get shipment by product
product = order2.shipments.first().products.first()
response = client.get("/api/shuup/shipment/?product=%s" % product.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
for ship_product in shipment_data["product"]:
assert ship_product["id"] == product.pk
assert ship_product["order"] == order2.pk
# get shipment by order
response = client.get("/api/shuup/shipment/?order=%s" % order3.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
assert ship["order"] == order3.pk
# get shipment by shop
response = client.get("/api/shuup/shipment/?shop=%s" % shop1.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
assert Shipment.objects.filter(pk=ship["id"], order__shop=shop1).exists()
示例4: 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"
示例5: test_retrieve_order
def test_retrieve_order(admin_user):
shop = get_default_shop()
product = create_product("test", shop, get_default_supplier())
order = create_random_order(get_person_contact(admin_user), [product])
order2 = create_random_order(create_random_person(), [product])
client = _get_client(admin_user)
response = client.get("/api/shuup/front/orders/{}/".format(order.pk))
response_data = json.loads(response.content.decode("utf-8"))
assert response.status_code == status.HTTP_200_OK
assert response_data["id"] == order.pk
response = client.get("/api/shuup/front/orders/{}/".format(100))
assert response.status_code == 404
response = client.get("/api/shuup/front/orders/{}/".format(order2.pk))
assert response.status_code == 404
示例6: test_mass_edit_orders
def test_mass_edit_orders(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
contact1 = create_random_person()
product1 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
product2 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="501")
order = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
assert order.status.role != OrderStatusRole.CANCELED
payload = {
"action": CancelOrderAction().identifier,
"values": [order.pk]
}
request = apply_request_middleware(rf.post(
"/",
user=admin_user,
))
request._body = json.dumps(payload).encode("UTF-8")
view = OrderListView.as_view()
response = view(request=request)
assert response.status_code == 200
for order in Order.objects.all():
assert order.status.role == OrderStatusRole.CANCELED
示例7: 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()
示例8: test_order_creator_customer_details
def test_order_creator_customer_details(rf, admin_user):
shop = get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
company = create_random_company()
group = get_default_customer_group()
contact.groups.add(group)
contact.company_memberships.add(company)
contact.save()
product = create_product(sku=printable_gibberish(), supplier=get_default_supplier(), shop=shop)
order = create_random_order(contact, products=[product])
request = apply_request_middleware(rf.get("/", {"command": "customer_details", "id": contact.id}), user=admin_user)
response = OrderEditView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert "customer_info" in data
assert "order_summary" in data
assert "recent_orders" in data
assert data["customer_info"]["name"] == contact.full_name
assert data["customer_info"]["phone_no"] == contact.phone
assert data["customer_info"]["email"] == contact.email
assert company.full_name in data["customer_info"]["companies"]
assert group.name in data["customer_info"]["groups"]
assert data["customer_info"]["merchant_notes"] == contact.merchant_notes
assert len(data["order_summary"]) == 1
assert data["order_summary"][0]["year"] == order.order_date.year
assert data["order_summary"][0]["total"] == format_money(order.taxful_total_price)
assert len(data["recent_orders"]) == 1
assert data["recent_orders"][0]["status"] == order.get_status_display()
assert data["recent_orders"][0]["total"] == format_money(order.taxful_total_price)
assert data["recent_orders"][0]["payment_status"] == force_text(order.payment_status.label)
assert data["recent_orders"][0]["shipment_status"] == force_text(order.shipping_status.label)
示例9: test_coupon_amount_limit
def test_coupon_amount_limit():
coupon = Coupon.objects.create(code="TEST", active=True)
get_default_campaign(coupon)
contact = create_random_person()
shop = get_default_shop()
product = create_product("test", shop=shop, supplier=get_default_supplier(), default_price="12")
order = create_random_order(customer=contact)
for x in range(50):
coupon.use(order)
assert coupon.usages.count() == 50
coupon.increase_usage_limit_by(5)
coupon.save()
assert coupon.usage_limit == 55
assert coupon.can_use_code(contact)
for x in range(5):
coupon.use(order)
assert coupon.usages.count() == 55
assert not Coupon.is_usable(coupon.code, order.customer)
assert coupon.usages.count() == 55 # no change, limit met
示例10: test_protected_fields
def test_protected_fields():
activate("en")
shop = Shop.objects.create(
name="testshop",
identifier="testshop",
status=ShopStatus.ENABLED,
public_name="test shop",
domain="derp",
currency="EUR"
)
get_currency("EUR")
get_currency("USD")
assert shop.name == "testshop"
assert shop.currency == "EUR"
assert not ConfigurationItem.objects.filter(shop=shop, key="languages").exists()
shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES)
assert not shop_form._get_protected_fields() # No protected fields just yet, right?
data = get_form_data(shop_form, prepared=True)
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
_test_cleanliness(shop_form)
shop_form.save()
# Now let's make it protected!
create_product(printable_gibberish(), shop=shop, supplier=get_default_supplier())
order = create_random_order(customer=create_random_person(), shop=shop)
assert order.shop == shop
# And try again...
data["currency"] = "USD"
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
assert shop_form._get_protected_fields() # So protected!
_test_cleanliness(shop_form)
shop = shop_form.save()
assert shop.currency == "EUR" # But the shop form ignored the change . . .
示例11: test_total_sales_customers_report
def test_total_sales_customers_report(rf):
shop = get_default_shop()
supplier = get_default_supplier()
p1 = create_product("p1", shop=shop, supplier=supplier, default_price="5")
p2 = create_product("p2", shop=shop, supplier=supplier, default_price="20")
# orders for person 1
person1 = create_random_person()
order1 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2])
order2 = create_random_order(customer=person1, completion_probability=1, products=[p1, p2])
# orders for person 2
person2 = create_random_person()
order3 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2])
order4 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2])
order5 = create_random_order(customer=person2, completion_probability=1, products=[p1, p2])
# pay orders
[o.create_payment(o.taxful_total_price) for o in Order.objects.all()]
data = {
"report": TotalSales.get_name(),
"shop": shop.pk,
"date_range": DateRangeChoices.ALL_TIME,
"writer": "json",
"force_download": 1,
}
report = TotalSales(**data)
writer = get_writer_instance(data["writer"])
response = writer.get_response(report=report)
if hasattr(response, "render"):
response.render()
json_data = json.loads(response.content.decode("utf-8"))
assert force_text(TotalSales.title) in json_data.get("heading")
data = json_data.get("tables")[0].get("data")[0]
avg_sales = (
order1.taxful_total_price +
order2.taxful_total_price +
order3.taxful_total_price +
order4.taxful_total_price +
order5.taxful_total_price
) / Decimal(5)
assert int(data["customers"]) == 2
assert int(data["order_amount"]) == 5
assert data["customer_avg_sale"] == str(avg_sales.value.quantize(Decimal('0.01')))
示例12: 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()
)
示例13: test_update_order_admin_comment
def test_update_order_admin_comment(admin_user, rf):
order = create_random_order(customer=create_random_person(), products=(get_default_product(),))
assert order.admin_comment == ""
view = UpdateAdminCommentView.as_view()
comment = "updated admin comment"
request = apply_request_middleware(rf.post("/", {"comment": comment}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code < 400
order.refresh_from_db()
assert order.admin_comment == comment
示例14: test_add_order_log_entry
def test_add_order_log_entry(admin_user, rf):
order = create_random_order(customer=create_random_person(), products=(get_default_product(),))
assert not OrderLogEntry.objects.filter(target=order).exists()
view = NewLogEntryView.as_view()
test_message = "test_order"
request = apply_request_middleware(rf.post("/", {"message": test_message}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code < 400
assert OrderLogEntry.objects.filter(target=order).exists()
assert OrderLogEntry.objects.filter(target=order).first().message == test_message
示例15: test_order_set_status_completed_works
def test_order_set_status_completed_works(admin_user, rf):
order = create_random_order(customer=create_random_person(), products=(get_default_product(),))
order.create_shipment_of_all_products() # Need to be shipped to set complete
assert order.status.role == OrderStatusRole.INITIAL
complete_status = OrderStatus.objects.get_default_complete()
view = OrderSetStatusView.as_view()
request = apply_request_middleware(rf.post("/", {"status": complete_status.pk}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code < 400
order = Order.objects.get(pk=order.pk)
assert order.status_id == complete_status.id
assert order.log_entries.filter(identifier="status_change").exists()