def get_request_for_contact_tests(rf): activate("en") request = rf.get("/") request.shop = get_shop(prices_include_tax=True) get_payment_method(request.shop) apply_request_middleware(request) return request
def seed_source(user, shop=None): source_shop = shop or get_default_shop() source = BasketishOrderSource(source_shop) billing_address = get_address() shipping_address = get_address(name="Shippy Doge") source.status = get_initial_order_status() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = get_person_contact(user) source.payment_method = get_payment_method(shop) source.shipping_method = get_shipping_method(shop) assert source.payment_method_id == get_payment_method(shop).id assert source.shipping_method_id == get_shipping_method(shop).id return source
def _get_frontend_order_state(shop, contact): tax = Tax.objects.create(code="test_code", rate=decimal.Decimal("0.20"), name="Default") tax_class = TaxClass.objects.create(identifier="test_tax_class", name="Default") rule = TaxRule.objects.create(tax=tax) rule.tax_classes.add(tax_class) rule.save() product = create_product(sku=printable_gibberish(), supplier=get_default_supplier(), shop=shop) product.tax_class = tax_class product.save() lines = [{"id": "x", "type": "product", "product": {"id": product.id}, "quantity": "32", "baseUnitPrice": 50}] state = { "customer": { "id": contact.id if contact else None, "billingAddress": _encode_address(contact.default_billing_address) if contact else {}, "shippingAddress": _encode_address(contact.default_shipping_address) if contact else {}, }, "lines": lines, "methods": { "shippingMethod": {"id": get_shipping_method(shop=shop).id}, "paymentMethod": {"id": get_payment_method(shop=shop).id}, }, "shop": { "selected": { "id": shop.id, "name": shop.safe_translation_getter("name"), "currency": shop.currency, "priceIncludeTaxes": shop.prices_include_tax, } }, } return state
def _get_source(user, shipping_country, billing_country): prices_include_taxes = True shop = get_shop(prices_include_taxes) payment_method = get_payment_method(shop) shipping_method = get_shipping_method(shop) source = _seed_source(shop, user, shipping_country, billing_country) source.payment_method = payment_method source.shipping_method = shipping_method assert source.payment_method_id == payment_method.id assert source.shipping_method_id == shipping_method.id supplier = get_default_supplier() product = create_product( sku="test-%s--%s" % (prices_include_taxes, 10), shop=source.shop, supplier=supplier, default_price=10 ) source.add_line( type=OrderLineType.PRODUCT, product=product, supplier=supplier, quantity=1, base_unit_price=source.create_price(10), ) assert payment_method == source.payment_method assert shipping_method == source.shipping_method return source
def _get_source(user, prices_include_taxes, total_price_value): shop = get_shop(prices_include_taxes) payment_method = get_payment_method(shop) shipping_method = get_shipping_method(shop) source = _seed_source(shop, user) source.payment_method = payment_method source.shipping_method = shipping_method assert source.payment_method_id == payment_method.id assert source.shipping_method_id == shipping_method.id supplier = get_default_supplier() product = create_product( sku="test-%s--%s" % (prices_include_taxes, total_price_value), shop=source.shop, supplier=supplier, default_price=total_price_value ) source.add_line( type=OrderLineType.PRODUCT, product=product, supplier=supplier, quantity=1, base_unit_price=source.create_price(total_price_value), ) if prices_include_taxes: assert source.taxful_total_price.value == total_price_value else: assert source.taxless_total_price.value == total_price_value assert payment_method == source.payment_method assert shipping_method == source.shipping_method return source, shipping_method
def _get_source(user, prices_include_taxes, total_price_value): shop = get_shop(prices_include_taxes) payment_method = get_payment_method(shop) shipping_method = get_shipping_method(shop) source = _seed_source(shop, user) source.payment_method = payment_method source.shipping_method = shipping_method assert source.payment_method_id == payment_method.id assert source.shipping_method_id == shipping_method.id supplier = get_default_supplier() product = create_product(sku="test-%s--%s" % (prices_include_taxes, total_price_value), shop=source.shop, supplier=supplier, default_price=total_price_value) source.add_line( type=OrderLineType.PRODUCT, product=product, supplier=supplier, quantity=1, base_unit_price=source.create_price(total_price_value), ) if prices_include_taxes: assert source.taxful_total_price.value == total_price_value else: assert source.taxless_total_price.value == total_price_value assert payment_method == source.payment_method assert shipping_method == source.shipping_method return source, shipping_method
def test_methods_impossible(admin_user): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) default_product = get_default_product() default_product.width = 5000 default_product.depth = 4000 default_product.heith = 1300 default_product.save() source.add_line( type=OrderLineType.PRODUCT, product=default_product, supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("200")) billing_address = get_address() shipping_address = get_address(name="My House", country='BR') shipping_address.postal_code = "89070210" source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = get_correios_carrier_1() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) assert len(errors) == 1
def _get_source(user, shipping_country, billing_country): prices_include_taxes = True shop = get_shop(prices_include_taxes) payment_method = get_payment_method(shop) shipping_method = get_shipping_method(shop) source = _seed_source(shop, user, shipping_country, billing_country) source.payment_method = payment_method source.shipping_method = shipping_method assert source.payment_method_id == payment_method.id assert source.shipping_method_id == shipping_method.id supplier = get_default_supplier() product = create_product(sku="test-%s--%s" % (prices_include_taxes, 10), shop=source.shop, supplier=supplier, default_price=10) source.add_line( type=OrderLineType.PRODUCT, product=product, supplier=supplier, quantity=1, base_unit_price=source.create_price(10), ) assert payment_method == source.payment_method assert shipping_method == source.shipping_method return source
def create_service(shop, line, tax_classes): assert line.quantity == 1 and line.discount == 0 if line.is_payment: meth = get_payment_method(shop=shop, price=line.price, name=line.payment_name) elif line.is_shipping: meth = get_shipping_method(shop=shop, price=line.price, name=line.shipping_name) meth.tax_class = tax_classes[line.tax_name] meth.save() return meth
def _get_frontend_order_state(shop, contact): tax = Tax.objects.create(code="test_code", rate=decimal.Decimal("0.20"), name="Default") tax_class = TaxClass.objects.create(identifier="test_tax_class", name="Default") rule = TaxRule.objects.create(tax=tax) rule.tax_classes.add(tax_class) rule.save() supplier = get_default_supplier(shop) product = create_product(sku=printable_gibberish(), supplier=supplier, shop=shop) product.tax_class = tax_class product.save() lines = [{ "id": "x", "type": "product", "product": { "id": product.id }, "quantity": "32", "baseUnitPrice": 50, "supplier": { "name": supplier.name, "id": supplier.id }, }] state = { "customer": { "id": contact.id if contact else None, "billingAddress": _encode_address(contact.default_billing_address) if contact else {}, "shippingAddress": _encode_address( contact.default_shipping_address) if contact else {}, }, "lines": lines, "methods": { "shippingMethod": { "id": get_shipping_method(shop=shop).id }, "paymentMethod": { "id": get_payment_method(shop=shop).id }, }, "shop": { "selected": { "id": shop.id, "name": shop.safe_translation_getter("name"), "currency": shop.currency, "priceIncludeTaxes": shop.prices_include_tax, } }, } return state
def initialize_test(rf, include_tax=False): activate("en") shop = get_shop(prices_include_tax=include_tax) # Valid baskets needs some payment methods to be available get_payment_method(shop) # Since some of the baskets are created for the default shop: get_payment_method(None) group = get_default_customer_group() customer = create_random_person() customer.groups.add(group) customer.save() request = rf.get("/") request.shop = shop apply_request_middleware(request) request.customer = customer return request, shop, group
def create_service(shop, line, tax_classes): assert line.quantity == 1 and line.discount == 0 if line.is_payment: meth = get_payment_method( shop=shop, price=line.price, name=line.payment_name) elif line.is_shipping: meth = get_shipping_method( shop=shop, price=line.price, name=line.shipping_name) meth.tax_class = tax_classes[line.tax_name] meth.save() return meth
def _init_test_for_product_with_basket(rf, default_price): request, product = _init_test_for_product_without_basket(rf, default_price) shop = factories.get_default_shop() supplier = factories.get_default_supplier() basket = get_basket(request) basket.status = factories.get_initial_order_status() basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1) basket.shipping_method = factories.get_shipping_method(shop=shop) basket.payment_method = factories.get_payment_method(shop=shop) assert basket.shop == request.shop assert basket.customer == request.customer return request, product, basket
def get_source(admin_user, service): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) billing_address = get_address() shipping_address = get_address(name="My House", country='BR') source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = service.carrier source.payment_method = get_payment_method(name="neat", price=4) return source
def _create_order(request, customer, coupon, product, expected_product_price): creator = OrderCreator(request) shop = request.shop request.basket = None request.customer = customer basket = get_basket(request) basket.status = factories.get_initial_order_status() basket.add_product(supplier=factories.get_default_supplier(), shop=shop, product=product, quantity=1) basket.shipping_method = factories.get_shipping_method(shop=shop) basket.payment_method = factories.get_payment_method(shop=shop) basket.add_code(coupon) assert basket.shop == request.shop assert basket.customer == request.customer assert product.get_price_info(request).price == expected_product_price creator.create_order(basket)
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2") ) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if country == "FI": # "Expenseefe-a Svedee Sheepping" will not allow shipping to # Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) assert [x.code for x in errors] == ["we_no_speak_finnish"] return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.price == source.create_price("5.00") else: assert line.price == source.create_price("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.price == source.create_price(4)
def test_methods_possible_no_shipping_address(admin_user): with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) default_product = get_default_product() default_product.width = 500 default_product.depth = 400 default_product.heith = 130 default_product.save() source.add_line( type=OrderLineType.PRODUCT, product=default_product, supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2")) billing_address = get_address(name="My House", country='BR') billing_address.postal_code = "89070210" source.billing_address = billing_address source.shipping_address = None source.customer = contact source.shipping_method = get_correios_carrier_1() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) # no errors assert len(errors) == 0 final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: assert line.text == "Correios - PAC #1" # no billing addres also - no shipping source.billing_address = None list(source.get_final_lines())
def seed_source(shipping_method=None, produce_price=10, shop=None): if not shop: shop = get_default_shop() source = BasketishOrderSource(shop) billing_address = get_address() shipping_address = get_address(name="Shippy Doge") source.status = get_initial_order_status() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = create_random_person() source.payment_method = get_payment_method(shop=shop) source.shipping_method = shipping_method if shipping_method else get_default_shipping_method() source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(produce_price), ) return source
def test_checkout(admin_user): get_default_shop() set_current_theme('shuup.themes.classic_gray') create_default_order_statuses() populate_if_required() create_test_data() default_product = get_default_product() sp = ShopProduct.objects.get(product=default_product, shop=get_default_shop()) sp.default_price = get_default_shop().create_price(Decimal(10.0)) sp.save() service = get_custom_carrier_service() component = SpecificShippingTableBehaviorComponent.objects.create( table=ShippingTable.objects.get(identifier='table-1')) service.behavior_components.add(component) c = SmartClient() basket_path = reverse("shuup:basket") add_to_basket_resp = c.post(basket_path, data={ "command": "add", "product_id": default_product.pk, "quantity": 1, "supplier": get_default_supplier().pk }) assert add_to_basket_resp.status_code < 400 shipping_method = service payment_method = get_payment_method(name="neat", price=4) # Resolve paths addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"}) methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"}) confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"}) # Phase: Addresses addresses_soup = c.soup(addresses_path) inputs = fill_address_inputs(addresses_soup, with_company=False) inputs['shipping-postal_code'] = "89060201" inputs['shipping-country'] = "BR" response = c.post(addresses_path, data=inputs) assert response.status_code == 302, "Address phase should redirect forth" assert response.url.endswith(methods_path) # Phase: Methods assert Order.objects.filter(payment_method=payment_method).count() == 0 response = c.post(methods_path, data={ "payment_method": payment_method.pk, "shipping_method": shipping_method.pk }) assert response.status_code == 302, "Methods phase should redirect forth" assert response.url.endswith(confirm_path) response = c.get(confirm_path) assert response.status_code == 200 # Phase: Confirm assert Order.objects.count() == 0 confirm_soup = c.soup(confirm_path) response = c.post(confirm_path, data=extract_form_fields(confirm_soup)) assert response.status_code == 302, "Confirm should redirect forth" assert Order.objects.count() == 1 order = Order.objects.filter(payment_method=payment_method).first() assert order.payment_status == PaymentStatus.NOT_PAID
def test_checkout(admin_user): get_default_shop() set_current_theme('shuup.themes.classic_gray') create_default_order_statuses() populate_if_required() create_test_data() default_product = get_default_product() sp = ShopProduct.objects.get(product=default_product, shop=get_default_shop()) sp.default_price = get_default_shop().create_price(Decimal(10.0)) sp.save() service = get_custom_carrier_service() component = SpecificShippingTableBehaviorComponent.objects.create( table=ShippingTable.objects.get(identifier='table-1') ) service.behavior_components.add(component) c = SmartClient() basket_path = reverse("shuup:basket") add_to_basket_resp = c.post(basket_path, data={ "command": "add", "product_id": default_product.pk, "quantity": 1, "supplier": get_default_supplier().pk }) assert add_to_basket_resp.status_code < 400 shipping_method = service payment_method = get_payment_method(name="neat", price=4) # Resolve paths addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"}) methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"}) confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"}) # Phase: Addresses addresses_soup = c.soup(addresses_path) inputs = fill_address_inputs(addresses_soup, with_company=False) inputs['shipping-postal_code'] = "89060201" inputs['shipping-country'] = "BR" response = c.post(addresses_path, data=inputs) assert response.status_code == 302, "Address phase should redirect forth" assert response.url.endswith(methods_path) # Phase: Methods assert Order.objects.filter(payment_method=payment_method).count() == 0 response = c.post( methods_path, data={ "payment_method": payment_method.pk, "shipping_method": shipping_method.pk } ) assert response.status_code == 302, "Methods phase should redirect forth" assert response.url.endswith(confirm_path) response = c.get(confirm_path) assert response.status_code == 200 # Phase: Confirm assert Order.objects.count() == 0 confirm_soup = c.soup(confirm_path) response = c.post(confirm_path, data=extract_form_fields(confirm_soup)) assert response.status_code == 302, "Confirm should redirect forth" assert Order.objects.count() == 1 order = Order.objects.filter(payment_method=payment_method).first() assert order.payment_status == PaymentStatus.NOT_PAID