def test_checkout_shipping_address_update_with_not_applicable_voucher( user_api_client, cart_with_item, voucher_shipping_type, graphql_address_data, address_other_country, shipping_method): assert cart_with_item.shipping_address is None assert cart_with_item.voucher_code is None cart_with_item.shipping_address = address_other_country cart_with_item.shipping_method = shipping_method cart_with_item.save(update_fields=['shipping_address', 'shipping_method']) assert cart_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_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code checkout_id = graphene.Node.to_global_id('Checkout', cart_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'] cart_with_item.refresh_from_db() cart_with_item.shipping_address.refresh_from_db() assert cart_with_item.shipping_address.country == new_address['country'] assert cart_with_item.voucher_code is None
def test_checkout_shipping_address_update_with_not_applicable_voucher( user_api_client, cart_with_item, voucher_shipping_type, graphql_address_data, address_other_country, shipping_method): assert cart_with_item.shipping_address is None assert cart_with_item.voucher_code is None cart_with_item.shipping_address = address_other_country cart_with_item.shipping_method = shipping_method cart_with_item.save(update_fields=['shipping_address', 'shipping_method']) assert cart_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_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code checkout_id = graphene.Node.to_global_id('Checkout', cart_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'] cart_with_item.refresh_from_db() cart_with_item.shipping_address.refresh_from_db() assert cart_with_item.shipping_address.country == new_address['country'] assert cart_with_item.voucher_code is None
def test_add_voucher_to_cart_fail( cart_with_item, voucher_with_high_min_amount_spent): with pytest.raises(NotApplicable) as e: add_voucher_to_cart( voucher_with_high_min_amount_spent, cart_with_item) assert cart_with_item.voucher_code is None
def test_checkout_lines_delete_with_not_applicable_voucher( user_api_client, cart_with_item, voucher): voucher.min_amount_spent = cart_with_item.get_subtotal().gross voucher.save(update_fields=['min_amount_spent']) add_voucher_to_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code line = cart_with_item.lines.first() checkout_id = graphene.Node.to_global_id('Checkout', cart_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'] cart_with_item.refresh_from_db() assert cart_with_item.lines.count() == 0 assert cart_with_item.voucher_code is None
def test_checkout_lines_delete_with_not_applicable_voucher( user_api_client, cart_with_item, voucher): voucher.min_amount_spent = cart_with_item.get_subtotal().gross voucher.save(update_fields=['min_amount_spent']) add_voucher_to_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code line = cart_with_item.lines.first() checkout_id = graphene.Node.to_global_id('Checkout', cart_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'] cart_with_item.refresh_from_db() assert cart_with_item.lines.count() == 0 assert cart_with_item.voucher_code is None
def test_add_voucher_to_cart_fail(cart_with_item, voucher_with_high_min_amount_spent): with pytest.raises(NotApplicable) as e: add_voucher_to_cart(voucher_with_high_min_amount_spent, cart_with_item) assert cart_with_item.voucher_code is None
def test_add_voucher_to_cart(cart_with_item, voucher): assert cart_with_item.voucher_code is None add_voucher_to_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code
def test_add_voucher_to_cart(cart_with_item, voucher): assert cart_with_item.voucher_code is None add_voucher_to_cart(voucher, cart_with_item) assert cart_with_item.voucher_code == voucher.code