예제 #1
0
def test_single_page_checkout_with_login_and_register(browser, live_server, settings):
    cache.clear()  # Avoid caches from past tests

    # initialize
    product_name = "Test Product"
    get_default_shop()
    get_default_payment_method()
    get_default_shipping_method()
    product = create_orderable_product(product_name, "test-123", price=100)
    OrderStatus.objects.create(
        identifier="initial",
        role=OrderStatusRole.INITIAL,
        name="initial",
        default=True
    )

    # Initialize test and go to front page
    browser = initialize_front_browser_test(browser, live_server)

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    navigate_to_checkout(browser, product)

    # Let's assume that after addresses the checkout is normal
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout Method"))
    test_username = "******"
    test_email = "*****@*****.**"
    test_password = "******"
    register_test(browser, live_server, test_username, test_email, test_password)

    login_and_finish_up_the_checkout(browser, live_server, test_username, test_email, test_password)
예제 #2
0
def create_simple_order(request, creator, customer):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=shop,
        payment_method=get_default_payment_method(),
        shipping_method=get_default_shipping_method(),
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    return order
예제 #3
0
def seed_source(user, shop):
    source = BasketishOrderSource(shop)
    source.status = get_initial_order_status()
    source.customer = get_person_contact(user)
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()
    return source
예제 #4
0
def test_coupon(browser, live_server, settings):
    activate("en")
    # initialize
    cache.clear()
    shop = get_default_shop()
    get_default_payment_method()
    get_default_shipping_method()

    first_category = Category.objects.create(
        identifier="cat-1", status=CategoryStatus.VISIBLE, name="First Category")
    first_category.shops.add(shop)

    _populate_products_form_data(CATEGORY_PRODUCT_DATA, shop, first_category)

    # initialize test and go to front page
    browser = initialize_front_browser_test(browser, live_server)

    _add_product_to_basket_from_category(live_server, browser, first_category, shop)
    _activate_basket_campaign_through_coupon(browser, first_category, shop)
예제 #5
0
def test_order_creator_view_1(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    get_default_payment_method()
    get_default_shipping_method()
    get_initial_order_status()
    supplier = get_default_supplier()
    person = create_random_person()
    person.shops.add(shop)

    create_product("test-sku0", shop=shop, default_price=10, supplier=supplier)
    create_product("test-sku1", shop=shop, default_price=10, supplier=supplier)
    object_created.connect(_add_custom_order_created_message, sender=Order, dispatch_uid="object_created_signal_test")

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_order_creator_view(browser, live_server)
    _test_language_change(browser)
    _test_customer_data(browser, person)
    _test_regions(browser, person)
    _test_quick_add_lines(browser)
예제 #6
0
def _save_cart_with_products(rf, user):
    shop = get_default_shop()
    person = get_person_contact(user)
    get_default_payment_method()
    get_default_shipping_method()
    request = rf.post("/", {"title": "test"})
    request.shop = shop
    request.user = user
    request.person = person
    request.customer = person
    basket = get_basket(request)
    request = apply_request_middleware(request, user=user, person=person, customer=person, basket=basket)
    basket = _add_products_to_basket(basket)
    basket.save()
    response = CartSaveView.as_view()(request)
    basket = StoredBasket.objects.filter(title="test").first()
    data = json.loads(response.content.decode("utf8"))
    assert data["ok"], "cart saved successfully"
    return basket
예제 #7
0
def test_order_create_without_default_address(admin_user):
    create_default_order_statuses()
    shop = get_default_shop()
    sm = get_default_shipping_method()
    pm = get_default_payment_method()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    contact.default_billing_address = None
    contact.default_shipping_address = None
    contact.save()
    product = create_product(
        sku=printable_gibberish(),
        supplier=get_default_supplier(),
        shop=shop
    )
    assert not Order.objects.count()
    client = _get_client(admin_user)
    lines = [
        {"type": "product", "product": product.id, "quantity": "1", "base_unit_price_value": "5.00"},
        {"type": "product", "product": product.id, "quantity": "2", "base_unit_price_value": "1.00", "discount_amount_value": "0.50"},
        {"type": "other", "sku": "hello", "text": "A greeting", "quantity": 1, "base_unit_price_value": "3.5"},
        {"type": "text", "text": "This was an order!", "quantity": 0},
    ]
    response = client.post("/api/E-Commerce/order/", content_type="application/json", data=json.dumps({
        "shop": shop.pk,
        "shipping_method": sm.pk,
        "payment_method": pm.pk,
        "customer": contact.pk,
        "lines": lines
    }))
    assert response.status_code == 201
    assert Order.objects.count() == 1
    order = Order.objects.first()
    assert order.shop == shop
    assert order.shipping_method == sm
    assert order.payment_method == pm
    assert order.customer == contact
    assert order.creator == admin_user
    assert order.billing_address is None
    assert order.shipping_address is None
    assert order.payment_status == PaymentStatus.NOT_PAID
    assert order.shipping_status == ShippingStatus.NOT_SHIPPED
    assert order.status == OrderStatus.objects.get_default_initial()
    assert order.taxful_total_price_value == decimal.Decimal(10)
    assert order.lines.count() == 6 # shipping line, payment line, 2 product lines, 2 other lines
    for idx, line in enumerate(order.lines.all()[:4]):
        assert line.quantity == decimal.Decimal(lines[idx].get("quantity"))
        assert line.base_unit_price_value == decimal.Decimal(lines[idx].get("base_unit_price_value", 0))
        assert line.discount_amount_value == decimal.Decimal(lines[idx].get("discount_amount_value", 0))
예제 #8
0
def seed_source(coupon, produce_price=10):
    source = BasketishOrderSource(get_default_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_default_payment_method()
    source.shipping_method = 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),
    )
    source.add_code(coupon.code)
    return source
예제 #9
0
def get_order_and_source(admin_user, product, language, language_fallback):
    # create original source to tamper with

    contact = get_person_contact(admin_user)
    contact.language = language
    contact.save()

    assert contact.language == language  # contact language is naive

    source = BasketishOrderSource(get_default_shop())
    source.status = get_initial_order_status()
    source.billing_address = MutableAddress.objects.create(name="Original Billing")
    source.shipping_address = MutableAddress.objects.create(name="Original Shipping")
    source.customer = contact
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product,
        supplier=get_default_supplier(),
        quantity=1,
        base_unit_price=source.create_price(10),
    )
    source.add_line(
        type=OrderLineType.OTHER,
        quantity=1,
        base_unit_price=source.create_price(10),
        require_verification=True,
    )
    assert len(source.get_lines()) == 2
    source.creator = admin_user

    assert not source._language  # is None because it was not directly assigned
    assert source.language == language_fallback

    creator = OrderCreator()
    order = creator.create_order(source)

    assert order.language == source.language

    return order, source
예제 #10
0
def test_create_without_a_contact(admin_user):
    create_default_order_statuses()
    shop = get_default_shop()
    sm = get_default_shipping_method()
    pm = get_default_payment_method()
    assert not Order.objects.count()
    client = _get_client(admin_user)
    lines = [
        {"type": "other", "sku": "hello", "text": "A greeting", "quantity": 1, "base_unit_price_value": "3.5"},
    ]
    response = client.post("/api/E-Commerce/order/", content_type="application/json", data=json.dumps({
        "shop": shop.pk,
        "customer": None,
        "shipping_method": sm.pk,
        "payment_method": pm.pk,
        "lines": lines
    }))
    assert response.status_code == 201
    assert Order.objects.count() == 1
    order = Order.objects.first()
    assert order.shop == shop
    assert order.customer == None
    assert order.creator == admin_user
    assert order.shipping_method == sm
    assert order.payment_method == pm
    assert order.billing_address == None
    assert order.shipping_address == None
    assert order.payment_status == PaymentStatus.NOT_PAID
    assert order.shipping_status == ShippingStatus.NOT_SHIPPED
    assert order.status == OrderStatus.objects.get_default_initial()
    assert order.taxful_total_price_value == decimal.Decimal(3.5)
    assert order.lines.count() == 3 # shipping line, payment line, 2 product lines, 2 other lines
    for idx, line in enumerate(order.lines.all()[:1]):
        assert line.quantity == decimal.Decimal(lines[idx].get("quantity"))
        assert line.base_unit_price_value == decimal.Decimal(lines[idx].get("base_unit_price_value", 0))
        assert line.discount_amount_value == decimal.Decimal(lines[idx].get("discount_amount_value", 0))
예제 #11
0
def test_order_creator_view_2(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    get_initial_order_status()
    supplier = get_default_supplier()
    person = create_random_person()
    person.registration_shop = shop
    person.save()
    person.shops.add(shop)

    create_product("test-sku0", shop=shop, default_price=10, supplier=supplier)
    create_product("test-sku1", shop=shop, default_price=10, supplier=supplier)
    object_created.connect(_add_custom_order_created_message, sender=Order, dispatch_uid="object_created_signal_test")

    initialize_admin_browser_test(browser, live_server, settings)
    browser.driver.set_window_size(1920, 1080)
    _visit_order_creator_view(browser, live_server)
    _test_customer_using_search(browser, person)
    _test_add_lines(browser)
    _test_methods(browser, sm, pm)
    _test_confirm(browser)
    assert Order.objects.first().log_entries.filter(identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1
    object_created.disconnect(sender=Order, dispatch_uid="object_created_signal_test")
예제 #12
0
def test_basket_clearing(rf):
    StoredBasket.objects.all().delete()
    shop = get_default_shop()
    supplier = get_default_supplier()
    product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=50)
    request = rf.get("/")
    request.session = {}
    request.shop = shop
    apply_request_middleware(request)
    basket = get_basket(request)

    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    basket.shipping_method = sm
    basket.payment_method = pm
    basket.save()

    assert basket.shipping_method
    assert basket.payment_method

    basket.clear_all()

    assert not basket.shipping_method
    assert not basket.payment_method
예제 #13
0
def test_encode_method_weights():
    payment_method = get_default_payment_method()
    assert encode_method(payment_method).get("minWeight") is None
    shipping_method = get_default_shipping_method()
    assert encode_method(shipping_method).get("minWeight") is None
예제 #14
0
def test_create_order(admin_user, currency):
    create_default_order_statuses()
    shop = get_default_shop()
    shop.currency = currency
    tax = get_default_tax()
    Currency.objects.get_or_create(code=currency, decimal_places=2)
    shop.save()
    sm = get_default_shipping_method()
    pm = get_default_payment_method()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    default_group = get_default_customer_group()
    default_group.members.add(contact)
    account_manager = create_random_person(locale="en_US", minimum_name_comp_len=5)
    contact.account_manager = account_manager
    contact.save()

    product = create_product(
        sku=printable_gibberish(),
        supplier=get_default_supplier(),
        shop=shop
    )
    assert not Order.objects.count()
    client = _get_client(admin_user)
    lines = [
        {"type": "product", "product": product.id, "quantity": "1", "base_unit_price_value": "5.00"},
        {"type": "product", "product": product.id, "quantity": "2", "base_unit_price_value": "1.00", "discount_amount_value": "0.50"},
        {"type": "other", "sku": "hello", "text": "A greeting", "quantity": 1, "base_unit_price_value": "3.5"},
        {"type": "text", "text": "This was an order!", "quantity": 0},
    ]
    response = client.post("/api/E-Commerce/order/", content_type="application/json", data=json.dumps({
        "shop": shop.pk,
        "shipping_method": sm.pk,
        "payment_method": pm.pk,
        "customer": contact.pk,
        "lines": lines
    }))
    assert response.status_code == 201
    assert Order.objects.count() == 1
    order = Order.objects.first()
    assert order.shop == shop
    assert order.shipping_method == sm
    assert order.payment_method == pm
    assert order.customer == contact
    assert order.creator == admin_user
    assert order.billing_address == contact.default_billing_address.to_immutable()
    assert order.shipping_address == contact.default_shipping_address.to_immutable()
    assert order.payment_status == PaymentStatus.NOT_PAID
    assert order.shipping_status == ShippingStatus.NOT_SHIPPED
    assert order.status == OrderStatus.objects.get_default_initial()
    assert order.taxful_total_price_value == decimal.Decimal(10)
    assert order.lines.count() == 6 # shipping line, payment line, 2 product lines, 2 other lines
    assert order.currency == currency
    for idx, line in enumerate(order.lines.all()[:4]):
        assert line.quantity == decimal.Decimal(lines[idx].get("quantity"))
        assert line.base_unit_price_value == decimal.Decimal(lines[idx].get("base_unit_price_value", 0))
        assert line.discount_amount_value == decimal.Decimal(lines[idx].get("discount_amount_value", 0))

    # Test tax summary
    response_data = json.loads(response.content.decode("utf-8"))
    # Tax summary should not be present here
    assert "summary" not in response_data

    response = client.get('/api/E-Commerce/order/{}/taxes/'.format(order.pk))
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))

    assert "lines" in response_data
    assert "summary" in response_data
    line_summary = response_data["lines"]
    summary = response_data["summary"]
    first_tax_summary = summary[0]

    assert int(first_tax_summary["tax_id"]) == tax.id
    assert first_tax_summary["tax_rate"] == tax.rate

    first_line_summary = line_summary[0]
    assert "tax" in first_line_summary

    response = client.get("/api/E-Commerce/order/%s/" % order.id)
    assert response.status_code == status.HTTP_200_OK
    order_data = json.loads(response.content.decode("utf-8"))
    assert order_data.get("id") == order.id

    assert "available_shipping_methods" in order_data
    assert "available_payment_methods" in order_data

    assert order_data["available_payment_methods"][0]["id"] == pm.id
    assert order_data["available_shipping_methods"][0]["id"] == sm.id

    assert order.account_manager == account_manager
    assert order.customer_groups.count() == contact.groups.count()
    for group in order.customer_groups.all():
        assert contact.groups.filter(id=group.id).exists()

    assert order.tax_group is not None
    assert order.tax_group == contact.tax_group
예제 #15
0
def test_browser_checkout_addresses_horizontal(browser, live_server, settings):
    # initialize
    product_name = "Test Product"
    get_default_shop()
    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    product = create_orderable_product(product_name, "test-123", price=100)
    OrderStatus.objects.create(
        identifier="initial",
        role=OrderStatusRole.INITIAL,
        name="initial",
        default=True
    )

    # initialize test and go to front page
    browser = initialize_front_browser_test(browser, live_server)

    # check that front page actually loaded
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present("Newest Products"))
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))

    click_element(browser, "#product-%s" % product.pk)  # open product from product list
    click_element(browser, "#add-to-cart-button-%s" % product.pk)  # add product to basket
    wait_until_appeared(browser, ".cover-wrap")
    wait_until_disappeared(browser, ".cover-wrap")

    click_element(browser, "#navigation-basket-partial")  # open upper basket navigation menu
    click_element(browser, "a[href='/basket/']")  # click the link to basket in dropdown
    wait_until_condition(browser, lambda x: x.is_text_present("Shopping cart"))  # we are in basket page
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))  # product is in basket

    click_element(browser, "a[href='/checkout/']") # click link that leads to checkout

    customer_name = "Test Tester"
    customer_street = "Test Street"

    customer_city1 = "Los Angeles"
    customer_city2 = "Blumenau"
    customer_city3 = "Vancouver"

    customer_region1 = "CA"
    customer_region2 = "SC"
    customer_region3 = "BC"

    customer_country1 = "US"
    customer_country2 = "BR"
    customer_country3 = "CA"

    # Fill all billing address fields with USA address
    browser.fill("billing-name", customer_name)
    browser.fill("billing-street", customer_street)
    browser.fill("billing-city", customer_city1)
    browser.select("billing-country", customer_country1)
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region1)

    # Fill all shipping address fields - Brazil address
    browser.fill("shipping-name", customer_name)
    browser.fill("shipping-street", customer_street)
    browser.fill("shipping-city", customer_city2)
    browser.select("shipping-country", customer_country2)
    wait_until_appeared(browser, "select[name='shipping-region_code']")
    browser.select("shipping-region_code", customer_region2)

    # Actually, click to send to billing address (copy billing to shipping)
    browser.find_by_css("label[for='same_as_billing']").first.click()

    # check whether fields are disable and the values are equals
    wait_until_condition(browser, lambda x: x.find_by_name("shipping-region_code").has_class("disabled"))
    wait_until_condition(browser, lambda x: x.find_by_name("shipping-country").has_class("disabled"))
    billing_country = browser.find_by_name("billing-country").first
    shipping_country = browser.find_by_name("shipping-country").first
    wait_until_appeared(browser, "select[name='billing-region_code']")
    wait_until_appeared(browser, "select[name='shipping-region_code']")
    billing_region_code = browser.find_by_name("billing-region_code").first
    shipping_region_code = browser.find_by_name("shipping-region_code").first
    assert billing_country.value == shipping_country.value
    assert billing_region_code.value == shipping_region_code.value

    # Actually, send to Canada
    browser.find_by_css("label[for='same_as_billing']").first.click()
    wait_until_condition(browser, lambda x: not x.find_by_name("shipping-region_code").has_class("disabled"))
    wait_until_condition(browser, lambda x: not x.find_by_name("shipping-country").has_class("disabled"))
    browser.fill("shipping-city", customer_city3)
    browser.select("shipping-country", customer_country3)
    wait_until_appeared(browser, "select[name='shipping-region_code']")
    browser.select("shipping-region_code", customer_region3)

    # continue
    click_element(browser, "#addresses button[type='submit']")

    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Shipping & Payment"))
    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))  # shipping method name is present
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))  # payment method name is present

    # back to address phase, we want to send to Brazil nstead
    address_link = browser.find_by_text('1. Addresses')
    address_link.click()

    # all values must be there with correct saved values
    billing_country = browser.find_by_name("billing-country").first
    wait_until_appeared(browser, "select[name='billing-region_code']")
    billing_region_code = browser.find_by_name("billing-region_code").first
    shipping_country = browser.find_by_name("shipping-country").first
    wait_until_appeared(browser, "select[name='shipping-region_code']")
    shipping_region_code = browser.find_by_name("shipping-region_code").first
    assert billing_country.value == customer_country1
    assert billing_region_code.value == customer_region1
    assert shipping_country.value == customer_country3
    assert shipping_region_code.value == customer_region3

    # Fill shipping with Brazil and Billing with Canada
    browser.fill("shipping-city", customer_city2)
    browser.select("shipping-country", customer_country2)
    wait_until_appeared(browser, "select[name='shipping-region_code']")
    browser.select("shipping-region_code", customer_region2)

    browser.fill("billing-city", customer_city3)
    browser.select("billing-country", customer_country3)
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region3)

    # continue
    click_element(browser, "#addresses button[type='submit']")
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Shipping & Payment"))

    click_element(browser, ".btn.btn-primary.btn-lg.pull-right")  # click "continue" on methods page
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Confirmation"))  # we are indeed in confirmation page

    # See that all expected texts are present
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))
    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))
    wait_until_condition(browser, lambda x: x.is_text_present("Delivery"))
    wait_until_condition(browser, lambda x: x.is_text_present("Billing"))
    # check that user information is available
    wait_until_condition(browser, lambda x: x.is_text_present(customer_name))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_street))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_city2))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_city3))
    wait_until_condition(browser, lambda x: x.is_text_present("Canada"))
    wait_until_condition(browser, lambda x: x.is_text_present("Brazil"))

    browser.execute_script('document.getElementById("id_accept_terms").checked=true')  # click accept terms
    click_element(browser, ".btn.btn-primary.btn-lg")
    wait_until_condition(browser, lambda x: x.is_text_present("Thank you for your order!"))
예제 #16
0
def test_browser_checkout_addresses_vertical(browser, live_server, settings):
    with override_settings(E-Commerce_CHECKOUT_VIEW_SPEC=("E-Commerce.front.views.checkout:SinglePageCheckoutView")):
        # initialize
        product_name = "Test Product"
        get_default_shop()
        pm = get_default_payment_method()
        sm = get_default_shipping_method()
        product = create_orderable_product(product_name, "test-123", price=100)
        OrderStatus.objects.create(
            identifier="initial",
            role=OrderStatusRole.INITIAL,
            name="initial",
            default=True
        )

        # initialize test and go to front page
        browser = initialize_front_browser_test(browser, live_server)
        # check that front page actually loaded
        wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
        wait_until_condition(browser, lambda x: x.is_text_present("Newest Products"))
        wait_until_condition(browser, lambda x: x.is_text_present(product_name))

        click_element(browser, "#product-%s" % product.pk)  # open product from product list
        click_element(browser, "#add-to-cart-button-%s" % product.pk)  # add product to basket

        wait_until_appeared(browser, ".cover-wrap")
        wait_until_disappeared(browser, ".cover-wrap")

        click_element(browser, "#navigation-basket-partial")  # open upper basket navigation menu
        click_element(browser, "a[href='/basket/']")  # click the link to basket in dropdown
        wait_until_condition(browser, lambda x: x.is_text_present("Shopping cart"))  # we are in basket page
        wait_until_condition(browser, lambda x: x.is_text_present(product_name))  # product is in basket

        click_element(browser, "a[href='/checkout/']") # click link that leads to checkout
        wait_until_appeared(browser, "h4.panel-title")

        customer_name = "Test Tester"
        customer_street = "Test Street"

        customer_city1 = "Los Angeles"
        customer_city2 = "Chiedo"

        customer_region1 = "CA"
        customer_region2 = "My Region Name"

        customer_country1 = "US"
        customer_country2 = "AR"    # Doesn't have region codes

        # Fill all billing address fields with USA address
        browser.fill("billing-name", customer_name)
        browser.fill("billing-street", customer_street)
        browser.fill("billing-city", customer_city1)
        browser.select("billing-country", customer_country1)
        wait_until_appeared(browser, "select[name='billing-region_code']")
        browser.select("billing-region_code", customer_region1)

        # Click to send to billing address (copy billing to shipping)
        browser.find_by_css("label[for='same_as_billing']").first.click()

        # continue
        click_element(browser, "#addresses button[type='submit']")

        wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment"))
        # continue on methods page
        click_element(browser, ".btn.btn-primary.btn-lg.pull-right")
        wait_until_condition(browser, lambda x: x.is_text_present("Confirmation"))

        # See that all expected texts are present
        wait_until_condition(browser, lambda x: x.is_text_present(customer_name))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_street))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_city1))
        wait_until_condition(browser, lambda x: x.is_text_present("United States"))

        # back to address phase, we want to send to Argentina
        browser.find_by_css("a[data-phase='addresses']").first.click()

        # all values must be there with correct saved values
        billing_country = browser.find_by_name("billing-country").first
        wait_until_appeared(browser, "select[name='billing-region_code']")
        billing_region_code = browser.find_by_name("billing-region_code").first
        shipping_country = browser.find_by_name("shipping-country").first
        wait_until_appeared(browser, "select[name='shipping-region_code']")
        shipping_region_code = browser.find_by_name("shipping-region_code").first
        assert billing_country.value == customer_country1
        assert billing_region_code.value == customer_region1
        assert shipping_country.value == customer_country1
        assert shipping_region_code.value == customer_region1

        # same_as_billing is not checked
        assert not browser.find_by_css("label[for='same_as_billing']").first.checked

        # click on same as billing twice, so we copy and clean the field, just to try messing
        browser.find_by_css("label[for='same_as_billing']").first.click()
        browser.find_by_css("label[for='same_as_billing']").first.click()

        # region field should be enabled
        wait_until_condition(browser, lambda x: not x.find_by_name("shipping-region_code").has_class("disabled"))

        # Fill all shipping address fields - Argentina address
        browser.fill("shipping-name", customer_name)
        browser.fill("shipping-street", customer_street)
        browser.fill("shipping-city", customer_city2)
        browser.select("shipping-country", customer_country2)
        browser.fill("shipping-region", customer_region2)

        # continue
        click_element(browser, "#addresses button[type='submit']")
        wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment"))
        # continue
        click_element(browser, ".btn.btn-primary.btn-lg.pull-right")
        wait_until_condition(browser, lambda x: x.is_text_present("Confirmation"))

        wait_until_condition(browser, lambda x: x.is_text_present(customer_name))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_street))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_city1))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_city2))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_region1))
        wait_until_condition(browser, lambda x: x.is_text_present(customer_region2))
        wait_until_condition(browser, lambda x: x.is_text_present("Argentina"))
        wait_until_condition(browser, lambda x: x.is_text_present("United States"))

        browser.execute_script('document.getElementById("id_accept_terms").checked=true')  # click accept terms
        click_element(browser, ".btn.btn-primary.btn-lg")  # click "place order"

        wait_until_condition(browser, lambda x: x.is_text_present("Thank you for your order!"))  # order succeeded
예제 #17
0
def get_frontend_order_state(contact, payment_method, product_price, valid_lines=True):
    """
    Get a dict structure mirroring what the frontend JavaScript would submit.
    :type contact: Contact|None
    """
    activate("en")
    shop = get_default_shop()
    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()
    if valid_lines:
        lines = [
            {"id": "x", "type": "product", "product": {"id": product.id}, "quantity": "1", "baseUnitPrice": product_price},
            {"id": "z", "type": "text", "text": "This was an order!", "quantity": 0},
        ]
    else:
        unshopped_product = create_product(sku=printable_gibberish(), supplier=get_default_supplier())
        not_visible_product = create_product(
            sku=printable_gibberish(),
            supplier=get_default_supplier(),
            shop=shop
        )
        not_visible_shop_product = not_visible_product.get_shop_instance(shop)
        not_visible_shop_product.visibility = ShopProductVisibility.NOT_VISIBLE
        not_visible_shop_product.save()
        lines = [
            {"id": "x", "type": "product"},  # no product?
            {"id": "x", "type": "product", "product": {"id": unshopped_product.id}},  # not in this shop?
            {"id": "y", "type": "product", "product": {"id": -product.id}},  # invalid product?
            {"id": "z", "type": "other", "quantity": 1, "unitPrice": "q"},  # what's that price?
            {"id": "rr", "type": "product", "quantity": 1, "product": {"id": not_visible_product.id}}  # not visible
        ]

    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_default_shipping_method().id},
            "paymentMethod": {"id": payment_method.id},
        },
        "shop": {
            "selected": {
                "id": shop.id,
                "name": shop.name,
                "currency": shop.currency,
                "priceIncludeTaxes": shop.prices_include_tax
            }
        }
    }
    return state
예제 #18
0
def create_order(request, creator, customer, product):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    default_pm = get_default_payment_method()
    default_sm = get_default_shipping_method()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=shop,
        payment_method=default_pm,
        shipping_method=default_sm,
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(
        pricing_context=request,
        order_line=product_order_line,
        product=product,
        quantity=5,
        supplier=supplier)

    assert product_order_line.text == product.safe_translation_getter("name")
    product_order_line.base_unit_price = shop.create_price(100)
    assert product_order_line.price.value > 0
    product_order_line.save()

    line_tax = get_line_taxes_for(product_order_line)[0]

    order_line_tax = OrderLineTax.from_tax(
        tax=line_tax.tax,
        base_amount=line_tax.base_amount,
        order_line=product_order_line,
    )
    order_line_tax.save()  # Save order_line_tax before linking to order_line.tax
    product_order_line.taxes.add(order_line_tax)

    discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
    discount_order_line.discount_amount = shop.create_price(30)
    assert discount_order_line.discount_amount.value == 30
    assert discount_order_line.price.value == -30
    assert discount_order_line.base_unit_price.value == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()

    assert not order.can_set_complete()

    base = 5 * shop.create_price(100).amount
    discount = shop.create_price(30).amount
    tax_value = line_tax.amount
    if not order.prices_include_tax:
        assert order.taxless_total_price.amount == base - discount
        assert order.taxful_total_price.amount == base + tax_value - discount
    else:
        assert_almost_equal(order.taxless_total_price.amount, base - tax_value - discount)
        assert_almost_equal(order.taxful_total_price.amount, base - discount)

    assert not order.is_fully_shipped()
    shipment = order.create_shipment_of_all_products(supplier=supplier)
    assert order.is_fully_shipped()

    assert shipment.total_products == 5, "All products were shipped"
    assert shipment.weight == product.gross_weight * 5 / 1000, "Gravity works"
    assert not order.get_unshipped_products(), "Nothing was left in the warehouse"

    assert order.can_set_complete()

    order.create_payment(order.taxful_total_price)
    assert order.is_paid()
    assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!"
    assert order.has_products()

    assert order.get_available_shipping_methods()
    assert order.get_available_payment_methods()

    assert default_sm in order.get_available_shipping_methods()
    assert default_pm in order.get_available_payment_methods()
예제 #19
0
def test_browser_checkout_disable_methods(browser, live_server, settings, delete_method):
    # initialize
    product_name = "Test Product"
    shop = get_default_shop()

    payment_method = get_default_payment_method()
    shipping_method = get_default_shipping_method()

    product = create_orderable_product(product_name, "test-123", price=100)
    OrderStatus.objects.create(
        identifier="initial",
        role=OrderStatusRole.INITIAL,
        name="initial",
        default=True
    )

    # initialize test and go to front page
    browser = initialize_front_browser_test(browser, live_server)

    # check that front page actually loaded
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present("Newest Products"))
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))

    click_element(browser, "#product-%s" % product.pk)  # open product from product list
    click_element(browser, "#add-to-cart-button-%s" % product.pk)  # add product to basket

    wait_until_appeared(browser, ".cover-wrap")
    wait_until_disappeared(browser, ".cover-wrap")

    click_element(browser, "#navigation-basket-partial")  # open upper basket navigation menu
    click_element(browser, "a[href='/basket/']")  # click the link to basket in dropdown
    wait_until_condition(browser, lambda x: x.is_text_present("Shopping cart"))  # we are in basket page
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))  # product is in basket

    click_element(browser, "a[href='/checkout/']") # click link that leads to checkout

    customer_name = "Test Tester"
    customer_street = "Test Street"
    customer_city = "Test City"
    customer_region = "CA"
    customer_country = "US"

    # Fill all necessary information
    browser.fill("billing-name", customer_name)
    browser.fill("billing-street", customer_street)
    browser.fill("billing-city", customer_city)
    browser.select("billing-country", customer_country)
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region)

    browser.fill("billing-name", customer_name)
    browser.fill("billing-street", customer_street)
    browser.fill("billing-city", customer_city)
    browser.select("billing-country", customer_country)
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region)

    click_element(browser, "#addresses button[type='submit']")  # This shouldn't submit since missing required fields

    # Fill rest of the fields
    browser.fill("shipping-name", customer_name)
    browser.fill("shipping-street", customer_street)
    browser.fill("shipping-city", customer_city)
    browser.select("shipping-country", customer_country)

    click_element(browser, "#addresses button[type='submit']")
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Shipping & Payment"))
    wait_until_condition(browser, lambda x: x.is_text_present(payment_method.name))
    wait_until_condition(browser, lambda x: x.is_text_present(shipping_method.name))

    browser.find_by_css("input[name='shipping_method'][value='%d']" % shipping_method.pk).first.click()
    browser.find_by_css("input[name='payment_method'][value='%d']" % payment_method.pk).first.click()

    click_element(browser, ".btn.btn-primary.btn-lg.pull-right")  # click "continue" on methods page
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Confirmation"))  # we are indeed in confirmation page

    if delete_method == "payment":
        payment_method.delete()
    else:
        shipping_method.delete()

    click_element(browser, "a[href='/checkout/methods/']")

    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Shipping & Payment"))

    if delete_method == "payment":
        wait_until_condition(browser, lambda x: x.is_text_present("No method is available."))
        wait_until_condition(browser, lambda x: not x.is_text_present(payment_method.name))
        wait_until_condition(browser, lambda x: x.is_text_present(shipping_method.name))
    else:
        wait_until_condition(browser, lambda x: x.is_text_present("No method is available."))
        wait_until_condition(browser, lambda x: x.is_text_present(payment_method.name))
        wait_until_condition(browser, lambda x: not x.is_text_present(shipping_method.name))
예제 #20
0
def test_browser_checkout_horizontal(browser, live_server, settings):
    # initialize
    product_name = "Test Product"
    get_default_shop()
    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    product = create_orderable_product(product_name, "test-123", price=100)
    OrderStatus.objects.create(
        identifier="initial",
        role=OrderStatusRole.INITIAL,
        name="initial",
        default=True
    )

    # initialize test and go to front page
    browser = initialize_front_browser_test(browser, live_server)

    # check that front page actually loaded
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present("Newest Products"))
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))

    click_element(browser, "#product-%s" % product.pk)  # open product from product list
    click_element(browser, "#add-to-cart-button-%s" % product.pk)  # add product to basket

    wait_until_appeared(browser, ".cover-wrap")
    wait_until_disappeared(browser, ".cover-wrap")

    click_element(browser, "#navigation-basket-partial")  # open upper basket navigation menu
    click_element(browser, "a[href='/basket/']")  # click the link to basket in dropdown
    wait_until_condition(browser, lambda x: x.is_text_present("Shopping cart"))  # we are in basket page
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))  # product is in basket

    click_element(browser, "a[href='/checkout/']") # click link that leads to checkout

    customer_name = "Test Tester"
    customer_street = "Test Street"
    customer_city = "Test City"
    customer_region = "CA"
    customer_country = "US"

    # Fill all necessary information
    browser.fill("billing-name", customer_name)
    browser.fill("billing-street", customer_street)
    browser.fill("billing-city", customer_city)
    browser.select("billing-country", customer_country)
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region)

    click_element(browser, "#addresses button[type='submit']")  # This shouldn't submit since missing required fields

    # Fill rest of the fields
    browser.fill("shipping-name", customer_name)
    browser.fill("shipping-street", customer_street)
    browser.fill("shipping-city", customer_city)
    browser.select("shipping-country", customer_country)

    click_element(browser, "#addresses button[type='submit']")
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Shipping & Payment"))

    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))  # shipping method name is present
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))  # payment method name is present

    click_element(browser, ".btn.btn-primary.btn-lg.pull-right")  # click "continue" on methods page

    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Confirmation"))  # we are indeed in confirmation page

    # See that all expected texts are present
    wait_until_condition(browser, lambda x: x.is_text_present(product_name))
    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))
    wait_until_condition(browser, lambda x: x.is_text_present("Delivery"))
    wait_until_condition(browser, lambda x: x.is_text_present("Billing"))

    # check that user information is available
    wait_until_condition(browser, lambda x: x.is_text_present(customer_name))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_street))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_city))
    wait_until_condition(browser, lambda x: x.is_text_present("United States"))

    browser.execute_script('document.getElementById("id_accept_terms").checked=true')  # click accept terms
    click_element(browser, ".btn.btn-primary.btn-lg")  # click "place order"

    wait_until_condition(browser, lambda x: x.is_text_present("Thank you for your order!"))  # order succeeded
예제 #21
0
def test_broken_order(admin_user):
    """
    """
    quantities = [44, 23, 65]
    expected = sum(quantities) * 50
    expected_based_on = expected / 1.5

    # E-Commerce is calculating taxes per line so there will be some "errors"
    expected_based_on = ensure_decimal_places(Decimal("%s" % (expected_based_on + 0.01)))

    shop = get_default_shop()

    supplier = get_default_supplier()
    product1 = create_product("simple-test-product1", shop, supplier, 50)
    product2 = create_product("simple-test-product2", shop, supplier, 50)
    product3 = create_product("simple-test-product3", shop, supplier, 50)

    tax = get_default_tax()

    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address(country="US")
    shipping_address = get_address(name="Test street", country="US")
    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_default_payment_method()
    source.shipping_method = get_default_shipping_method()

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product1,
        supplier=get_default_supplier(),
        quantity=quantities[0],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product2,
        supplier=get_default_supplier(),
        quantity=quantities[1],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product3,
        supplier=get_default_supplier(),
        quantity=quantities[2],
        base_unit_price=source.create_price(50),
    )

    currency = "EUR"
    summary = source.get_tax_summary()


    assert len(summary) == 1
    summary = summary[0]

    assert summary.taxful == Money(expected, "EUR")
    assert summary.based_on == Money(expected_based_on, "EUR")

    # originally non-rounded value
    assert bankers_round(source.get_total_tax_amount()) == summary.tax_amount

    assert source.taxless_total_price.value == expected_based_on
    assert summary.taxful.value == source.taxful_total_price.value

    assert summary.tax_amount == Money(bankers_round(source.taxful_total_price.value - source.taxless_total_price.value), currency)
    assert summary.taxful == summary.raw_based_on + summary.tax_amount

    assert summary.tax_rate == tax.rate
    assert summary.taxful.value == (summary.based_on + summary.tax_amount).value - Decimal("%s" % 0.01)

    # create order from basket
    creator = OrderCreator()
    order = creator.create_order(source)
    assert order.taxless_total_price.value == expected_based_on

    # originally non-rounded value
    assert bankers_round(order.get_total_tax_amount()) == summary.tax_amount
예제 #22
0
def login_and_finish_up_the_checkout(browser, live_server, test_username, test_email, test_password):
    fields = browser.driver.find_elements_by_name("login-username")
    # there should be only a single username field
    assert len(fields) == 1

    browser.fill("login-username", test_email)
    browser.fill("login-password", test_password)
    click_element(browser, "button[name='login']")

    wait_until_condition(browser, lambda x: x.is_text_present("Addresses"), timeout=100)
    # Reload here just in case since there might have been reload with JS
    # which might cause issues with tests since the elements is in cache
    browser.reload()

    # This should be first order upcoming
    assert Order.objects.count() == 0

    # Fnish the checkout
    customer_name = "Test Tester"
    customer_street = "Test Street"
    customer_city = "Test City"
    customer_region = "CA"
    customer_country = "US"

    # Fill all necessary information
    browser.fill("billing-name", customer_name)
    browser.fill("billing-street", customer_street)
    browser.fill("billing-city", customer_city)
    wait_until_appeared(browser, "#id_billing-region")
    browser.select("billing-country", customer_country)
    wait_until_disappeared(browser, "#id_billing-region")
    wait_until_appeared(browser, "select[name='billing-region_code']")
    browser.select("billing-region_code", customer_region)

    click_element(browser, "#addresses button[type='submit']")  # Shouldn't submit since required fields

    browser.fill("shipping-name", customer_name)
    browser.fill("shipping-street", customer_street)
    browser.fill("shipping-city", customer_city)
    wait_until_appeared(browser, "#id_shipping-region")
    browser.select("shipping-country", customer_country)
    wait_until_disappeared(browser, "#id_shipping-region")
    wait_until_appeared(browser, "select[name='shipping-region_code']")

    click_element(browser, "#addresses button[type='submit']")
    wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment"))

    pm = get_default_payment_method()
    sm = get_default_shipping_method()

    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))  # shipping method name is present
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))  # payment method name is present

    click_element(browser, ".btn.btn-primary.btn-lg.pull-right")  # click "continue" on methods page

    wait_until_condition(browser, lambda x: x.is_text_present("Confirmation"))  # we are indeed in confirmation page
    product = Product.objects.first()

    # See that all expected texts are present
    wait_until_condition(browser, lambda x: x.is_text_present(product.name))
    wait_until_condition(browser, lambda x: x.is_text_present(sm.name))
    wait_until_condition(browser, lambda x: x.is_text_present(pm.name))
    wait_until_condition(browser, lambda x: x.is_text_present("Delivery"))
    wait_until_condition(browser, lambda x: x.is_text_present("Billing"))

    # check that user information is available
    wait_until_condition(browser, lambda x: x.is_text_present(customer_name))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_street))
    wait_until_condition(browser, lambda x: x.is_text_present(customer_city))
    wait_until_condition(browser, lambda x: x.is_text_present("United States"))

    browser.execute_script('document.getElementById("id_accept_terms").checked=true')  # click accept terms
    click_element(browser, ".btn.btn-primary.btn-lg")  # click "place order"

    wait_until_condition(browser, lambda x: x.is_text_present("Thank you for your order!"))  # order succeeded

    # Let's make sure the order now has a customer
    assert Order.objects.count() == 1
    order = Order.objects.first()
    assert order.customer == PersonContact.objects.filter(user__username=test_username).first()
    assert order.customer.name == customer_name
    assert order.customer.default_shipping_address is not None
    assert order.customer.default_billing_address is not None
    assert order.customer.user.username == test_username