当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_redirect_location函数代码示例

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


在下文中一共展示了get_redirect_location函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_order_payment_flow

def test_order_payment_flow(
        request_cart_with_item, client, address, shipping_method):
    request_cart_with_item.shipping_address = address
    request_cart_with_item.billing_address = address.get_copy()
    request_cart_with_item.email = '[email protected]'
    request_cart_with_item.shipping_method = (
        shipping_method.price_per_country.first())
    request_cart_with_item.save()

    order = create_order(
        request_cart_with_item, 'tracking_code', discounts=None, taxes=None)

    # Select payment method
    url = reverse('order:payment', kwargs={'token': order.token})
    data = {'method': 'default'}
    response = client.post(url, data, follow=True)

    assert len(response.redirect_chain) == 1
    assert response.status_code == 200
    redirect_url = reverse(
        'order:payment', kwargs={'token': order.token, 'variant': 'default'})
    assert response.request['PATH_INFO'] == redirect_url

    # Go to payment details page, enter payment data
    data = {
        'status': PaymentStatus.PREAUTH,
        'fraud_status': FraudStatus.UNKNOWN,
        'gateway_response': '3ds-disabled',
        'verification_result': 'waiting'}

    response = client.post(redirect_url, data)

    assert response.status_code == 302
    redirect_url = reverse(
        'order:payment-success', kwargs={'token': order.token})
    assert get_redirect_location(response) == redirect_url

    # Complete payment, go to checkout success page
    data = {'status': 'ok'}
    response = client.post(redirect_url, data)
    assert response.status_code == 302
    redirect_url = reverse(
        'order:checkout-success', kwargs={'token': order.token})
    assert get_redirect_location(response) == redirect_url

    # Assert that payment object was created and contains correct data
    payment = order.payments.all()[0]
    assert payment.total == order.total.gross.amount
    assert payment.tax == order.total.tax.amount
    assert payment.currency == order.total.currency
    assert payment.delivery == order.shipping_price.net.amount
    assert len(payment.get_purchased_items()) == len(order.lines.all())
开发者ID:zach-luman,项目名称:saleor,代码行数:52,代码来源:test_order.py

示例2: test_view_fulfill_order_lines_with_empty_quantity

def test_view_fulfill_order_lines_with_empty_quantity(admin_client, order_with_lines):
    url = reverse(
        "dashboard:fulfill-order-lines", kwargs={"order_pk": order_with_lines.pk}
    )
    data = {
        "csrfmiddlewaretoken": "hello",
        "form-INITIAL_FORMS": "0",
        "form-MAX_NUM_FORMS": "1000",
        "form-MIN_NUM_FORMS": "0",
        "form-TOTAL_FORMS": order_with_lines.lines.count(),
        "send_mail": "on",
        "tracking_number": "",
    }
    for i, line in enumerate(order_with_lines):
        data["form-{}-order_line".format(i)] = line.pk
        data["form-{}-quantity".format(i)] = line.quantity_unfulfilled

    # Set first order line's fulfill quantity to 0
    data["form-0-quantity"] = 0

    response = admin_client.post(url, data)
    assert response.status_code == 302
    assert get_redirect_location(response) == reverse(
        "dashboard:order-details", kwargs={"order_pk": order_with_lines.pk}
    )
    order_with_lines.refresh_from_db()
    assert not order_with_lines.lines.all()[0].quantity_unfulfilled == 0
    for line in order_with_lines.lines.all()[1:]:
        assert line.quantity_unfulfilled == 0
开发者ID:mirumee,项目名称:saleor,代码行数:29,代码来源:test_order.py

示例3: test_view_product_type_edit_to_no_variants_valid

def test_view_product_type_edit_to_no_variants_valid(admin_client, product):
    product_type = ProductType.objects.create(
        name="New product type", has_variants=True
    )
    product.product_type = product_type
    product.save()

    url = reverse("dashboard:product-type-update", kwargs={"pk": product_type.pk})
    # When all products have only one variant you can change
    # has_variants to false
    data = {
        "name": product_type.name,
        "product_attributes": product_type.product_attributes.values_list(
            "pk", flat=True
        ),
        "variant_attributes": product_type.variant_attributes.values_list(
            "pk", flat=True
        ),
        "has_variants": False,
        "weight": ["3.47"],
    }

    response = admin_client.post(url, data)

    assert response.status_code == 302
    assert get_redirect_location(response) == url
    product_type.refresh_from_db()
    assert not product_type.has_variants
    assert product.variants.count() == 1
开发者ID:mirumee,项目名称:saleor,代码行数:29,代码来源:test_product.py

示例4: test_add_order_note_view

def test_add_order_note_view(order, authorized_client, customer_user):
    order.user_email = customer_user.email
    order.save()
    url = reverse("order:details", kwargs={"token": order.token})
    customer_note = "bla-bla note"
    data = {"customer_note": customer_note}

    response = authorized_client.post(url, data)

    redirect_url = reverse("order:details", kwargs={"token": order.token})
    assert get_redirect_location(response) == redirect_url
    order.refresh_from_db()
    assert order.customer_note == customer_note

    # Ensure an order event was triggered
    note_event = order_events.OrderEvent.objects.get()  # type: order_events.OrderEvent
    assert note_event.type == order_events.OrderEvents.NOTE_ADDED
    assert note_event.user == customer_user
    assert note_event.order == order
    assert note_event.parameters == {"message": customer_note}

    # Ensure a customer event was triggered
    note_event = account_events.CustomerEvent.objects.get()
    assert note_event.type == account_events.CustomerEvents.NOTE_ADDED_TO_ORDER
    assert note_event.user == customer_user
    assert note_event.order == order
    assert note_event.parameters == {"message": customer_note}
开发者ID:mirumee,项目名称:saleor,代码行数:27,代码来源:test_order.py

示例5: test_view_product_type_edit_to_no_variants_valid

def test_view_product_type_edit_to_no_variants_valid(admin_client, product):
    product_type = ProductType.objects.create(
        name='New product type', has_variants=True)
    product.product_type = product_type
    product.save()

    url = reverse(
        'dashboard:product-type-update', kwargs={'pk': product_type.pk})
    # When all products have only one variant you can change
    # has_variants to false
    data = {
        'name': product_type.name,
        'product_attributes': product_type.product_attributes.values_list(
            'pk', flat=True),
        'variant_attributes': product_type.variant_attributes.values_list(
            'pk', flat=True),
        'has_variants': False}

    response = admin_client.post(url, data)

    assert response.status_code == 302
    assert get_redirect_location(response) == url
    product_type.refresh_from_db()
    assert not product_type.has_variants
    assert product.variants.count() == 1
开发者ID:zach-luman,项目名称:saleor,代码行数:25,代码来源:test_product.py

示例6: test_view_add_variant_to_order

def test_view_add_variant_to_order(admin_client, order_with_lines, admin_user):
    order_with_lines.status = OrderStatus.DRAFT
    order_with_lines.save()
    variant = ProductVariant.objects.get(sku="SKU_A")
    line = OrderLine.objects.get(product_sku="SKU_A")
    line_quantity_before = line.quantity

    assert not OrderEvent.objects.exists()

    added_quantity = 2
    url = reverse(
        "dashboard:add-variant-to-order", kwargs={"order_pk": order_with_lines.pk}
    )
    data = {"variant": variant.pk, "quantity": added_quantity}

    response = admin_client.post(url, data)

    line.refresh_from_db()
    assert response.status_code == 302
    assert get_redirect_location(response) == reverse(
        "dashboard:order-details", kwargs={"order_pk": order_with_lines.pk}
    )
    assert line.quantity == line_quantity_before + added_quantity

    removed_items_event = OrderEvent.objects.last()
    assert removed_items_event.type == OrderEvents.DRAFT_ADDED_PRODUCTS
    assert removed_items_event.user == admin_user
    assert removed_items_event.parameters == {
        "lines": [{"quantity": line.quantity, "line_pk": line.pk, "item": str(line)}]
    }
开发者ID:mirumee,项目名称:saleor,代码行数:30,代码来源:test_order.py

示例7: test_view_cancel_order_line

def test_view_cancel_order_line(admin_client, draft_order):
    lines_before = draft_order.lines.all()
    lines_before_count = lines_before.count()
    line = lines_before.first()
    line_quantity = line.quantity
    quantity_allocated_before = line.variant.quantity_allocated

    url = reverse(
        'dashboard:orderline-cancel', kwargs={
            'order_pk': draft_order.pk,
            'line_pk': line.pk})

    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(url, {'csrfmiddlewaretoken': 'hello'})
    assert response.status_code == 302
    assert get_redirect_location(response) == reverse(
        'dashboard:order-details', args=[draft_order.pk])
    # check ordered item removal
    lines_after = Order.objects.get().lines.all()
    assert lines_before_count - 1 == lines_after.count()
    # check stock deallocation
    line.variant.refresh_from_db()
    assert line.variant.quantity_allocated == (
        quantity_allocated_before - line_quantity)
    url = reverse(
        'dashboard:orderline-cancel', kwargs={
            'order_pk': draft_order.pk,
            'line_pk': OrderLine.objects.get().pk})
    response = admin_client.post(
        url, {'csrfmiddlewaretoken': 'hello'}, follow=True)
    assert Order.objects.get().lines.all().count() == 0
    # check success messages after redirect
    assert response.context['messages']
开发者ID:zdobooto,项目名称:saleor,代码行数:34,代码来源:test_order.py

示例8: test_view_cancel_order_line

def test_view_cancel_order_line(admin_client, draft_order, track_inventory, admin_user):
    lines_before = draft_order.lines.all()
    lines_before_count = lines_before.count()
    line = lines_before.first()
    line_quantity = line.quantity
    quantity_allocated_before = line.variant.quantity_allocated

    line.variant.track_inventory = track_inventory
    line.variant.save()

    assert not OrderEvent.objects.exists()

    url = reverse(
        "dashboard:orderline-cancel",
        kwargs={"order_pk": draft_order.pk, "line_pk": line.pk},
    )

    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(url, {"csrfmiddlewaretoken": "hello"})
    assert response.status_code == 302
    assert get_redirect_location(response) == reverse(
        "dashboard:order-details", args=[draft_order.pk]
    )
    # check ordered item removal
    lines_after = Order.objects.get().lines.all()
    assert lines_before_count - 1 == lines_after.count()

    # check stock deallocation
    line.variant.refresh_from_db()

    if track_inventory:
        assert line.variant.quantity_allocated == (
            quantity_allocated_before - line_quantity
        )
    else:
        assert line.variant.quantity_allocated == quantity_allocated_before

    removed_items_event = OrderEvent.objects.last()
    assert removed_items_event.type == OrderEvents.DRAFT_REMOVED_PRODUCTS
    assert removed_items_event.user == admin_user
    assert removed_items_event.parameters == {
        "lines": [
            {
                "quantity": line.quantity,
                "line_pk": None,  # the line was deleted
                "item": str(line),
            }
        ]
    }

    url = reverse(
        "dashboard:orderline-cancel",
        kwargs={"order_pk": draft_order.pk, "line_pk": OrderLine.objects.get().pk},
    )
    response = admin_client.post(url, {"csrfmiddlewaretoken": "hello"}, follow=True)
    assert Order.objects.get().lines.all().count() == 0
    # check success messages after redirect
    assert response.context["messages"]
开发者ID:mirumee,项目名称:saleor,代码行数:59,代码来源:test_order.py

示例9: test_view_remove_draft_order

def test_view_remove_draft_order(admin_client, draft_order):
    url = reverse("dashboard:draft-order-delete", kwargs={"order_pk": draft_order.pk})

    response = admin_client.post(url, {})

    assert response.status_code == 302
    assert get_redirect_location(response) == reverse("dashboard:orders")
    assert Order.objects.count() == 0
开发者ID:mirumee,项目名称:saleor,代码行数:8,代码来源:test_order.py

示例10: test_checkout_flow

def test_checkout_flow(request_cart_with_item, client, shipping_method):  # pylint: disable=W0613,R0914
    """
    Basic test case that confirms if core checkout flow works
    """

    # Enter checkout
    checkout_index = client.get(reverse('checkout:index'), follow=True)
    # Checkout index redirects directly to shipping address step
    shipping_address = client.get(checkout_index.request['PATH_INFO'])

    # Enter shipping address data
    shipping_data = {
        'email': '[email protected]',
        'first_name': 'John',
        'last_name': 'Doe',
        'street_address_1': 'Aleje Jerozolimskie 2',
        'street_address_2': '',
        'city': 'Warszawa',
        'city_area': '',
        'country_area': '',
        'postal_code': '00-374',
        'country': 'PL'}
    shipping_response = client.post(shipping_address.request['PATH_INFO'],
                                    data=shipping_data, follow=True)

    # Select shipping method
    shipping_method_page = client.get(shipping_response.request['PATH_INFO'])

    # Redirect to summary after shipping method selection
    shipping_method_data = {'method': shipping_method.pk}
    shipping_method_response = client.post(shipping_method_page.request['PATH_INFO'],
                                           data=shipping_method_data, follow=True)

    # Summary page asks for Billing address, default is the same as shipping
    address_data = {'address': 'shipping_address'}
    summary_response = client.post(shipping_method_response.request['PATH_INFO'],
                                   data=address_data, follow=True)

    # After summary step, order is created and it waits for payment
    order = summary_response.context['order']

    # Select payment method
    payment_page = client.post(summary_response.request['PATH_INFO'],
                               data={'method': 'default'}, follow=True)
    assert len(payment_page.redirect_chain) == 1
    assert payment_page.status_code == 200
    # Go to payment details page, enter payment data
    payment_page_url = payment_page.redirect_chain[0][0]
    payment_data = {
        'status': PaymentStatus.PREAUTH,
        'fraud_status': FraudStatus.UNKNOWN,
        'gateway_response': '3ds-disabled',
        'verification_result': 'waiting'}
    payment_response = client.post(payment_page_url, data=payment_data)
    assert payment_response.status_code == 302
    order_password = reverse('order:create-password',
                             kwargs={'token': order.token})
    assert get_redirect_location(payment_response) == order_password
开发者ID:maciekiks,项目名称:saleor,代码行数:58,代码来源:test_checkout_integration.py

示例11: test_view_product_select_type

def test_view_product_select_type(admin_client, product_type):
    url = reverse('dashboard:product-add-select-type')
    data = {'product_type': product_type.pk}

    response = admin_client.post(url, data)

    assert get_redirect_location(response) == reverse(
        'dashboard:product-add', kwargs={'type_pk': product_type.pk})
    assert response.status_code == 302
开发者ID:zach-luman,项目名称:saleor,代码行数:9,代码来源:test_product.py

示例12: test_summary_without_address

def test_summary_without_address(request_cart_with_item, client):  # pylint: disable=W0613
    """
    user tries to get summary step without saved shipping method -
     if is redirected to shipping method step
    """

    response = client.get(reverse('checkout:summary'))
    assert response.status_code == 302
    assert get_redirect_location(response) == reverse('checkout:shipping-method')
开发者ID:maciekiks,项目名称:saleor,代码行数:9,代码来源:test_checkout_integration.py

示例13: test_view_connect_order_with_user_different_email

def test_view_connect_order_with_user_different_email(
        order, authorized_client):
    url = reverse(
        'order:connect-order-with-user', kwargs={'token': order.token})
    response = authorized_client.post(url)

    redirect_location = get_redirect_location(response)
    assert redirect_location == reverse('account:details')
    order.refresh_from_db()
    assert order.user is None
开发者ID:patrys,项目名称:saleor,代码行数:10,代码来源:test_order.py

示例14: test_client_login

def test_client_login(request_cart_with_item, client, admin_user):
    data = {
        'username': admin_user.email,
        'password': 'password'
    }
    response = client.post(reverse('registration:login'), data=data)
    assert response.status_code == 302
    assert get_redirect_location(response) == '/'
    response = client.get(reverse('checkout:shipping-address'))
    assert response.context['checkout'].cart.token == request_cart_with_item.token
开发者ID:fnugrahendi,项目名称:saleor,代码行数:10,代码来源:test_checkout_integration.py

示例15: test_view_product_variant_details_redirect_to_product

def test_view_product_variant_details_redirect_to_product(
        admin_client, product):
    variant = product.variants.get()
    url = reverse(
        'dashboard:variant-details',
        kwargs={'product_pk': product.pk, 'variant_pk': variant.pk})

    response = admin_client.get(url)

    assert response.status_code == 302
    assert get_redirect_location(response) == reverse(
        'dashboard:product-details', kwargs={'pk': product.pk})
开发者ID:zach-luman,项目名称:saleor,代码行数:12,代码来源:test_product.py


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