• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factories.create_empty_order函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shuup.testing.factories.create_empty_order函数的典型用法代码示例。如果您正苦于以下问题:Python create_empty_order函数的具体用法?Python create_empty_order怎么用?Python create_empty_order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了create_empty_order函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:suutari-ai,项目名称:shuup,代码行数:14,代码来源:test_order_api.py


示例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
开发者ID:ahmadzai,项目名称:shuup,代码行数:35,代码来源:test_methods.py


示例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)
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_orders.py


示例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
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:test_order_customer_name.py


示例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)
开发者ID:gurch101,项目名称:shuup,代码行数:8,代码来源:test_order_reference.py


示例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
开发者ID:suutari-ai,项目名称:shuup,代码行数:9,代码来源:test_order_api.py


示例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
开发者ID:ruqaiya,项目名称:shuup,代码行数:10,代码来源:test_order_customer_name.py


示例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
开发者ID:suutari-ai,项目名称:shuup,代码行数:10,代码来源:test_order_api.py


示例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
开发者ID:shawnadelic,项目名称:shuup,代码行数:12,代码来源:test_order_list.py


示例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)
开发者ID:gurch101,项目名称:shuup,代码行数:12,代码来源:test_order_reference.py


示例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)
开发者ID:gurch101,项目名称:shuup,代码行数:12,代码来源:test_order_reference.py


示例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
开发者ID:suutari-ai,项目名称:shuup,代码行数:40,代码来源:test_order_api.py


示例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
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:14,代码来源:test_shipments.py


示例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
开发者ID:NamiStudio,项目名称:shuup,代码行数:50,代码来源:test_order_creator.py


示例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
开发者ID:suutari-ai,项目名称:shuup,代码行数:24,代码来源:test_order_api.py


示例16: test_empty_order

def test_empty_order():
    order = create_empty_order()
    order.save()
    with pytest.raises(NoProductsToShipException):
        order.create_shipment_of_all_products()
    with pytest.raises(NoProductsToShipException):
        order.create_shipment(supplier=None, product_quantities={1: 0})
    assert order.can_edit()
    order.set_canceled()
    assert not order.can_edit(), "Can't edit canceled order"
    assert not order.can_set_complete(), "Can't process canceled order"
    order.set_canceled()  # Again! (This should be a no-op)
    order.delete()
    assert order.pk and order.deleted, "Order is soft-deleted"
    order.delete()  # Again! (This, too, should be a no-op)
开发者ID:millujye,项目名称:shuup,代码行数:15,代码来源:test_orders.py


示例17: test_known_extra_data

def test_known_extra_data():
    order = create_empty_order()
    order.shipping_data = {"instruction": "Hello"}
    order.payment_data = {"ssn": "101010-010X"}
    order.extra_data = {"wrapping_color": "blue"}
    order.save()
    with override_settings(
        SHUUP_ORDER_KNOWN_SHIPPING_DATA_KEYS=[("instruction", "Instruction")],
        SHUUP_ORDER_KNOWN_PAYMENT_DATA_KEYS=[("ssn", "Social Security Number")],
        SHUUP_ORDER_KNOWN_EXTRA_DATA_KEYS=[("wrapping_color", "Wrapping Color")],
    ):
        known_data = dict(order.get_known_additional_data())
        assert ("Instruction" in known_data)
        assert ("Social Security Number" in known_data)
        assert ("Wrapping Color" in known_data)
开发者ID:ruqaiya,项目名称:shuup,代码行数:15,代码来源:test_orders.py


示例18: test_product_detail

def test_product_detail(browser, admin_user, live_server, settings):
    activate(settings.PARLER_DEFAULT_LANGUAGE_CODE)
    shop = get_default_shop()
    order = create_empty_order(shop=shop)
    order.save()
    initialize_admin_browser_test(browser, live_server, settings)
    url = reverse("shuup_admin:order.detail", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Order %s" % order.pk))

    change_addresses(live_server, browser, order)

    set_status(browser, order, OrderStatus.objects.get_default_processing())
    assert order.can_set_complete()
    set_status(browser, order, OrderStatus.objects.get_default_complete())
开发者ID:ruqaiya,项目名称:shuup,代码行数:15,代码来源:test_order_detail.py


示例19: test_delete_toolbar_button

def test_delete_toolbar_button(rf, admin_user, view_cls, get_method, method_attr):
    method = get_method()
    assert method.can_delete()
    view = view_cls.as_view()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    check_for_delete(view, request, method)

    # Create order for method and test the can_delete and edit view
    order = create_empty_order()
    setattr(order, method_attr, method)
    order.save()
    assert not method.can_delete()
    check_for_delete(view, request, method)

    # Make sure that the actual delete is also blocked
    with pytest.raises(ProtectedError):
        method.delete()
开发者ID:NamiStudio,项目名称:shuup,代码行数:17,代码来源:test_services.py


示例20: _get_order

def _get_order(shop, supplier, stocked=False):
    order = create_empty_order(shop=shop)
    order.full_clean()
    order.save()
    for product_data in _get_product_data(stocked):
        quantity = product_data.pop("quantity")
        product = create_product(
            sku=product_data.pop("sku"),
            shop=shop,
            supplier=supplier,
            default_price=3.33,
            **product_data)
        add_product_to_order(order, supplier, product, quantity=quantity, taxless_base_unit_price=1)
    order.cache_prices()
    order.check_all_verified()
    order.save()
    return order
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:17,代码来源:test_shipments.py



注:本文中的shuup.testing.factories.create_empty_order函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap