예제 #1
0
def test_product_create(browser, admin_user, live_server, settings):
    activate("en")
    shop = get_default_shop()
    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    configuration.set(None, "shuup_product_tour_complete", True)
    object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test")
    initialize_admin_browser_test(browser, live_server, settings)

    url = reverse("shuup_admin:shop_product.new")
    browser.visit("%s%s" % (live_server, url))
    sku = "testsku"
    name = "Some product name"
    price_value = 10
    short_description = "short but gold"

    browser.fill("base-sku", sku)
    browser.fill("base-name__en", name)
    browser.fill("base-short_description__en", short_description)
    browser.fill("shop%s-default_price_value" % shop.pk, price_value)

    configuration.set(None, "shuup_category_tour_complete", True)
    _add_primary_category(browser, shop)
    _add_additional_category(browser, shop)

    click_element(browser, "button[form='product_form']")
    wait_until_appeared(browser, "div[class='message success']")
    product = Product.objects.filter(sku=sku).first()
    assert product.log_entries.filter(identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1
    object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test")
    shop_product = product.get_shop_instance(shop)
    assert shop_product.categories.count() == 2
예제 #2
0
def _set_settings(browser):
    assert not browser.is_text_present("Account Manager")
    browser.find_by_css(".btn.btn-default.btn-inverse").click()
    browser.find_by_css(".btn.btn-xs.btn-success.btn-add-sortable").first.click()
    browser.find_by_css(".btn.btn-success").first.click()
    wait_until_appeared(browser, ".picotable-item-info")
    wait_until_condition(browser, lambda x: x.is_text_present("Account Manager"))
예제 #3
0
def _test_customer_data(browser, person):
    # check defaults
    assert browser.find_by_css("input[name='save-address']").first.checked == True
    assert browser.find_by_css("input[name='ship-to-billing-address']").first.checked == False
    assert browser.find_by_css("input[name='order-for-company']").first.checked == False
    assert not browser.find_by_css("input[name='billing-tax_number']").first['required']
    browser.check("ship-to-billing-address")
    browser.check("order-for-company")
    assert len(browser.find_by_css("input[name='shipping-name']")) == 0, "shipping address column is hidden"
    assert browser.find_by_css("input[name='billing-tax_number']").first['required'], "tax number is required"

    browser.uncheck("order-for-company")
    click_element(browser, "#select-existing-customer")
    browser.windows.current = browser.windows[1]
    wait_until_appeared(browser, "a")
    # click second row - first row is admin
    browser.find_by_css("tbody tr")[1].find_by_css("a").click()
    browser.windows.current = browser.windows[0]
    # check fields were set
    wait_until_condition(
        browser, lambda x: x.find_by_name("billing-name").value == person.name)
    assert browser.find_by_name("billing-name").value == person.name
    assert browser.find_by_name("billing-street").value == person.default_billing_address.street
    assert browser.find_by_name("billing-city").value == person.default_billing_address.city
    assert browser.find_by_name("billing-country").value == person.default_billing_address.country
예제 #4
0
def _test_customer_using_search(browser, person):
    click_element(browser, "#customer-search .select2")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.find_by_css("input.select2-search__field").first.value = person.first_name
    wait_until_appeared(browser, ".select2-results__option[aria-selected='false']")
    browser.execute_script('$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    wait_until_condition(browser, lambda x: len(x.find_by_css(".view-details-link")) == 1)
예제 #5
0
def _test_customer_data(browser, person):
    browser.driver.execute_script("window.scrollTo(0, 200);")
    # check defaults
    assert browser.find_by_css("input[name='save-address']").first.checked == True
    assert browser.find_by_css("input[name='ship-to-billing-address']").first.checked == False
    assert browser.find_by_css("input[name='order-for-company']").first.checked == False
    assert not browser.find_by_css("input[name='billing-tax_number']").first["required"]
    browser.find_by_css("input[name=ship-to-billing-address]").check()
    assert browser.find_by_css("input[name=ship-to-billing-address]").first.checked
    browser.find_by_css("input[name='order-for-company']").check()
    assert browser.find_by_css("input[name='order-for-company']").first.checked
    wait_until_condition(browser, lambda x: x.find_by_css("input[name='billing-tax_number']").first["required"])
    assert len(browser.find_by_css("input[name='shipping-name']")) == 0, "shipping address column is hidden"

    browser.find_by_css("input[name='order-for-company']").uncheck()
    click_element(browser, "#select-existing-customer")
    browser.windows.current = browser.windows[1]
    wait_until_appeared(browser, "a")

    # click second row - first row is admin
    browser.find_by_css("tbody tr")[1].find_by_css("a").click()

    # Wait until there is only one window left
    # after that is safe to switch the current window
    # back and test the results of the customer pick.
    wait_until_condition(browser, lambda x: len(browser.windows) == 1, timeout=30)
    browser.windows.current = browser.windows[0]
    # check fields were set
    wait_until_condition(browser, lambda x: x.find_by_name("billing-name").value == person.name)
    assert browser.find_by_name("billing-name").value == person.name
    assert browser.find_by_name("billing-street").value == person.default_billing_address.street
    assert browser.find_by_name("billing-city").value == person.default_billing_address.city
    assert browser.find_by_name("billing-country").value == person.default_billing_address.country
    click_element(browser, "#clear-customer")
    wait_until_condition(browser, lambda x: "new customer" in x.find_by_css("#customer-description").text)
예제 #6
0
def _save_category(iframe):  # TODO: Revise! It seems that iframes are hard for Travis
    time.sleep(3)  # Let's just wait here to the iFrame to open fully (for Chrome and headless)
    wait_until_appeared(iframe, "button[form='category_form']")
    try:
        click_element(iframe, "button[form='category_form']")
    except selenium.common.exceptions.SessionNotCreatedException as e:
        click_element(iframe, "button[form='category_form']")
예제 #7
0
def _set_settings(browser):
    assert not browser.is_text_present("Internal Identifier")
    browser.find_by_css(".btn.btn-default.btn-inverse").click()
    browser.find_by_id("id_view_configuration_contact_identifier").click()
    browser.find_by_css(".btn.btn-success").click()
    wait_until_appeared(browser, ".picotable-item-info")
    assert browser.is_text_present("Internal Identifier")
예제 #8
0
def _set_settings(browser):
    assert not browser.is_text_present("Internal Identifier")
    browser.find_by_css(".btn.btn-default.btn-inverse").click()
    browser.find_by_id("id_view_configuration_contact_identifier").click()
    browser.find_by_css(".btn.btn-success").click()
    wait_until_appeared(browser, ".picotable-item-info")
    assert browser.is_text_present("Internal Identifier")
예제 #9
0
def _test_language_change(browser):
    assert browser.is_element_present_by_css("h2[class='block-title']")
    # By default the initialization the admin should be in English
    found_customer_details_en = False
    for block_title in browser.find_by_css("h2[class='block-title']"):
        if "Customer Details" in block_title.text:
            found_customer_details_en = True
    assert found_customer_details_en

    # Make sure that the translations is handled correctly and change to Finnish
    browser.find_by_id("dropdownMenu").click()
    browser.find_by_xpath('//a[@data-value="fi"]').first.click()

    wait_until_appeared(browser, "h2[class='block-title']")
    found_customer_details_fi = False
    for block_title in browser.find_by_css("h2[class='block-title']"):
        if "Asiakkaan tiedot" in block_title.text:
            found_customer_details_fi = True

    assert found_customer_details_fi

    # And back in English
    browser.find_by_id("dropdownMenu").click()
    browser.find_by_xpath('//a[@data-value="en"]').first.click()
    wait_until_appeared(browser, "h2[class='block-title']")
예제 #10
0
def set_status(browser, order, status):
    click_element(browser, "button.set-status-button")
    form_action = reverse("shuup_admin:order.set-status", kwargs={"pk": order.pk})
    click_element(browser, "button[formaction='%s'][value='%s']" % (form_action, status.pk))
    wait_until_appeared(browser, "div[class='message success']")
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Order %s" % order.pk))
    order.refresh_from_db()
    assert order.status.pk == status.pk
예제 #11
0
def _test_toolbar_visibility(browser, live_server, order):
    url = reverse("shuup_admin:order.detail", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_appeared(browser, "#order_details")
    _check_create_refund_link(browser, order, False)
    order.create_payment(order.taxful_total_price)
    browser.reload()
    wait_until_appeared(browser, "#order_details")
    _check_create_refund_link(browser, order, True)
예제 #12
0
def test_dev_onboarding(browser, admin_user, live_server, settings):
    Shop.objects.first().delete()  # Delete first shop created by test initializations
    call_command("shuup_init", *[], **{})
    shop = Shop.objects.first()
    assert shop.maintenance_mode
    initialize_admin_browser_test(browser, live_server, settings, onboarding=True)

    browser.fill("address-first_name", "Matti")
    browser.fill("address-last_name", "Teppo")
    browser.fill("address-phone", "112")
    browser.fill("address-street", "Teststreet")
    browser.fill("address-postal_code", "20540")
    browser.fill("address-city", "Turku")

    click_element(browser, "#select2-id_address-country-container")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.find_by_css("input.select2-search__field").first.value = "Finland"
    wait_until_appeared(browser, ".select2-results__option:not([aria-live='assertive'])")
    browser.execute_script('$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("To start accepting payments right away"))
    click_element(browser, "div[data-name='manual_payment'] button[name='activate']")
    browser.fill("manual_payment-service_name", "Laskulle")
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("To start shipping products right away"))
    click_element(browser, "div[data-name='manual_shipping'] button[name='activate']")
    browser.fill("manual_shipping-service_name", "Kotiinkuljetus")
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("theme for your shop"))
    click_element(browser, "div[data-identifier='candy_pink'] button[data-theme='shuup.themes.classic_gray']")
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("initial content and configure"))
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("install some sample data"))
    browser.execute_script('document.getElementsByName("sample-categories")[0].checked=true')
    browser.execute_script('document.getElementsByName("sample-products")[0].checked=true')
    click_element(browser, "button[name='next']")

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Shuup!"))

    click_element(browser, "input[value='Publish shop']")

    shop.refresh_from_db()
    assert not shop.maintenance_mode
    assert Product.objects.count() == 10
    supplier = Supplier.objects.first()
    customer = AnonymousContact()
    assert len([
        product for product in Product.objects.all()
            if product.get_shop_instance(shop).is_orderable(supplier, customer, 1)
    ]) == 10
예제 #13
0
def _add_product_to_basket_from_category(live_server, browser, first_category, shop):
    url = reverse("shuup:category", kwargs={"pk": first_category.pk, "slug": first_category.slug})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present(first_category.name))

    # Make sure that the correct price is visible
    product = Product.objects.filter(sku="test-sku-2").first()
    selector = "#product-%s div.price-line span.lead strong" % product.id
    wait_until_condition(browser, lambda x: "720" in x.find_by_css(selector).first.text)

    # Test product price update
    new_price = 42
    shop_product = product.get_shop_instance(shop)
    shop_product.default_price_value = new_price
    shop_product.save()

    discount_amount = 5
    _create_category_product_discount(first_category, shop, discount_amount)

    browser.reload()
    wait_until_condition(
        browser,
        lambda x: str(new_price - discount_amount) in x.find_by_css(selector).first.text
    )

    # Go to product detail and update the price one more time
    click_element(browser, selector)

    product_detail_price_selector = "#product-price-div-%s span.product-price strong" % product.id
    wait_until_appeared(browser, product_detail_price_selector)
    wait_until_condition(
        browser,
        lambda x: str(new_price - discount_amount) in x.find_by_css(product_detail_price_selector).first.text)

    last_price = 120.53
    shop_product = product.get_shop_instance(shop)
    shop_product.default_price_value = last_price
    shop_product.save()

    new_discount_amount = 10
    _create_category_product_discount(first_category, shop, new_discount_amount)

    browser.reload()
    wait_until_condition(
        browser,
        lambda x: str(last_price - new_discount_amount) in x.find_by_css(product_detail_price_selector).first.text
    )

    # Add product to basket and navigate to basket view
    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
예제 #14
0
def _test_confirm(browser):
    total = sum([decimal.Decimal(total_el.value) for total_el in browser.find_by_css("input[name='total']")])
    assert str(total) in browser.find_by_css(".order-footer h2").text, "order total is correct"
    click_element(browser, ".order-footer button")
    wait_until_appeared(browser, ".btn-danger")  # wait until the back button appears
    assert len(browser.find_by_css("table tbody tr")) == 5, "2 line items, 2 methods, 1 total line shown in confirmation table"
    # click confirm
    click_element(browser, ".btn-success")
    wait_until_appeared(browser, "#details-status-section")
    assert Order.objects.count() == 1, "order created"
예제 #15
0
def _test_regions(browser, person):
    with pytest.raises(ElementDoesNotExist):
        browser.find_by_css("input[name='billing-region_code']").first
    assert browser.find_by_css("input[name='billing-region']").first
    browser.select("billing-country", "US")
    wait_until_appeared(browser, "select[name='billing-region_code']")
    with pytest.raises(ElementDoesNotExist):
        browser.find_by_css("input[name='billing-region']").first
    browser.select("billing-region_code", "CA")
    browser.select("billing-country", "CG")  # Congo does not have regions defined
    wait_until_appeared(browser, "input[name='billing-region']")
    browser.select("billing-country", person.default_billing_address.country)
예제 #16
0
def test_xtheme_snippet_injection(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    initialize_admin_browser_test(browser, live_server, settings)

    url = reverse("shuup_admin:xtheme_snippet.new")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("New Snippet"))
    browser.execute_script("$(\"[name='location']\").val('body_end').trigger('change')")
    browser.execute_script("$(\"[name='snippet_type']\").val('inline_js').trigger('change')")
    browser.execute_script("window.CodeMirror.editors['id_snippet-snippet'].setValue('alert(\"works\")');")
    click_element(browser, "button[type='submit']")
    wait_until_appeared(browser, "div[class='message success']")

    url = reverse("shuup:index")
    browser.visit("%s%s" % (live_server, url))

    def has_alert(browser):
        try:
            return browser.get_alert().text == "works"
        except:
            return False

    wait_until_condition(browser, has_alert)
    browser.get_alert().accept()

    theme = get_current_theme(shop)
    snippet = Snippet.objects.filter(shop=shop).first()
    snippet.themes = [theme.identifier]
    snippet.save()

    cache.clear()
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, has_alert)
    browser.get_alert().accept()

    snippet.themes = ["doesnt-exist"]
    snippet.save()

    cache.clear()
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    with pytest.raises(Exception):
        browser.get_alert()

    # delete the snippet
    url = reverse("shuup_admin:xtheme_snippet.edit", kwargs=dict(pk=snippet.pk))
    browser.visit("%s%s" % (live_server, url))
    assert Snippet.objects.filter(shop=shop).exists()

    click_element(browser, ".shuup-toolbar button.btn.btn-danger")
    browser.get_alert().accept()
    wait_until_condition(browser, lambda x: not Snippet.objects.filter(shop=shop).exists())
예제 #17
0
def guest_ordering_test(browser, live_server):
    browser.fill("login-username", "test-username")
    click_element(browser, "button[name='login']")  # Shouldn't submit
    browser.fill("login-password", "test-password")
    click_element(browser, "button[name='login']")
    wait_until_condition(browser, lambda x: x.is_text_present("Please enter a correct username and password."))
    wait_until_appeared(browser, "div.alert.alert-danger")

    click_element(browser, "button[data-id='id_checkout_method_choice-register']")
    click_element(browser, "li[data-original-index='0'] a")
    click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Addresses"))
    url = reverse("shuup:checkout", kwargs={"phase": "checkout_method"})
    browser.visit("%s%s" % (live_server, url))
def guest_ordering_test(browser, live_server):
    browser.fill("login-username", "test-username")
    click_element(browser, "button[name='login']")
    wait_until_appeared(browser, "div.form-group.passwordinput.required.has-error")
    browser.fill("login-password", "test-password")
    click_element(browser, "button[name='login']")
    wait_until_condition(browser, lambda x: x.is_text_present("Please enter a correct username and password."))
    wait_until_appeared(browser, "div.alert.alert-danger")

    click_element(browser, "button[data-id='id_checkout_method_choice-register']")
    click_element(browser, "li[data-original-index='0'] a")
    click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Addresses"))
    url = reverse("shuup:checkout", kwargs={"phase": "checkout_method"})
    browser.visit("%s%s" % (live_server, url))
예제 #19
0
def _test_create_full_refund(browser, live_server, order):
    url = reverse("shuup_admin:order.create-refund", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("Refunded: %s" % format_money(order.shop.create_price("0.00"))))
    wait_until_condition(browser, lambda x: x.is_text_present("Remaining: %s" % format_money(order.taxful_total_price)))
    url = reverse("shuup_admin:order.create-full-refund", kwargs={"pk": order.pk})
    click_element(browser, "a[href='%s']" % url)
    wait_until_condition(browser, lambda x: x.is_text_present("Refund Amount: %s" % format_money(order.taxful_total_price)))
    click_element(browser, "#create-full-refund")
    wait_until_appeared(browser, "#order_details")
    _check_create_refund_link(browser, order, False)
    order.refresh_from_db()
    assert not order.taxful_total_price
    assert order.is_paid()
    assert order.is_fully_shipped()
def navigate_to_checkout(browser, product):
    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
예제 #21
0
def test_xtheme_plugin_form_language_order(admin_user, browser, live_server, settings, default_language):
    """
    Test that the first language option is the Parler default

    As you can see, we check for that the page has loaded and we use a sleep of 1 second.
    This is necessary specially into iframes. On this test, when we click to add a new plugin row
    or after a row selection, the iframe content is changed through a request,
    like a internal link when user clicks on a anchor. We have to make sure the NEW content is loaded
    before doing any element check, because it looks like the iframe won't find the correct elements
    if you start checking that before the new content gets loaded.
    """
    with override_settings(PARLER_DEFAULT_LANGUAGE_CODE=default_language):
        browser = initialize_admin_browser_test(browser, live_server, settings)
        browser.visit(live_server + "/")

        # Start edit
        wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20)
        wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']")
        click_element(browser, ".xt-edit-toggle button[type='submit']")

        placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
        placeholder_name = "front_content"
        wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector))
        click_element(browser, placeholder_selector)

        with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
            # make sure all scripts are loaded
            wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

            wait_until_condition(iframe, lambda x: x.is_text_present("Edit Placeholder: %s" % placeholder_name))
            wait_until_appeared(iframe, "button.layout-add-row-btn")
            time.sleep(1)
            wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

            # click to add a new row
            click_element(iframe, "button.layout-add-row-btn")
            time.sleep(1)
            wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

            # select the last row (the added one)
            click_element(iframe, "button.layout-add-row-btn")
            iframe.find_by_css("div.layout-cell").last.click()
            time.sleep(1)
            wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

            # select the TextPlugin
            wait_until_appeared(iframe, "select[name='general-plugin']")
            iframe.select("general-plugin", "text")
            time.sleep(1)
            wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)
            wait_until_appeared(iframe, "ul.editor-tabs")

            # check the languages order
            languages = [el.text for el in iframe.find_by_css("ul.editor-tabs li a")]
            assert languages[0] == default_language
def test_recently_viewed_products(browser, live_server, settings):
    shop = get_default_shop()
    category = get_default_category()
    category.shops.add(shop)
    category.status = CategoryStatus.VISIBLE
    category.save()
    category_url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug})
    browser = initialize_front_browser_test(browser, live_server)
    for i in range(1, 7):
        product = new_product(i, shop, category)
        product_url = reverse("shuup:product", kwargs={"pk": product.pk, "slug": product.slug})
        browser.visit(live_server + product_url)
        wait_until_appeared(browser, ".product-main")
        browser.visit(live_server + category_url)
        wait_until_appeared(browser, ".categories-nav")
        items = browser.find_by_css(".recently-viewed li")
        assert items.first.text == product.name, "recently clicked product on top"
        assert len(items) == min(i, 5)
예제 #23
0
def _test_add_lines(browser):
    line_items_before = browser.find_by_id("lines").find_by_css('.list-group-item')
    click_element(browser, "#add-line")
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == len(line_items_before) + 1)
    # select product
    click_element(browser, "#lines .list-group-item:last-child a")
    browser.windows.current = browser.windows[1]
    wait_until_appeared(browser, "a")
    click_element(browser, "tbody a:first-of-type")
    browser.windows.current = browser.windows[0]
    wait_until_condition(browser, lambda x: x.find_by_css('#lines input[name="total"]').first.value == '10')
    last_line_item = browser.find_by_css("#lines .list-group-item:last-child")
    assert last_line_item.find_by_css('input[name="quantity"]').first.value == "1", "1 piece added"
    assert last_line_item.find_by_css('input[name="total"]').first.value == "10", "line item total is 10"
    click_element(browser, "#lines .list-group-item:last-child .delete button")
    wait_until_condition(
        browser,
        lambda x: len(x.find_by_css("#lines .list-group-item")) == len(line_items_before))
예제 #24
0
def test_gdpr_consent(browser, live_server, settings):
    shop = get_default_shop()
    index_url = reverse("shuup:index")

    # create a GDPR setting for the shop
    shop_gdpr = GDPRSettings.get_for_shop(shop)
    shop_gdpr.cookie_banner_content = "my cookie banner content"
    shop_gdpr.cookie_privacy_excerpt = "my cookie privacyexcerpt"
    shop_gdpr.enabled = True
    shop_gdpr.save() # Enable GDPR

    browser = initialize_front_browser_test(browser, live_server)
    browser.visit("%s%s" % (live_server, index_url))
    wait_until_appeared(browser, ".gdpr-consent-warn-bar")
    assert (len(browser.find_by_css(".gdpr-consent-preferences")) == 1)
    click_element(browser, "#agree-btn")

    wait_until_condition(browser, lambda x: len(x.find_by_css(".gdpr-consent-warn-bar")) == 0)
    wait_until_condition(browser, lambda x: len(x.find_by_css(".gdpr-consent-preferences")) == 0)
예제 #25
0
def _set_settings(browser, setting_type):
    used_settings = list_view_settings[setting_type]
    default_column_count = used_settings["default_column_count"]
    addable_fields = used_settings["addable_fields"]

    # not selected by default
    for idx, text in addable_fields:
        assert not browser.is_text_present(text)
    #shuup_tests/browser/front/test_category_view.py
    settings_xpath = "(//a[contains(text(),'Settings')])[2]"
    # go to settings
    browser.find_by_xpath(settings_xpath).click()

    # select settings
    for idx, (index_key, text) in enumerate(addable_fields):
        expected_index = default_column_count + 1 + idx
        assert browser.is_text_present(text)
        browser.find_by_xpath("//ul[@id='source-sortable']/li[%d]/button" % index_key).first.click()
        wait_until_appeared_xpath(browser, "//ul[@id='target-sortable']/li[%d]/button" % expected_index)
        # browser.find_by_css(".btn.btn-xs.btn-success.btn-add-sortable").first.click()

    # save settings
    browser.find_by_css(".btn.btn-success").first.click()
    wait_until_appeared(browser, ".picotable-item-info")

    for idx, text in addable_fields:
        wait_until_condition(browser, lambda x: x.is_text_present(text))

    # go back to settings
    browser.find_by_xpath(settings_xpath).click()

    wait_until_appeared_xpath(browser, "//a[contains(text(),'Reset Defaults')]")

    # reset to defaults
    browser.find_by_xpath("//a[contains(text(),'Reset Defaults')]").click()

    # wait
    wait_until_appeared(browser, ".picotable-item-info")

    # not selected by default
    for idx, text in addable_fields:
        assert not browser.is_text_present(text)
예제 #26
0
def test_product_create(browser, admin_user, live_server, settings):
    activate("en")
    shop = get_default_shop()
    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test")
    initialize_admin_browser_test(browser, live_server, settings)

    url = reverse("shuup_admin:shop_product.new")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("New shop product"))

    sku = "testsku"
    name = "Some product name"
    price_value = 10
    short_description = "short but gold"
    move_to_element(browser, "#id_base-sku")
    browser.fill("base-sku", sku)
    browser.fill("base-name__en", name)
    browser.fill("base-short_description__en", short_description)
    browser.fill("shop%s-default_price_value" % shop.pk, price_value)

    _add_primary_category(browser, shop)
    _add_additional_category(browser, shop)

    move_to_element(browser, "button[form='product_form']")
    try:
        click_element(browser, "button[form='product_form']")
        wait_until_appeared(browser, "div[class='message success']")
    except selenium.common.exceptions.WebDriverException as e:
        # TODO: Revise!
        # Give a product save second chance it seems that the save can
        # lag a little and the success message doesn't happen fast
        # enough every single time.
        click_element(browser, "button[form='product_form']")
        wait_until_appeared(browser, "div[class='message success']")
    product = Product.objects.filter(sku=sku).first()
    assert product.log_entries.filter(identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1
    object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test")
    shop_product = product.get_shop_instance(shop)
    assert shop_product.categories.count() == 2
def register_test(browser, live_server, test_username, test_email, test_password):
    click_element(browser, "button[data-id='id_checkout_method_choice-register']")
    click_element(browser, "li[data-original-index='1'] a")
    click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_condition(browser, lambda x: x.is_text_present("Register"))

    browser.find_by_id("id_username").fill(test_username)
    browser.find_by_id("id_email").fill(test_email)
    browser.find_by_id("id_password1").fill(test_password)
    browser.find_by_id("id_password2").fill("typo-%s" % test_password)
    click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_appeared(browser, "div.form-group.passwordinput.required.has-error")

    browser.find_by_id("id_password1").fill(test_password)
    browser.find_by_id("id_password2").fill(test_password)
    click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right")

    wait_until_condition(browser, lambda x: x.is_text_present("Addresses"))
    # 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()

    # Log out and go back to checkout choice phase
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Ensure that the language is still english. It seems that the language might change
    # during the logout.
    browser.find_by_id("language-changer").click()
    browser.find_by_xpath('//a[@class="language"]').first.click()

    # There is no products on basket anymore so let's add one
    product = Product.objects.first()
    product_url = reverse("shuup:product", kwargs={"pk": product.pk, "slug": product.slug})
    browser.visit("%s%s" % (live_server, product_url))
    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")

    browser.visit("%s%s" % (live_server, "/checkout/"))
예제 #28
0
def _test_quick_add_lines(browser):
    assert browser.find_by_css("input[name='auto-add']").first.checked == True
    # add line automatically just by searching and finding direct match
    click_element(browser, "#quick-add .select2")
    wait_until_condition(
        browser, lambda x: len(browser.find_by_css("#quick-add .select2-container--open")) == 1)
    browser.find_by_css("input.select2-search__field").first.value = "test-sku1"
    wait_until_condition(browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == 1)
    line_items = browser.find_by_css("#lines .list-group-item")
    assert len(browser.find_by_css("#quick-add .select2-container--open")) == 1, "select is open after add"
    assert line_items.first.find_by_css('input[name="quantity"]').first.value == '1', "one piece added"

    browser.find_by_css("input.select2-search__field").first.value = "test-sku1"
    wait_until_condition(browser, lambda x: x.find_by_css('#lines input[name="quantity"]').first.value == '2')
    line_items = browser.find_by_id("lines").find_by_css('.list-group-item')
    assert len(line_items) == 1, "only one line item exists"
    assert line_items.first.find_by_css('input[name="quantity"]').first.value == '2', "two pieces added"

    # add line automatically by searching and clicking on match
    browser.find_by_css("input.select2-search__field").first.value = "test-sku"
    wait_until_appeared(browser, ".select2-results__option:not([aria-live='assertive'])")
    browser.execute_script('$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    wait_until_condition(browser, lambda x: x.find_by_css('#lines input[name="quantity"]').first.value == '3')
    assert line_items.first.find_by_css('input[name="quantity"]').first.value == '3', "three pieces added"

    # add line manually
    browser.uncheck("auto-add")
    click_element(browser, "#quick-add .select2")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.find_by_css("input.select2-search__field").first.value = "test-sku0"
    wait_until_appeared(browser, ".select2-results__option:not([aria-live='assertive'])")
    browser.execute_script('$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    wait_until_condition(browser, lambda x: len(x.find_by_css('#lines .list-group-item')) == 2)
    line_items = browser.find_by_id("lines").find_by_css('.list-group-item')
    assert len(line_items) == 2, "two line items exist"
예제 #29
0
def _test_refund_view(browser, live_server, order):
    url = reverse("shuup_admin:order.create-refund", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("Refunded: %s" % format_money(order.shop.create_price("0.00"))))
    assert len(browser.find_by_css("#id_form-0-line_number option")) == 12 # blank + arbitrary amount + num lines
    click_element(browser, "#select2-id_form-0-line_number-container")
    wait_until_appeared(browser, "input.select2-search__field")
    wait_until_appeared(browser, ".select2-results__option[aria-selected='false']")
    browser.execute_script('$($(".select2-results__option")[1]).trigger({type: "mouseup"})') # select arbitrary amount
    wait_until_condition(browser, lambda x: len(x.find_by_css("#id_form-0-text")))
    wait_until_condition(browser, lambda x: len(x.find_by_css("#id_form-0-amount")))
    browser.find_by_css("#id_form-0-text").first.value = "test"
    browser.find_by_css("#id_form-0-amount").first.value = "900"
    move_to_element(browser, "#add-refund")
    click_element(browser, "#add-refund")

    # New line starts here...
    move_to_element(browser, "#add-refund")
    click_element(browser, "#select2-id_form-1-line_number-container")
    wait_until_appeared(browser, "input.select2-search__field")

    elem = browser.find_by_css("input.select2-search__field").first
    elem._element.send_keys("line 1")
    elem._element.send_keys(Keys.RETURN)

    assert decimal.Decimal(browser.find_by_css("#id_form-1-amount").first.value) == decimal.Decimal("100.00")
    assert int(decimal.Decimal(browser.find_by_css("#id_form-1-quantity").first.value)) == 10
    click_element(browser, "button[form='create_refund']")
    _check_create_refund_link(browser, order, True) # can still refund quantity
    _check_order_details_visible(browser)
    order.refresh_from_db()
    assert not order.taxful_total_price
    assert order.is_paid()
    assert not order.is_fully_shipped()
예제 #30
0
파일: test_menu.py 프로젝트: ruqaiya/shuup
def test_menu_small_device(browser, admin_user, live_server, settings):
    get_default_shop()

    browser.driver.set_window_size(480, 960)
    initialize_admin_browser_test(browser, live_server, settings)

    # Lets navigate to orders so we don't click that menu button too fast
    # it seems that without this we click the menu button before the
    # page is actually ready.
    url = reverse("shuup_admin:order.list")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Orders"))

    wait_until_condition(browser, lambda x: x.is_element_present_by_css("#menu-button"))
    browser.find_by_css("#menu-button").first.click()

    wait_until_condition(browser, lambda x: x.is_text_present("Quicklinks"))
    browser.find_by_css(".quicklinks a").first.click()

    wait_until_appeared(browser, ".item-category.item-active")
    browser.find_by_css(".menu-list li a")[1].click()

    wait_until_condition(browser, lambda x: x.is_text_present("New shop product"))
예제 #31
0
파일: test_menu.py 프로젝트: ruqaiya/shuup
def test_menu(browser, admin_user, live_server, settings):
    get_default_shop()
    initialize_admin_browser_test(browser, live_server, settings)

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
    wait_until_condition(browser, lambda x: x.is_text_present("Quicklinks"))

    try:
        browser.find_by_css(".quicklinks a").first.click()
    except selenium.common.exceptions.TimeoutException as e:
        # TODO: Revise!
        # Give the Quicklinks click second chance. It seems there is a way
        # to click it too fast. Wouldn't be too worried this to be actual
        # issue with the menu. Looks like something that happens under
        # 10% of time in my local environment, but main reason for this
        # is Travis.
        browser.find_by_css(".quicklinks a").first.click()


    wait_until_appeared(browser, ".item-category.item-active")
    browser.find_by_css(".menu-list li a")[1].click()

    wait_until_condition(browser, lambda x: x.is_text_present("New shop product"))
예제 #32
0
def test_product_detail(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    product = create_product("test_sku", shop, default_price=10)
    initialize_admin_browser_test(browser, live_server, settings)

    url = reverse("shuup_admin:shop_product.edit", kwargs={"pk": product.get_shop_instance(shop).pk})
    browser.visit("%s%s" % (live_server, url))
    assert browser.find_by_id("id_base-sku").value == product.sku

    # Test product save
    new_sku = "some-new-sku"
    browser.find_by_id("id_base-sku").fill(new_sku)
    browser.execute_script("window.scrollTo(0,0)")
    click_element(browser, "button[form='product_form']")

    # Here saving the product seems to take some time occasionally so it
    # should be worth to wait until the save goes through
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Product edited"), timeout=50)

    product.refresh_from_db()
    check_product_name(browser, product, new_sku)

    # Test that toolbar action item is there
    dropdowns = browser.find_by_css(".btn.dropdown-toggle")
    for dropdown in dropdowns:
        if "Actions" in dropdown.text:
            dropdown.click()

    wait_until_appeared(browser, "a[href='#%s']" % product.sku)
    click_element(browser, "a[href='#%s']" % product.sku)

    # Make sure that the tabs is clickable in small devices
    browser.driver.set_window_size(480, 960)

    click_element(browser, "#product-images-section", header_height=320)
    click_element(browser, "#additional-details-section", header_height=320)
예제 #33
0
def test_xtheme_plugin_form_selected_language_pane(admin_user, browser, live_server, settings, language):
    """
    Test that the current language is selected by default
    """
    browser = initialize_admin_browser_test(browser, live_server, settings, language=language)
    browser.visit(live_server + "/")

    # Start edit
    wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20)
    wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']")
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector))
    click_element(browser, placeholder_selector)

    with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
        # make sure all scripts are loaded
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

        wait_until_condition(iframe, lambda x: x.is_text_present("front_content"))
        wait_until_appeared(iframe, "button.layout-add-row-btn")
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

        # click to add a new row
        click_element(iframe, "button.layout-add-row-btn")
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

        # select the last row (the added one)
        click_element(iframe, "button.layout-add-row-btn")
        iframe.find_by_css("div.layout-cell").last.click()
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

        # select the TextPlugin
        wait_until_appeared(iframe, "select[name='general-plugin']")
        iframe.select("general-plugin", "text")
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)
        wait_until_appeared(iframe, "ul.editor-tabs")

        # check the active language
        assert language == iframe.find_by_css("ul.editor-tabs li.active a").first.text
예제 #34
0
def _add_primary_category(browser, shop):
    assert Category.objects.count() == 0
    select_id = "id_shop%s-primary_category" % shop.pk
    move_to_element(browser, "#%s" % select_id, header_height=100)

    # Quick add new primary category
    wait_until_appeared(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id)
    click_element(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id)
    wait_until_appeared(browser, "#create-object-iframe")
    with browser.get_iframe('create-object-iframe') as iframe:
        wait_until_appeared(iframe, "input[name='base-name__en']")
        iframe.fill("base-name__en", "Test Category")
        _save_category(iframe)

    wait_until_condition(browser, condition=lambda x: not x.is_element_present_by_id("create-object-overlay"))
    check_category_count(browser, 1)
    wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option" % select_id)) == 1)