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
Exemple #2
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"
Exemple #3
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"))
def test_single_page_checkout_with_login_and_register(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)

    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)
Exemple #5
0
def test_product_descriptions(browser, live_server, settings):
    activate("en")
    cache.clear()
    shop = get_default_shop()
    product = create_product("product1",
                             shop=shop,
                             description="<b>My HTML description</b>",
                             short_description="some short of description instead",
                             supplier=get_default_supplier())
    sp = ShopProduct.objects.get(product=product, shop=shop)
    sp.primary_category = get_default_category()
    sp.categories.add(get_default_category())
    sp.save()

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

    # view product detail page
    url = reverse("shuup:product", kwargs={"pk": product.pk, "slug": product.slug})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present(product.short_description))
    assert product.description in browser.html

    # ensure the version is in static files
    assert "style.css?v=%s" % shuup.__version__ in browser.html

    # product preview
    url = reverse("shuup:xtheme_extra_view", kwargs={"view": "products"})
    browser.visit("%s%s" % (live_server, url))
    product_div_name = "product-{}".format(product.pk)
    wait_until_condition(browser, lambda x: x.find_by_css("#{} button.btn".format(product_div_name)))
    browser.execute_script("$('#{} button.btn').click();".format(product_div_name))
    assert product.short_description == browser.find_by_css("#{} p.description".format(product_div_name))[0].html
Exemple #6
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
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())
Exemple #8
0
def test_menu(browser, admin_user, live_server, settings):
    shop = get_default_shop()

    initialize_admin_browser_test(browser, live_server, settings)

    browser.find_by_css(".menu-list li").first.click()
    wait_until_condition(browser, lambda x: x.is_text_present("New product"))

    # Make sure that the menu is clickable in small devices
    browser.driver.set_window_size(480, 960)
    browser.find_by_css("#menu-button").first.click()
    browser.find_by_css(".menu-list li").first.click()
    wait_until_condition(browser, lambda x: x.is_text_present("New product"))
Exemple #9
0
def second_category_sort_test(browser, live_server, shop, category):
    url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug})
    browser.visit("%s%s" % (live_server, url))
    assert not browser.is_text_present("Sort")  # Sort shouldn't be available since default configurations
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12)
    click_element(browser, "#next_page a")
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1, timeout=30)
    click_element(browser, "#previous_page a")
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12, timeout=30)

    # Activate limit page size changer
    set_configuration(
        shop=shop,
        data={
            "sort_products_by_name": True,
            "sort_products_by_name_ordering": 1,
            "sort_products_by_price": True,
            "sort_products_by_price_ordering": 2,
            "limit_product_list_page_size": True
        }
    )
    browser.reload()
    # Set limit to 24
    click_element(browser, "button[data-id='id_limit']")
    click_element(browser, "button[data-id='id_limit'] + .dropdown-menu li[data-original-index='1'] a")
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13)
Exemple #10
0
def categories_filter_test(browser, first_cat, second_cat, third_cat):
    # Add all products in second category to also in first category
    for shop_product in ShopProduct.objects.filter(primary_category=second_cat):
        shop_product.categories.add(first_cat)
    # Add one product including first_cat also to third_cat
    shop_product = ShopProduct.objects.filter(primary_category=first_cat).last()
    shop_product.categories.add(third_cat)

    # Activate categories filter for current category which is the first one
    set_configuration(
        category=first_cat,
        data={
            "override_default_configuration": True,
            "sort_products_by_name": True,
            "sort_products_by_name_ordering": 1,
            "sort_products_by_price": True,
            "sort_products_by_price_ordering": 2,
            "filter_products_by_category": True
        }
    )
    browser.reload()
    wait_until_condition(browser, lambda x: x.is_element_present_by_id("categories-%s" % third_cat.id))
    browser.execute_script("$('#categories-%s').click();" % third_cat.id)
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1)
    browser.execute_script("$('#categories-%s').click();" % second_cat.id)
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1)
    browser.execute_script("$('#categories-%s').click();" % third_cat.id)
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12)
Exemple #11
0
def second_category_sort_test(browser, live_server, shop, category):
    url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug})
    browser.visit("%s%s" % (live_server, url))

    wait_until_condition(browser, lambda x: x.is_element_present_by_css("button[data-id='id_limit']"), timeout=30)
    # Set limit to 24
    click_element(browser, "button[data-id='id_limit']")
    click_element(browser, "button[data-id='id_limit'] + .dropdown-menu li[data-original-index='1'] a")
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30)

    # Check that visibility change affects the product count
    shop_products = ShopProduct.objects.filter(primary_category_id=category.id)[:3]
    for sp in shop_products:
        sp.visibility = ShopProductVisibility.NOT_VISIBLE
        sp.save()

    cache.clear()
    browser.reload()
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 10)

    for sp in shop_products:
        sp.visibility = ShopProductVisibility.ALWAYS_VISIBLE
        sp.save()

    cache.clear()
    browser.reload()
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30)
Exemple #12
0
def basic_sorting_test(browser):
    # Sort from Z to A
    click_element(browser, "button[data-id='id_sort']")
    # WARNING: data-original-index was removed after bootstrap-select 1.6.3
    click_element(browser, "li[data-original-index='1'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)

    # Sort by price (highest first)
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='3'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(sku="sku-8").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)


    # Sort by price (lowest first)
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='2'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)

    # Sort from A to Z
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='0'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(sku="sku-2").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)
Exemple #13
0
def second_category_sort_with_price_filter(browser, category):
    set_configuration(
        category=category,
        data={
            "override_default_configuration": True,
            "filter_products_by_price": True,
            "filter_products_by_price_range_min": 5,
            "filter_products_by_price_range_max": 12,
            "filter_products_by_price_range_size": 3
        }
    )
    browser.reload()

    wait_until_condition(browser, lambda x: len(x.find_by_css("#id_price_range option")) == 5)
    # 5 products and let's filter all products with price less than 5
    click_element(browser, "button[data-id='id_price_range']")
    click_element(browser, "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='1'] a")

    # 4 products and let's filter products with price +12
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 4)
    click_element(browser, "button[data-id='id_price_range']")
    click_element(browser, "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='4'] a")

    # Now 2 products left and now filter with price 8-11
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2)
    click_element(browser, "button[data-id='id_price_range']")
    click_element(browser, "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='3'] a")

    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3)
Exemple #14
0
def second_test_query(browser, live_server, url):
    browser.visit("%s%s?q=Test" % (live_server, url))
    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 7)
    expected_first_prod_id = "product-%s" % Product.objects.filter(sku="sku-4").first().id
    wait_until_condition(browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)

    expected_second_prod_id = "product-%s" % Product.objects.filter(sku="sku-10").first().id
    wait_until_condition(browser, lambda x: x.find_by_css(".product-card")[1]["id"] == expected_second_prod_id)

    expected_third_prod_id = "product-%s" % Product.objects.filter(sku="sku-8").first().id
    wait_until_condition(browser, lambda x: x.find_by_css(".product-card")[2]["id"] == expected_third_prod_id)

    expected_last_prod_id = "product-%s" % Product.objects.filter(sku="sku-2").first().id
    wait_until_condition(browser, lambda x: x.find_by_css(".product-card").last["id"] == expected_last_prod_id)
def test_quick_add(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    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)

    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:
        assert Category.objects.count() == 0
        wait_until_appeared(iframe, "input[name='base-name__en']")
        iframe.fill("base-name__en", "Test Category")
        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']")
        click_element(browser, "button[form='category_form']")
        wait_until_condition(browser, condition=lambda x: Category.objects.count() == 1, timeout=20)

    assert Category.objects.first().name == "Test Category"

    # click to edit the button
    click_element(browser, "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id)

    with browser.get_iframe('create-object-iframe') as iframe:
        wait_until_appeared(iframe, "input[name='base-name__en']")
        new_cat_name = "Changed Name"
        iframe.fill("base-name__en", new_cat_name)
        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']")
        click_element(iframe, "button[form='category_form']")

    wait_until_condition(browser, condition=lambda x: Category.objects.first().name == new_cat_name, timeout=20)

    click_element(browser, "button[form='product_form']")
    wait_until_appeared(browser, "div[class='message success']")
Exemple #16
0
def test_product_detail(browser, admin_user, live_server, settings):
    activate(settings.PARLER_DEFAULT_LANGUAGE_CODE)
    shop = get_default_shop()
    order = create_empty_order(shop=shop)
    order.save()
    initialize_admin_browser_test(browser, live_server, settings)
    url = reverse("shuup_admin:order.detail", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Order %s" % order.pk))

    change_addresses(live_server, browser, order)

    set_status(browser, order, OrderStatus.objects.get_default_processing())
    assert order.can_set_complete()
    set_status(browser, order, OrderStatus.objects.get_default_complete())
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))
Exemple #18
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)
Exemple #19
0
def _activate_basket_campaign_through_coupon(browser, category, shop):
    # We should already be at basket so let's verify the total
    wait_until_condition(browser, lambda x: "110.53" in x.find_by_css("div.total-price strong").first.text)

    coupon_code = _create_coupon_campaign(category, shop)
    browser.fill("code", coupon_code)
    click_element(browser, "#submit-code")

    wait_until_condition(browser, lambda x: x.is_text_present(coupon_code))
    wait_until_condition(browser, lambda x: "-€22.11" in x.find_by_css("div.product-sum h4.price").last.text)
    wait_until_condition(browser, lambda x: "€88.42" in x.find_by_css("div.total-price strong").first.text)
Exemple #20
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)
Exemple #21
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
Exemple #22
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)
Exemple #23
0
def _set_settings(browser, setting_type, creator):
    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)

    browser.find_by_css(".shuup-toolbar .btn.btn-inverse").first.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)

    # save settings
    move_to_element(browser, ".shuup-toolbar .btn.btn-success")
    browser.find_by_css(".shuup-toolbar .btn.btn-success").first.click()
    _check_picotable_item_info(browser, creator)

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

    # go back to settings
    browser.find_by_css(".shuup-toolbar .btn.btn-inverse").first.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
    _check_picotable_item_info(browser, creator)

    # not selected by default
    if creator:
        for idx, text in addable_fields:
           assert not browser.is_text_present(text)
Exemple #24
0
def _add_additional_category(browser, shop):
    assert Category.objects.count() == 1
    select_id = "id_shop%s-categories" % shop.pk
    wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 1)
    browser.execute_script('$("#%s").parent().find("span.quick-add-btn a.btn").click();' % select_id)
    with browser.get_iframe('create-object-iframe') as iframe:
        wait_until_condition(iframe, lambda x: x.is_text_present("New category"))
        category_test_name = "Test Category 2"
        iframe.fill("base-name__en", category_test_name)
        click_element(iframe, "button[form='category_form']")
    wait_until_condition(browser, lambda x: x.is_text_present("New product"))
    assert Category.objects.count() == 2
    wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 2)
Exemple #25
0
def change_addresses(live_server, browser, order):
    edit_url = reverse("shuup_admin:order.edit-addresses", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, edit_url))
    order_edited_log_entries = order.log_entries.filter(identifier=ADDRESS_EDITED_LOG_IDENTIFIER).count()

    edit_address_title = "Save -- Order %s" % order.pk
    wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title))
    # Do nothing just hit the save
    click_element(browser, "button[form='edit-addresses']")
    assert order.log_entries.filter(identifier=ADDRESS_EDITED_LOG_IDENTIFIER).count() == order_edited_log_entries

    # Update billing address email
    browser.visit("%s%s" % (live_server, edit_url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title))
    new_email = "*****@*****.**"
    browser.fill("billing_address-email", new_email)
    assert new_email != order.billing_address.email
    click_element(browser, "button[form='edit-addresses']")
    check_log_entries_count(browser, order, order_edited_log_entries + 1)

    order.refresh_from_db()
    assert new_email == order.billing_address.email
    assert order.billing_address.email != order.shipping_address.email
    assert order.billing_address.pk != order.shipping_address.pk

    # Update shipping address postal code
    browser.visit("%s%s" % (live_server, edit_url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title))
    new_postal_code = "20540"
    browser.fill("shipping_address-postal_code", new_postal_code)
    assert new_postal_code != order.shipping_address.postal_code
    click_element(browser, "button[form='edit-addresses']")
    check_log_entries_count(browser, order, order_edited_log_entries + 2)

    order.refresh_from_db()
    assert new_postal_code == order.shipping_address.postal_code
    assert order.billing_address.postal_code != order.shipping_address.postal_code
    assert order.billing_address.pk != order.shipping_address.pk

    # Now update both same time
    browser.visit("%s%s" % (live_server, edit_url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title))
    click_element(browser, "#billing-to-shipping")
    new_name = "%s (edited)" % order.billing_address.name
    browser.fill("billing_address-name", new_name)
    click_element(browser, "button[form='edit-addresses']")
    check_log_entries_count(browser, order, order_edited_log_entries + 4)
    order.refresh_from_db()
    assert new_name == order.shipping_address.name
    assert order.billing_address.name == order.shipping_address.name
    assert order.billing_address.email == order.shipping_address.email
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/"))
Exemple #27
0
def test_category_product_filters_2(browser, live_server, settings):
    cache.clear()  # Avoid cache from past tests
    shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db()

    # Activate limit page size changer for the shop
    set_configuration(
        shop=shop,
        data={
            "sort_products_by_name": True,
            "sort_products_by_name_ordering": 1,
            "sort_products_by_price": True,
            "sort_products_by_price_ordering": 2,
            "limit_product_list_page_size": 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!"))

    url = reverse("shuup:category", kwargs={"pk": first_cat.pk, "slug": first_cat.slug})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("First Category"))
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    assert not browser.is_text_present("Manufacturers")  # Since not in default configuration
    second_category_sort_test(browser, live_server, shop, second_cat)
    second_category_sort_with_price_filter(browser, second_cat)
Exemple #28
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()
def test_generic_script_template(browser, admin_user, live_server, settings, script_template_cls):
    initialize(browser, live_server, settings)

    url = reverse("shuup_admin:notify.script.list")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_element_present_by_css("div.btn-toolbar a.btn.btn-info"))

    # find the button to load from template
    browser.find_by_css("div.btn-toolbar a.btn.btn-info").first.click()

    identifier = script_template_cls.identifier
    form_id = "form-" + identifier
    button_id = "#{} button.btn.btn-success".format(form_id)
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(button_id))
    browser.find_by_css(button_id).first.click()

    config_url = reverse("shuup_admin:notify.script-template-config", kwargs={"id": identifier})
    wait_until_condition(browser, lambda b: b.url.endswith(config_url), timeout=15)
    wait_until_condition(browser, lambda b: b.is_text_present("Configure the Script Template"))

    # click to create the script
    browser.execute_script("""
        $(document).ready(function(){
            $('#lang-en .summernote-editor').summernote('editor.insertText', 'NEW CONTENT');
        });
    """)
    browser.find_by_id("id_en-subject").fill("custom subject!")
    browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click()

    wait_until_condition(browser, lambda b: b.url.endswith(reverse("shuup_admin:notify.script.list")))

    script = Script.objects.first()
    serialized_steps = script.get_serialized_steps()

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert len(serialized_steps[0]["conditions"]) == 0
    assert serialized_steps[0]["actions"][0]["recipient"]["variable"] == "customer_email"
    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "custom subject!"
    assert "NEW CONTENT" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]
Exemple #30
0
def test_search_product_list(browser, live_server, settings):
    activate("en")
    # initialize
    cache.clear()
    shop = get_default_shop()

    for name, sku, price in PRODUCT_DATA:
        create_orderable_product(name, sku, price=price)

    # 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!"))

    url = reverse("shuup:product_search")
    browser.visit("%s%s?q=test product" % (live_server, url))

    wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 9)

    check_default_ordering(browser)
    # basic_sorting_test(browser)
    second_test_query(browser, live_server, url)
Exemple #31
0
def _test_language_change(browser):
    wait_until_condition(browser, lambda x: x.is_text_present("Customer Details"))

    # 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_condition(browser, condition=lambda x: x.is_text_present("Asiakkaan tiedot"))

    # And back in English
    browser.find_by_id("dropdownMenu").click()
    browser.find_by_xpath('//a[@data-value="en"]').first.click()
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Customer Details"))
Exemple #32
0
def _add_primary_category(browser, shop):
    assert Category.objects.count() == 0
    select_id = "id_shop%s-primary_category" % shop.pk
    browser.execute_script(
        '$("#%s").parent().find("span.quick-add-btn a.btn").click();' %
        select_id)
    with browser.get_iframe('create-object-iframe') as iframe:
        wait_until_condition(iframe,
                             lambda x: x.is_text_present("New category"))
        category_test_name = "Test Category"
        iframe.fill("base-name__en", category_test_name)
        click_element(iframe, "button[form='category_form']")
    wait_until_condition(browser, lambda x: x.is_text_present("New product"))
    assert Category.objects.count() == 1
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#%s option" % select_id)) == 2)
    wait_until_condition(
        browser, lambda x: len(
            x.find_by_css("#%s option[selected='selected']" % select_id)) == 1)
Exemple #33
0
def test_category_product_filters_4(browser, live_server, settings, reindex_catalog):
    """
    Do not show manufacturer option if there is any product
    """
    cache.clear()  # Avoid cache from past tests
    shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db()

    # remove manufacturers from all products
    Product.objects.all().update(manufacturer=None)
    # show manufacturer filter
    set_configuration(
        category=first_cat,
        data={
            "override_default_configuration": True,
            "sort_products_by_name": True,
            "sort_products_by_name_ordering": 1,
            "sort_products_by_price": True,
            "sort_products_by_price_ordering": 2,
            "filter_products_by_manufacturer": True,
        },
    )
    reindex_catalog()

    # 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!"))

    url = reverse("shuup:category", kwargs={"pk": first_cat.pk, "slug": first_cat.slug})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("First Category"))
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    assert not browser.is_text_present("Manufacturers")  # Since there is no product with manufacturer

    # add the manufacturer to the last product so the manufacturer filter is show
    last_product = Product.objects.last()
    last_product.manufacturer = first_manufacturer
    last_product.save()
    reindex_catalog()
    browser.visit("%s%s" % (live_server, url))
    assert browser.is_text_present("Manufacturers")

    # set the shop product hidden
    shop_product = last_product.get_shop_instance(shop)
    shop_product.visibility = ShopProductVisibility.NOT_VISIBLE
    shop_product.save()
    reindex_catalog()

    # the manufacturer filter is removed
    browser.visit("%s%s" % (live_server, url))
    assert not browser.is_text_present("Manufacturers")
Exemple #34
0
def second_category_sort_test(browser, live_server, shop, category):
    url = reverse("shuup:category",
                  kwargs={
                      "pk": category.pk,
                      "slug": category.slug
                  })
    browser.visit("%s%s" % (live_server, url))

    wait_until_condition(
        browser,
        lambda x: x.is_element_present_by_css("button[data-id='id_limit']"),
        timeout=30)
    # Set limit to 24
    click_element(browser, "button[data-id='id_limit']")
    click_element(
        browser,
        "button[data-id='id_limit'] + .dropdown-menu li:nth-child(2) a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 13,
                         timeout=30)

    # Check that visibility change affects the product count
    shop_products = ShopProduct.objects.filter(
        primary_category_id=category.id)[:3]
    for sp in shop_products:
        sp.visibility = ShopProductVisibility.NOT_VISIBLE
        sp.save()

    cache.clear()
    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 10)

    for sp in shop_products:
        sp.visibility = ShopProductVisibility.ALWAYS_VISIBLE
        sp.save()

    cache.clear()
    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 13,
                         timeout=30)
Exemple #35
0
def second_category_sort_with_price_filter(browser, category):
    set_configuration(
        category=category,
        data={
            "override_default_configuration": True,
            "filter_products_by_price": True,
            "filter_products_by_price_range_min": 5,
            "filter_products_by_price_range_max": 12,
            "filter_products_by_price_range_size": 3,
        },
    )
    browser.reload()

    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#id_price_range option")) == 5)
    # 5 products and let's filter all products with price less than 5
    click_element(browser, "button[data-id='id_price_range']")
    click_element(
        browser,
        "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='1'] a"
    )

    # 4 products and let's filter products with price +12
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 4)
    click_element(browser, "button[data-id='id_price_range']")
    click_element(
        browser,
        "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='4'] a"
    )

    # Now 2 products left and now filter with price 8-11
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 2)
    click_element(browser, "button[data-id='id_price_range']")
    click_element(
        browser,
        "button[data-id='id_price_range'] + .dropdown-menu li[data-original-index='3'] a"
    )

    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 3)
Exemple #36
0
def second_category_sort_with_price_filter(browser, category):
    set_configuration(category=category,
                      data={
                          "filter_products_by_price": True,
                          "filter_products_by_price_range_min": 5,
                          "filter_products_by_price_range_max": 12,
                          "filter_products_by_price_range_size": 3
                      })
    browser.reload()
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#id_price_range option")) == 5)
    browser.select("price_range", "-5")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 4)
    browser.select("price_range", "12-")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 2)
    browser.select("price_range", "8-11")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 3)
Exemple #37
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()
    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)
    # add customer using search
    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.name
    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(".view-details-link")) == 1)
Exemple #38
0
def test_checkout_with_login_and_register(browser, live_server,
                                          reindex_catalog):
    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)
    reindex_catalog()
    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"))
    guest_ordering_test(browser, live_server)

    test_username = "******"
    test_email = "*****@*****.**"
    test_password = "******"
    wait_until_condition(browser,
                         lambda x: x.is_text_present("Checkout Method"))
    register_test(browser, live_server, test_username, test_email,
                  test_password)

    wait_until_condition(browser,
                         lambda x: x.is_text_present("Checkout Method"))
    login_and_finish_up_the_checkout(browser, live_server, test_username,
                                     test_email, test_password)
Exemple #39
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")
    _check_create_refund_link(browser, order, False)
    _check_order_details_visible(browser)
    order.refresh_from_db()
    assert not order.taxful_total_price
    assert order.is_paid()
    assert order.is_fully_shipped()
def second_category_sort_test(browser, live_server, shop, category):
    url = reverse("shuup:category",
                  kwargs={
                      "pk": category.pk,
                      "slug": category.slug
                  })
    browser.visit("%s%s" % (live_server, url))
    assert not browser.is_text_present(
        "Sort")  # Sort shouldn't be available since default configurations
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12)
    click_element(browser, "#next_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1,
                         timeout=30)
    click_element(browser, "#previous_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12,
                         timeout=30)

    # Activate limit page size changer
    set_configuration(shop=shop,
                      data={
                          "sort_products_by_name": True,
                          "sort_products_by_name_ordering": 1,
                          "sort_products_by_price": True,
                          "sort_products_by_price_ordering": 2,
                          "limit_product_list_page_size": True
                      })
    browser.reload()
    # Set limit to 24
    click_element(browser, "button[data-id='id_limit']")
    click_element(
        browser,
        "button[data-id='id_limit'] + .dropdown-menu li[data-original-index='1'] a"
    )
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 13)
Exemple #41
0
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"))
Exemple #42
0
def manufacturer_filter_test(browser, category, manufacturer):
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 3)
    set_configuration(category=category,
                      data={
                          "sort_products_by_name": True,
                          "sort_products_by_name_ordering": 1,
                          "sort_products_by_price": True,
                          "sort_products_by_price_ordering": 2,
                          "filter_products_by_manufacturer": True
                      })
    browser.reload()
    wait_until_condition(browser, lambda x: x.is_text_present("Manufacturers"))
    browser.execute_script("$('#manufacturers-%s').click();" % manufacturer.id)
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1)
Exemple #43
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()
Exemple #44
0
def basic_sorting_test(browser):
    # Sort from Z to A
    click_element(browser, "button[data-id='id_sort']")
    # WARNING: data-original-index was removed after bootstrap-select 1.6.3
    click_element(browser, "li[data-original-index='1'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    # Sort by price (highest first)
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='3'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-8").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    # Sort by price (lowest first)
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='2'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    # Sort from A to Z
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='0'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-2").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)
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)
def _add_additional_category(browser, shop):
    assert Category.objects.count() == 1
    select_id = "id_shop%s-categories" % shop.pk
    move_to_element(browser, "#%s" % select_id, header_height=100)

    # Quick add new additional category
    wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 1)
    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 2")
        _save_category(iframe)

    wait_until_condition(browser, condition=lambda x: not x.is_element_present_by_id("create-object-overlay"))
    check_category_count(browser, 2)
    wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 2)
Exemple #47
0
def check_default_ordering(browser):
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-1").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    expected_second_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card")[1]["id"] ==
        expected_second_prod_id)

    expected_third_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-2").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card")[2]["id"] ==
        expected_third_prod_id)
Exemple #48
0
def test_category_product_filters_1(browser, live_server, settings):
    cache.clear()  # Avoid cache from past tests
    shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db()

    # 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!"))

    url = reverse("shuup:category", kwargs={"pk": first_cat.pk, "slug": first_cat.slug})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda x: x.is_text_present("First Category"))
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    assert not browser.is_text_present("Manufacturers")  # Since not in default configuration
    hide_sorts_for_shop(browser, shop)
    show_sorts_for_the_category_only(browser, first_cat)
    second_category_page_change(browser, live_server, shop, second_cat)
Exemple #49
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))
Exemple #50
0
def second_category_page_change(browser, live_server, shop, category):
    url = reverse("shuup:category",
                  kwargs={
                      "pk": category.pk,
                      "slug": category.slug
                  })
    browser.visit("%s%s" % (live_server, url))
    assert not browser.is_text_present(
        "Sort")  # Sort shouldn't be available since default configurations
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12)
    click_element(browser, "#next_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1,
                         timeout=30)
    click_element(browser, "#previous_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12,
                         timeout=30)
Exemple #51
0
def show_sorts_for_the_category_only(browser, category):
    set_configuration(category=category, data={"sort_products_by_name": True})
    browser.reload()
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_sort option")) == 2)
    click_element(browser, "button[data-id='id_sort']")

    set_configuration(category=category,
                      data={
                          "sort_products_by_name": True,
                          "sort_products_by_name_ordering": 1,
                          "sort_products_by_price": True,
                          "sort_products_by_price_ordering": 2,
                          "sort_products_by_date_created": True,
                          "sort_products_by_date_created_ordering": 3
                      })
    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_sort option")) == 5)
Exemple #52
0
def test_summernote_editor_picture(browser, admin_user, live_server, settings):
    activate("en")
    factories.get_default_shop()
    factories.get_default_product_type()
    factories.get_default_sales_unit()
    factories.get_default_tax_class()
    filer_image = factories.get_random_filer_image()

    initialize_admin_browser_test(browser, live_server, settings)
    original_size = browser.driver.get_window_size()
    browser.driver.set_window_size(1920, 1080)

    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"))

    img_icon_selector = "#id_base-description__en-editor-wrap i[class='note-icon-picture']"
    move_to_element(browser, img_icon_selector)
    click_element(browser, img_icon_selector)
    wait_until_condition(browser, lambda b: len(b.windows) == 2)

    # change to the media browser window
    browser.windows.current = browser.windows[1]

    # click to select the picture
    wait_until_appeared(browser, "a.file-preview")
    click_element(browser, "a.file-preview")

    # back to the main window
    wait_until_condition(browser, lambda b: len(b.windows) == 1)
    browser.windows.current = browser.windows[0]

    # make sure the image was added to the editor
    wait_until_appeared(
        browser,
        "#id_base-description__en-editor-wrap .note-editable img[src='%s']" %
        filer_image.url,
        timeout=20)
    browser.driver.set_window_size(original_size["width"],
                                   original_size["height"])
Exemple #53
0
def _add_primary_category(browser, shop):
    assert Category.objects.count() == 0
    select_id = "id_shop%s-primary_category" % shop.pk
    browser.execute_script(
        '$("#%s").parent().find("span.quick-add-btn a.btn").click();' %
        select_id)

    wait_until_condition(browser,
                         condition=lambda x: x.find_by_id(
                             "create-object-content-pane").has_class("open"))
    with browser.get_iframe('create-object-iframe') as iframe:
        iframe.fill("base-name__en", "Test Category")
        time.sleep(
            3
        )  # Let's just wait here to the iFrame to open fully (for Chrome and headless)
        click_element(iframe, "button[form='category_form']")

    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)) == 2)
Exemple #54
0
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"))
Exemple #55
0
def test_category_product_filters_2(browser, live_server, settings):
    cache.clear()  # Avoid cache from past tests
    shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db(
    )

    # Activate limit page size changer for the shop
    set_configuration(
        shop=shop,
        data={
            "sort_products_by_name": True,
            "sort_products_by_name_ordering": 1,
            "sort_products_by_price": True,
            "sort_products_by_price_ordering": 2,
            "limit_product_list_page_size": 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!"))

    url = reverse("shuup:category",
                  kwargs={
                      "pk": first_cat.pk,
                      "slug": first_cat.slug
                  })
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser,
                         lambda x: x.is_text_present("First Category"))
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    assert not browser.is_text_present(
        "Manufacturers")  # Since not in default configuration
    second_category_sort_test(browser, live_server, shop, second_cat)
    second_category_sort_with_price_filter(browser, second_cat)
Exemple #56
0
def variations_filter_test(browser, category):
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1)
    # Activate categories filter for current category which is the first one
    set_configuration(category=category,
                      data={
                          "sort_products_by_name": True,
                          "sort_products_by_name_ordering": 1,
                          "sort_products_by_price": True,
                          "sort_products_by_price_ordering": 2,
                          "filter_products_by_variation_value": True,
                          "filter_products_by_variation_value_ordering": 1
                      })

    def get_var_id(value):
        return value.replace(" ", "*")

    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 3)

    # Two brown products
    browser.execute_script("$('#variation_color-%s').click();" %
                           get_var_id("Brown"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 2)

    # Two brown L sized products
    browser.execute_script("$('#variation_size-%s').click();" %
                           get_var_id("L"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 2)

    # One brown big
    browser.execute_script("$('#variation_size-%s').click();" %
                           get_var_id("Big"))
    browser.execute_script("$('#variation_size-%s').click();" %
                           get_var_id("L"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1)

    browser.execute_script("$('#variation_color-%s').click();" %
                           get_var_id("Brown"))  # unselect brown

    # Two Big or Black products
    browser.execute_script("$('#variation_color-%s').click();" %
                           get_var_id("Black"))

    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 2)

    browser.execute_script("$('#variation_color-%s').click();" %
                           get_var_id("Black"))  # unselect black

    # Three Big or Pink products
    browser.execute_script("$('#variation_color-%s').click();" %
                           get_var_id("Pink"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 0)

    # One pink product
    browser.execute_script("$('#variation_size-%s').click();" %
                           get_var_id("Big"))
    browser.execute_script("$('#variation_size-%s').click();" %
                           get_var_id("Brown"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1)
def test_quick_add(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    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)

    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:
        assert Category.objects.count() == 0
        wait_until_appeared(iframe, "input[name='base-name__en']")
        iframe.fill("base-name__en", "Test Category")
        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']")
        click_element(browser, "button[form='category_form']")
        wait_until_condition(browser,
                             condition=lambda x: Category.objects.count() == 1,
                             timeout=20)

    assert Category.objects.first().name == "Test Category"

    # click to edit the button
    click_element(
        browser,
        "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id)

    with browser.get_iframe("create-object-iframe") as iframe:
        wait_until_appeared(iframe, "input[name='base-name__en']")
        new_cat_name = "Changed Name"
        iframe.fill("base-name__en", new_cat_name)
        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']")
        click_element(iframe, "button[form='category_form']")

    wait_until_condition(
        browser,
        condition=lambda x: Category.objects.first().name == new_cat_name,
        timeout=20)

    click_element(browser, "button[form='product_form']")
    wait_until_appeared(browser, "div[class='message success']")
def test_edit_button_no_permission(browser, admin_user, live_server, settings):
    shop = get_default_shop()

    manager_group = Group.objects.create(name="Managers")

    manager = create_random_user("en", is_staff=True)
    manager.username = "******"
    manager.set_password("password")
    manager.save()
    manager.groups.add(manager_group)
    shop.staff_members.add(manager)

    # add permissions for Product admin module
    manager_permissions = set(["dashboard", "Products", "shop_product.new"])
    set_permissions_for_group(manager_group, manager_permissions)

    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    initialize_admin_browser_test(browser,
                                  live_server,
                                  settings,
                                  username=manager.username)

    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)

    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")

    # no permission to add category
    with browser.get_iframe("create-object-iframe") as iframe:
        error = "Can't view this page. You do not have the required permissions: category.new"
        wait_until_condition(iframe,
                             condition=lambda x: x.is_text_present(error))

    # close iframe
    click_element(browser, "#create-object-overlay a.close-btn")

    # add permission to add category
    manager_permissions.add("category.new")
    manager_permissions.add("category.edit")
    set_permissions_for_group(manager_group, manager_permissions)

    # click to add category again
    click_element(
        browser,
        "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id)
    wait_until_appeared(browser, "#create-object-iframe")

    # add the category
    with browser.get_iframe("create-object-iframe") as iframe:
        assert Category.objects.count() == 0
        wait_until_appeared(iframe, "input[name='base-name__en']")
        iframe.fill("base-name__en", "Test Category")
        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']")
        click_element(browser, "button[form='category_form']")
        wait_until_condition(browser,
                             condition=lambda x: Category.objects.count() == 1,
                             timeout=20)

    assert Category.objects.first().name == "Test Category"

    # remove the edit category permissions
    # add permission to add category
    manager_permissions.remove("category.edit")
    set_permissions_for_group(manager_group, manager_permissions)

    # click to edit the button
    click_element(
        browser,
        "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id)

    # no permission to edit category
    with browser.get_iframe("create-object-iframe") as iframe:
        error = "Can't view this page. You do not have the required permission(s): `category.edit`."
        wait_until_condition(iframe,
                             condition=lambda x: x.is_text_present(error))

    # close iframe
    click_element(browser, "#create-object-overlay a.close-btn")

    manager_permissions.add("category.edit")
    set_permissions_for_group(manager_group, manager_permissions)

    click_element(
        browser,
        "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id)
    wait_until_appeared(browser, "#create-object-iframe")

    new_cat_name = "Changed Name"
    with browser.get_iframe("create-object-iframe") as iframe:
        wait_until_appeared(iframe, "input[name='base-name__en']")
        iframe.fill("base-name__en", new_cat_name)
        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']")
        click_element(browser, "button[form='category_form']")

    wait_until_condition(
        browser,
        condition=lambda x: Category.objects.first().name == new_cat_name,
        timeout=20)
Exemple #59
0
def test_home_tour(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    shop2 = factories.get_shop(identifier="shop2")
    admin_user_2 = factories.create_random_user(is_staff=True,
                                                is_superuser=True)
    admin_user_2.set_password("password")
    admin_user_2.save()

    shop.staff_members.add(admin_user)
    shop.staff_members.add(admin_user_2)

    for user in [admin_user, admin_user_2]:
        initialize_admin_browser_test(browser,
                                      live_server,
                                      settings,
                                      username=user.username,
                                      tour_complete=False)
        wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
        browser.visit(live_server + "/sa/home")

        wait_until_condition(
            browser,
            lambda x: x.is_text_present("Hi, new shop owner!"),
            timeout=30)
        wait_until_condition(
            browser, lambda x: x.is_element_present_by_css(
                ".shepherd-button.btn-primary"))
        click_element(browser, ".shepherd-button.btn-primary")

        category_targets = [
            ".shepherd-enabled[data-target-id='category-1'",
            ".shepherd-enabled[data-target-id='category-2'",
            ".shepherd-enabled[data-target-id='category-3'",
            ".shepherd-enabled[data-target-id='category-5'",
            ".shepherd-enabled[data-target-id='category-9'",
            ".shepherd-enabled[data-target-id='category-4'",
            ".shepherd-enabled[data-target-id='category-6'",
            ".shepherd-enabled[data-target-id='category-7'",
            ".shepherd-enabled[data-target-id='category-8'",
            ".shepherd-enabled#site-search",
            ".shepherd-enabled.shop-btn.visit-store",
        ]
        for target in category_targets:
            wait_until_condition(browser,
                                 lambda x: x.is_element_present_by_css(target))
            move_to_element(browser, ".shepherd-button.btn-primary")
            browser.find_by_css(".shepherd-button.btn-primary").last.click()

        wait_until_condition(browser,
                             lambda x: x.is_text_present("We're done!"),
                             timeout=30)
        move_to_element(browser, ".shepherd-button.btn-primary")
        browser.find_by_css(".shepherd-button.btn-primary").last.click()
        wait_until_condition(browser,
                             lambda x: is_tour_complete(shop, "home", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/home")
        wait_until_condition(
            browser, lambda x: not x.is_text_present("Hi, new shop owner!"))

        browser.visit(live_server + "/logout")
        browser.visit(live_server + "/sa")

        wait_until_condition(
            browser, lambda x: not x.is_text_present("Hi, new shop owner!"))

        assert is_tour_complete(shop2, "home", user) is False
Exemple #60
0
def test_dashbord_tour(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    shop2 = factories.get_shop(identifier="shop2")
    admin_user_2 = factories.create_random_user(is_staff=True,
                                                is_superuser=True)
    admin_user_2.set_password("password")
    admin_user_2.save()

    shop.staff_members.add(admin_user)
    shop.staff_members.add(admin_user_2)

    # test with admin_user 1
    initialize_admin_browser_test(browser,
                                  live_server,
                                  settings,
                                  shop=shop,
                                  tour_complete=False)
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
    wait_until_condition(browser, lambda x: x.is_text_present("Quicklinks"))
    wait_until_condition(browser,
                         lambda x: x.is_element_present_by_css("#menu-button"))
    wait_until_condition(
        browser,
        lambda x: x.is_text_present("This is the dashboard for your store."),
        timeout=30)
    wait_until_condition(
        browser,
        lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary"))
    click_element(browser, ".shepherd-button.btn-primary")
    wait_until_condition(
        browser, lambda x: not x.is_element_present_by_css(".shepherd-button"))
    wait_until_condition(
        browser, lambda x: is_tour_complete(shop, "dashboard", admin_user))

    browser.visit(live_server + "/logout")
    browser.visit(live_server + "/sa")

    # test with admin_user 2
    initialize_admin_browser_test(browser,
                                  live_server,
                                  settings,
                                  shop=shop,
                                  tour_complete=False,
                                  username=admin_user_2.username)
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
    wait_until_condition(browser,
                         lambda x: x.is_element_present_by_css("#menu-button"))
    wait_until_condition(
        browser,
        lambda x: x.is_text_present("This is the dashboard for your store."),
        timeout=30)
    wait_until_condition(
        browser,
        lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary"))
    click_element(browser, ".shepherd-button.btn-primary")
    wait_until_condition(
        browser, lambda x: not x.is_element_present_by_css(".shepherd-button"))
    wait_until_condition(
        browser, lambda x: is_tour_complete(shop, "dashboard", admin_user_2))

    # check whether the tour is shown again
    browser.visit(live_server + "/sa")
    wait_until_condition(
        browser, lambda x: not x.is_text_present(
            "This is the dashboard for your store."))

    assert is_tour_complete(shop2, "dashboard", admin_user) is False
    assert is_tour_complete(shop2, "dashboard", admin_user_2) is False