Esempio n. 1
0
def test_add_voucher_to_checkout_fail(
    checkout_with_item, voucher_with_high_min_spent_amount
):
    with pytest.raises(NotApplicable):
        add_voucher_to_checkout(checkout_with_item, voucher_with_high_min_spent_amount)

    assert checkout_with_item.voucher_code is None
Esempio n. 2
0
def test_add_voucher_to_checkout_fail(
    checkout_with_item, voucher_with_high_min_amount_spent
):
    with pytest.raises(NotApplicable):
        add_voucher_to_checkout(voucher_with_high_min_amount_spent, checkout_with_item)

    assert checkout_with_item.voucher_code is None
def test_checkout_lines_delete_with_not_applicable_voucher(
        user_api_client, checkout_with_item, voucher):
    subtotal = calculations.checkout_subtotal(checkout=checkout_with_item,
                                              lines=list(checkout_with_item))
    voucher.min_spent = subtotal.gross
    voucher.save(update_fields=["min_spent_amount", "currency"])

    add_voucher_to_checkout(checkout_with_item, list(checkout_with_item),
                            voucher)
    assert checkout_with_item.voucher_code == voucher.code

    line = checkout_with_item.lines.first()

    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
    variables = {"checkoutId": checkout_id, "lineId": line_id}
    response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE,
                                            variables)
    content = get_graphql_content(response)

    data = content["data"]["checkoutLineDelete"]
    assert not data["errors"]
    checkout_with_item.refresh_from_db()
    assert checkout_with_item.lines.count() == 0
    assert checkout_with_item.voucher_code is None
Esempio n. 4
0
def test_checkout_shipping_address_update_with_not_applicable_voucher(
        user_api_client, checkout_with_item, voucher_shipping_type,
        graphql_address_data, address_other_country, shipping_method):
    assert checkout_with_item.shipping_address is None
    assert checkout_with_item.voucher_code is None

    checkout_with_item.shipping_address = address_other_country
    checkout_with_item.shipping_method = shipping_method
    checkout_with_item.save(update_fields=['shipping_address', 'shipping_method'])
    assert checkout_with_item.shipping_address.country == \
        address_other_country.country

    voucher = voucher_shipping_type
    assert voucher.countries[0].code == address_other_country.country

    add_voucher_to_checkout(voucher, checkout_with_item)
    assert checkout_with_item.voucher_code == voucher.code

    checkout_id = graphene.Node.to_global_id('Checkout', checkout_with_item.pk)
    new_address = graphql_address_data
    variables = {'checkoutId': checkout_id, 'shippingAddress': new_address}
    response = user_api_client.post_graphql(
        MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)
    content = get_graphql_content(response)
    data = content['data']['checkoutShippingAddressUpdate']
    assert not data['errors']

    checkout_with_item.refresh_from_db()
    checkout_with_item.shipping_address.refresh_from_db()

    assert checkout_with_item.shipping_address.country == new_address['country']
    assert checkout_with_item.voucher_code is None
Esempio n. 5
0
def test_checkout_lines_delete_with_not_applicable_voucher(
    user_api_client, checkout_with_item, voucher
):
    voucher.min_amount_spent = checkout_with_item.get_subtotal().gross
    voucher.save(update_fields=["min_amount_spent"])

    add_voucher_to_checkout(voucher, checkout_with_item)
    assert checkout_with_item.voucher_code == voucher.code

    line = checkout_with_item.lines.first()

    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
    variables = {"checkoutId": checkout_id, "lineId": line_id}
    response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
    content = get_graphql_content(response)

    data = content["data"]["checkoutLineDelete"]
    assert not data["errors"]
    checkout_with_item.refresh_from_db()
    assert checkout_with_item.lines.count() == 0
    assert checkout_with_item.voucher_code is None
def test_checkout_shipping_address_update_with_not_applicable_voucher(
    user_api_client,
    checkout_with_item,
    voucher_shipping_type,
    graphql_address_data,
    address_other_country,
    shipping_method,
):
    assert checkout_with_item.shipping_address is None
    assert checkout_with_item.voucher_code is None

    checkout_with_item.shipping_address = address_other_country
    checkout_with_item.shipping_method = shipping_method
    checkout_with_item.save(
        update_fields=["shipping_address", "shipping_method"])
    assert checkout_with_item.shipping_address.country == address_other_country.country

    voucher = voucher_shipping_type
    assert voucher.countries[0].code == address_other_country.country

    add_voucher_to_checkout(checkout_with_item, list(checkout_with_item),
                            voucher)
    assert checkout_with_item.voucher_code == voucher.code

    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    new_address = graphql_address_data
    variables = {"checkoutId": checkout_id, "shippingAddress": new_address}
    response = user_api_client.post_graphql(
        MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)
    content = get_graphql_content(response)
    data = content["data"]["checkoutShippingAddressUpdate"]
    assert not data["errors"]

    checkout_with_item.refresh_from_db()
    checkout_with_item.shipping_address.refresh_from_db()

    assert checkout_with_item.shipping_address.country == new_address[
        "country"]
    assert checkout_with_item.voucher_code is None
Esempio n. 7
0
def test_checkout_lines_delete_with_not_applicable_voucher(
        user_api_client, checkout_with_item, voucher):
    voucher.min_amount_spent = checkout_with_item.get_subtotal().gross
    voucher.save(update_fields=['min_amount_spent'])

    add_voucher_to_checkout(voucher, checkout_with_item)
    assert checkout_with_item.voucher_code == voucher.code

    line = checkout_with_item.lines.first()

    checkout_id = graphene.Node.to_global_id('Checkout', checkout_with_item.pk)
    line_id = graphene.Node.to_global_id('CheckoutLine', line.pk)
    variables = {'checkoutId': checkout_id, 'lineId': line_id}
    response = user_api_client.post_graphql(
        MUTATION_CHECKOUT_LINES_DELETE, variables)
    content = get_graphql_content(response)

    data = content['data']['checkoutLineDelete']
    assert not data['errors']
    checkout_with_item.refresh_from_db()
    assert checkout_with_item.lines.count() == 0
    assert checkout_with_item.voucher_code is None
Esempio n. 8
0
def test_checkout_shipping_address_update_with_not_applicable_voucher(
    user_api_client,
    checkout_with_item,
    voucher_shipping_type,
    graphql_address_data,
    address_other_country,
    shipping_method,
):
    assert checkout_with_item.shipping_address is None
    assert checkout_with_item.voucher_code is None

    checkout_with_item.shipping_address = address_other_country
    checkout_with_item.shipping_method = shipping_method
    checkout_with_item.save(update_fields=["shipping_address", "shipping_method"])
    assert checkout_with_item.shipping_address.country == address_other_country.country

    voucher = voucher_shipping_type
    assert voucher.countries[0].code == address_other_country.country

    add_voucher_to_checkout(voucher, checkout_with_item)
    assert checkout_with_item.voucher_code == voucher.code

    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    new_address = graphql_address_data
    variables = {"checkoutId": checkout_id, "shippingAddress": new_address}
    response = user_api_client.post_graphql(
        MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
    )
    content = get_graphql_content(response)
    data = content["data"]["checkoutShippingAddressUpdate"]
    assert not data["errors"]

    checkout_with_item.refresh_from_db()
    checkout_with_item.shipping_address.refresh_from_db()

    assert checkout_with_item.shipping_address.country == new_address["country"]
    assert checkout_with_item.voucher_code is None
Esempio n. 9
0
def test_add_voucher_to_checkout(checkout_with_item, voucher):
    assert checkout_with_item.voucher_code is None
    add_voucher_to_checkout(checkout_with_item, voucher)

    assert checkout_with_item.voucher_code == voucher.code
Esempio n. 10
0
def test_add_voucher_to_checkout(checkout_with_item, voucher):
    assert checkout_with_item.voucher_code is None
    add_voucher_to_checkout(voucher, checkout_with_item)

    assert checkout_with_item.voucher_code == voucher.code