def test_send_confirmation_emails_without_addresses_for_order( mocked_templated_email, order, site_settings, digital_content): assert not order.lines.count() template = emails.CONFIRM_ORDER_TEMPLATE add_variant_to_draft_order(order, digital_content.product_variant, quantity=1) order.shipping_address = None order.shipping_method = None order.billing_address = None order.save(update_fields=[ "shipping_address", "shipping_method", "billing_address" ]) redirect_url = "https://www.example.com" emails.send_order_confirmation(order.pk, redirect_url) email_data = emails.collect_data_for_email(order.pk, template, redirect_url) recipients = [order.get_customer_email()] expected_call_kwargs = { "context": email_data["context"], "from_email": site_settings.default_from_email, "template_name": template, } mocked_templated_email.assert_called_once_with(recipient_list=recipients, **expected_call_kwargs) # Render the email to ensure there is no error email_connection = get_connection() email_connection.get_email_message(to=recipients, **expected_call_kwargs)
def test_order_weight_add_new_variant(order_with_lines, product): variant = product.variants.first() add_variant_to_draft_order(order_with_lines, variant, 2) order_with_lines.refresh_from_db() assert order_with_lines.weight == _calculate_order_weight_from_lines( order_with_lines )
def test_order_weight_add_more_variant(order_with_lines): variant = order_with_lines.lines.first().variant add_variant_to_draft_order(order_with_lines, variant, 2) order_with_lines.refresh_from_db() assert order_with_lines.weight == _calculate_order_weight_from_lines( order_with_lines )
def test_add_variant_to_draft_order_not_allocates_stock_for_new_variant( order_with_lines, product): variant = product.variants.get() stock = Stock.objects.get(product_variant=variant) stock_before = get_quantity_allocated_for_stock(stock) add_variant_to_draft_order(order_with_lines, variant, 1) stock.refresh_from_db() assert get_quantity_allocated_for_stock(stock) == stock_before
def test_add_variant_to_draft_order_edits_line_for_existing_variant(order_with_lines): existing_line = order_with_lines.lines.first() variant = existing_line.variant lines_before = order_with_lines.lines.count() line_quantity_before = existing_line.quantity add_variant_to_draft_order(order_with_lines, variant, 1) existing_line.refresh_from_db() assert order_with_lines.lines.count() == lines_before assert existing_line.product_sku == variant.sku assert existing_line.quantity == line_quantity_before + 1
def test_get_order_weight_non_existing_product(order_with_lines, product): # Removing product should not affect order's weight order = order_with_lines variant = product.variants.first() add_variant_to_draft_order(order, variant, 1) old_weight = order.get_total_weight() product.delete() order.refresh_from_db() new_weight = order.get_total_weight() assert old_weight == new_weight
def test_add_variant_to_draft_order_not_allocates_stock_for_existing_variant( order_with_lines, ): existing_line = order_with_lines.lines.first() variant = existing_line.variant stock = Stock.objects.get(product_variant=variant) stock_before = get_quantity_allocated_for_stock(stock) quantity_before = existing_line.quantity quantity_unfulfilled_before = existing_line.quantity_unfulfilled add_variant_to_draft_order(order_with_lines, variant, 1) stock.refresh_from_db() existing_line.refresh_from_db() assert get_quantity_allocated_for_stock(stock) == stock_before assert existing_line.quantity == quantity_before + 1 assert existing_line.quantity_unfulfilled == quantity_unfulfilled_before + 1
def test_add_variant_to_draft_order_adds_line_for_new_variant( order_with_lines, product, product_translation_fr, settings): order = order_with_lines variant = product.variants.get() lines_before = order.lines.count() settings.LANGUAGE_CODE = "fr" add_variant_to_draft_order(order, variant, 1) line = order.lines.last() assert order.lines.count() == lines_before + 1 assert line.product_sku == variant.sku assert line.quantity == 1 assert line.unit_price == TaxedMoney(net=Money(10, "USD"), gross=Money(10, "USD")) assert line.translated_product_name == str(variant.product.translated) assert line.variant_name == str(variant) assert line.product_name == str(variant.product)