示例#1
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"))
示例#2
0
def test_category_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/categories/new")

        wait_until_condition(browser, lambda x: x.is_text_present("Add a new product category"), 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, "category", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/categories/new")
        wait_until_condition(browser, lambda x: not x.is_text_present("Add a new product category"))

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

        assert is_tour_complete(shop2, "category", user) is False
示例#3
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)
    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
    )
示例#4
0
def test_menu_toggle(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"))

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

    # Close menu
    try:
        browser.find_by_css("#menu-button").first.click()
    except selenium.common.exceptions.TimeoutException as e:
        browser.find_by_css("#menu-button").first.click()
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))

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

    # Should be closed after page load
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))

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

    url = reverse("shuup_admin:shop_product.list")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Products"))

    # Should be still open after page load
    wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".desktop-menu-closed"))
示例#5
0
def test_login_logout(browser, admin_user, live_server, settings):
    get_default_shop()
    initialize_admin_browser_test(browser, live_server, settings)
    browser.visit("%s%s" % (live_server, "/sa/logout"))
    wait_until_condition(
        browser,
        lambda x: x.is_text_present("You have been securely logged out."))
示例#6
0
def test_category_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/categories/new")

        wait_until_condition(browser, lambda x: x.is_text_present("Add a new product category"))
        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, "category", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/categories/new")
        wait_until_condition(browser, lambda x: not x.is_text_present("Add a new product category"))

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

        assert is_tour_complete(shop2, "category", user) is False
示例#7
0
def test_menu_toggle(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"))

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

    # Close menu
    try:
        browser.find_by_css("#menu-button").first.click()
    except selenium.common.exceptions.TimeoutException as e:
        browser.find_by_css("#menu-button").first.click()
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))

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

    # Should be closed after page load
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))

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

    url = reverse("shuup_admin:shop_product.list")
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, condition=lambda x: x.is_text_present("Products"))

    # Should be still open after page load
    wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".desktop-menu-closed"))
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())
def test_order_creator_view_2(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    get_initial_order_status()
    supplier = get_default_supplier()
    person = create_random_person()
    person.registration_shop = shop
    person.save()
    person.shops.add(shop)

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

    initialize_admin_browser_test(browser, live_server, settings)
    browser.driver.set_window_size(1920, 1080)
    _visit_order_creator_view(browser, live_server)
    _test_customer_using_search(browser, person)
    _test_add_lines(browser)
    _test_methods(browser, sm, pm)
    _test_confirm(browser)
    assert Order.objects.first().log_entries.filter(
        identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1
    object_created.disconnect(sender=Order,
                              dispatch_uid="object_created_signal_test")
示例#10
0
def test_carousel_create(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    filer_image = factories.get_random_filer_image()
    factories.get_default_category()

    initialize_admin_browser_test(browser, live_server, settings, shop=shop)
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))

    assert not Carousel.objects.exists()

    browser.visit(live_server + "/sa/carousels/new")
    wait_until_condition(browser, lambda x: x.is_text_present("New Carousel"))
    browser.fill("base-name", "Carrot")
    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")

    assert Carousel.objects.count() == 1
    carousel = Carousel.objects.first()

    browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk)
    time.sleep(1)
    wait_until_condition(browser, lambda x: x.is_text_present(carousel.name))
    click_element(browser, "a[href='#slides-section']")
    wait_until_appeared(browser, ".slide-add-new-panel")

    # add 1 slide
    click_element(browser, ".slide-add-new-panel")
    wait_until_condition(browser, lambda x: x.is_text_present("Slide 1"))
    wait_until_appeared(browser, "a[href='#collapse1']")
    click_element(browser, "a[href='#collapse1']")

    browser.find_by_css(
        "#slide_1-en [name='slides-__slide_prefix__-caption__en']").fill(
            "New Slide")
    click_element(browser,
                  "[name='slides-__slide_prefix__-category_link'] + .select2")
    wait_until_appeared(
        browser,
        ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li"
    )
    click_element(
        browser,
        ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li:last-child"
    )

    browser.find_by_css("#slide_1-en [data-dropzone='true']").click()
    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]
    wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name)

    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")
示例#11
0
def test_product_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()
    product = factories.get_default_product()
    shop_product = product.get_shop_instance(shop)

    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/products/%d/" % shop_product.pk)

        wait_until_condition(browser, lambda x: x.is_text_present(shop_product.product.name))
        # as this is added through javascript, add an extra timeout
        wait_until_condition(browser, lambda x: x.is_text_present("You are adding a product."), 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 = [
            "a.shepherd-enabled[href='#basic-information-section']",
            "a.shepherd-enabled[href='#additional-details-section']",
            "a.shepherd-enabled[href='#manufacturer-section']",
            "a.shepherd-enabled[href*='-additional-section']",
            "a.shepherd-enabled[href='#product-media-section']",
            "a.shepherd-enabled[href='#product-images-section']",
            "a.shepherd-enabled[href='#contact-group-pricing-section']",
            "a.shepherd-enabled[href='#contact-group-discount-section']"
        ]

        # Scroll top before starting to click. For some reason the first
        # item is not found without this. For Firefox or Chrome the browser
        # does not do any extra scroll which could hide the first item.
        # Steps are scrollTo false on purpose since the scrollTo true is the
        # config which does not work in real world.
        browser.execute_script("window.scrollTo(0,0)")
        for target in category_targets:
            try:
                wait_until_condition(browser, lambda x: x.is_element_present_by_css(target))
                browser.find_by_css(".shepherd-button.btn-primary").last.click()
            except ElementNotInteractableException:
                move_to_element(browser, ".shepherd-button.btn-primary")
                wait_until_condition(browser, lambda x: x.is_element_present_by_css(target))
                browser.find_by_css(".shepherd-button.btn-primary").last.click()

        wait_until_condition(browser, lambda x: is_tour_complete(shop, "product", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/products/%d/" % shop_product.pk)
        wait_until_condition(browser, lambda x: not x.is_text_present("You are adding a product."), timeout=20)

        assert is_tour_complete(shop2, "product", user) is False

        browser.visit(live_server + "/logout")
        browser.visit(live_server + "/sa")
示例#12
0
def test_product_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()
    product = factories.get_default_product()
    shop_product = product.get_shop_instance(shop)

    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/products/%d/" % shop_product.pk)

        wait_until_condition(browser, lambda x: x.is_text_present(shop_product.product.name))
        # as this is added through javascript, add an extra timeout
        wait_until_condition(browser, lambda x: x.is_text_present("You are adding a product."), 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 = [
            "a.shepherd-enabled[href='#basic-information-section']",
            "a.shepherd-enabled[href='#additional-details-section']",
            "a.shepherd-enabled[href='#manufacturer-section']",
            "a.shepherd-enabled[href*='-additional-section']",
            "a.shepherd-enabled[href='#product-media-section']",
            "a.shepherd-enabled[href='#product-images-section']",
            "a.shepherd-enabled[href='#contact-group-pricing-section']",
            "a.shepherd-enabled[href='#contact-group-discount-section']"
        ]

        # Scroll top before starting to click. For some reason the first
        # item is not found without this. For Firefox or Chrome the browser
        # does not do any extra scroll which could hide the first item.
        # Steps are scrollTo false on purpose since the scrollTo true is the
        # config which does not work in real world.
        browser.execute_script("window.scrollTo(0,0)")
        for target in category_targets:
            try:
                wait_until_condition(browser, lambda x: x.is_element_present_by_css(target))
                browser.find_by_css(".shepherd-button.btn-primary").last.click()
            except ElementNotInteractableException:
                move_to_element(browser, ".shepherd-button.btn-primary")
                wait_until_condition(browser, lambda x: x.is_element_present_by_css(target))
                browser.find_by_css(".shepherd-button.btn-primary").last.click()

        wait_until_condition(browser, lambda x: is_tour_complete(shop, "product", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/products/%d/" % shop_product.pk)
        wait_until_condition(browser, lambda x: not x.is_text_present("You are adding a product."), timeout=20)

        assert is_tour_complete(shop2, "product", user) is False

        browser.visit(live_server + "/logout")
        browser.visit(live_server + "/sa")
示例#13
0
def test_product_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()
    product = factories.get_default_product()
    shop_product = product.get_shop_instance(shop)

    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/products/%d/" % shop_product.pk)

        wait_until_condition(
            browser, lambda x: x.is_text_present("You are adding a product."))
        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 = [
            "a.shepherd-enabled[href='#basic-information-section']",
            "a.shepherd-enabled[href='#additional-details-section']",
            "a.shepherd-enabled[href='#manufacturer-section']",
            "a.shepherd-enabled[href*='-additional-section']",
            "a.shepherd-enabled[href='#product-media-section']",
            "a.shepherd-enabled[href='#product-images-section']",
            "a.shepherd-enabled[href='#contact-group-pricing-section']",
            "a.shepherd-enabled[href='#contact-group-discount-section']"
        ]
        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: is_tour_complete(shop, "product", user))

        # check whether the tour is shown again
        browser.visit(live_server + "/sa/products/%d/" % shop_product.pk)
        wait_until_condition(
            browser,
            lambda x: not x.is_text_present("You are adding a product."))

        assert is_tour_complete(shop2, "product", user) is False

        browser.visit(live_server + "/logout")
        browser.visit(live_server + "/sa")
示例#14
0
def test_dev_onboarding(browser, admin_user, live_server, settings):
    Shop.objects.first().delete()  # Delete first shop created by test initializations
    call_command("shuup_init", *[], **{})
    shop = Shop.objects.first()
    assert shop.maintenance_mode
    initialize_admin_browser_test(browser, live_server, settings, onboarding=True)

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

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

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

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

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

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

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

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

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

    shop.refresh_from_db()
    assert not shop.maintenance_mode
    assert Product.objects.count() == 10
    supplier = Supplier.objects.first()
    customer = AnonymousContact()
    assert len([
        product for product in Product.objects.all()
            if product.get_shop_instance(shop).is_orderable(supplier, customer, 1)
    ]) == 10
示例#15
0
def test_dev_onboarding(browser, admin_user, live_server, settings):
    Shop.objects.first().delete()  # Delete first shop created by test initializations
    call_command("shuup_init", *[], **{})
    shop = Shop.objects.first()
    assert not shop.maintenance_mode
    initialize_admin_browser_test(browser, live_server, settings, onboarding=True)

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

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

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

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

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

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

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

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

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

    shop.refresh_from_db()
    assert not shop.maintenance_mode
    assert Product.objects.count() == 10
    supplier = Supplier.objects.first()
    customer = AnonymousContact()
    assert len([
        product for product in Product.objects.all()
            if product.get_shop_instance(shop).is_orderable(supplier, customer, 1)
    ]) == 10
示例#16
0
def test_refunds(browser, admin_user, live_server, settings):
    order = create_order_with_product(
        get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
        shop=get_default_shop())
    order2 = create_order_with_product(
        get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
        shop=get_default_shop())
    order2.create_payment(order2.taxful_total_price)
    initialize_admin_browser_test(browser, live_server, settings)
    _test_toolbar_visibility(browser, live_server, order)
    _test_create_full_refund(browser, live_server, order)
    _test_refund_view(browser, live_server, order2)
示例#17
0
def test_list_views(browser, admin_user, live_server, settings, visit_type):
    shop = get_default_shop()
    creator = list_view_settings[visit_type].get("creator", None)

    if creator and callable(creator):
        creator(shop)

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_list_view(browser, live_server, visit_type, creator)
    if list_view_settings[visit_type].get("test_pagination", False):
        _test_pagination(browser)
    _set_settings(browser, visit_type, creator)
示例#18
0
def test_orders_list_view(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    for i in range(0, 9):
        order = create_empty_order(shop=shop)
        order.save()

    # Set last one canceled
    Order.objects.last().set_canceled()

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_orders_list_view(browser, live_server)
    _test_status_filter(browser)  # Will set three orders from end canceled
示例#19
0
def test_orders_list_view(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    for i in range(0, 9):
        order = create_empty_order(shop=shop)
        order.save()

    # Set last one canceled
    Order.objects.last().set_canceled()

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_orders_list_view(browser, live_server)
    _test_status_filter(browser)  # Will set three orders from end canceled
示例#20
0
def test_xtheme_snippet_injection(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    initialize_admin_browser_test(browser, live_server, settings)

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

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

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

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

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

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

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

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

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

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

    click_element(browser, ".shuup-toolbar button.btn.btn-danger")
    browser.get_alert().accept()
    wait_until_condition(browser, lambda x: not Snippet.objects.filter(shop=shop).exists())
示例#21
0
def test_refunds(browser, admin_user, live_server, settings):
    order = create_order_with_product(
        get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
        shop=get_default_shop())
    order2 = create_order_with_product(
        get_default_product(), get_default_supplier(), 10, decimal.Decimal("10"), n_lines=10,
        shop=get_default_shop())
    order2.create_payment(order2.taxful_total_price)
    initialize_admin_browser_test(browser, live_server, settings)
    _test_toolbar_visibility(browser, live_server, order)
    _test_create_full_refund(browser, live_server, order)
    _test_refund_view(browser, live_server, order2)
示例#22
0
def test_list_views(browser, admin_user, live_server, settings, visit_type):
    shop = get_default_shop()
    creator = list_view_settings[visit_type].get("creator", None)

    if creator and callable(creator):
        creator(shop)

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_list_view(browser, live_server, visit_type, creator)
    if list_view_settings[visit_type].get("test_pagination", False):
        _test_pagination(browser)
    _set_settings(browser, visit_type, creator)
示例#23
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!"))
        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!"))
        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
示例#24
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
示例#25
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)
    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"))

    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
    browser.driver.set_window_size(original_size["width"],
                                   original_size["height"])
示例#26
0
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']")
示例#27
0
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']")
示例#28
0
def test_carousel_create(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    filer_image = factories.get_random_filer_image()
    factories.get_default_category()

    initialize_admin_browser_test(browser, live_server, settings, shop=shop)
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))

    assert not Carousel.objects.exists()

    browser.visit(live_server + "/sa/carousels/new")
    wait_until_condition(browser, lambda x: x.is_text_present("New Carousel"))
    browser.fill("base-name", "Carrot")
    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")

    assert Carousel.objects.count() == 1
    carousel = Carousel.objects.first()

    browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk)
    wait_until_condition(browser, lambda x: x.is_text_present(carousel.name))
    click_element(browser, "a[href='#slides-section']")
    wait_until_appeared(browser, ".slide-add-new-panel")

    # add 1 slide
    click_element(browser, ".slide-add-new-panel")
    wait_until_condition(browser, lambda x: x.is_text_present("Slide 1"))
    wait_until_appeared(browser, "a[href='#collapse1']")
    click_element(browser, "a[href='#collapse1']")

    browser.find_by_css("#slide_1-en [name='slides-__slide_prefix__-caption__en']").fill("New Slide")
    click_element(browser, "[name='slides-__slide_prefix__-category_link'] + .select2")
    wait_until_appeared(browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li")
    click_element(browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li:last-child")

    browser.find_by_css("#slide_1-en [data-dropzone='true']").click()
    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]
    wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name)

    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")
示例#29
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())
示例#30
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())
示例#31
0
def test_xtheme_plugin_form_selected_language_pane(admin_user, browser,
                                                   live_server, settings,
                                                   language):
    """
    Test that the current language is selected by default
    """
    browser = initialize_admin_browser_test(browser,
                                            live_server,
                                            settings,
                                            language=language)
    browser.visit(live_server + "/")

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

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

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

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

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

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

        # select the TextPlugin
        wait_until_appeared(iframe, "select[name='general-plugin']")
        click_element(iframe, "#select2-id_general-plugin-container")
        wait_until_appeared(iframe, "input.select2-search__field")
        iframe.find_by_css("input.select2-search__field").first.value = "Text"
        wait_until_appeared(
            browser, ".select2-results__option:not([aria-live='assertive'])")
        iframe.execute_script(
            '$($(".select2-results__option")[1]).trigger({type: "mouseup"})')
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)
        wait_until_appeared(iframe, "ul.editor-tabs")

        # check the active language
        assert language == iframe.find_by_css(
            "ul.editor-tabs li.active a").first.text
def test_variation_templates(browser, admin_user, live_server, settings):
    cache.clear()  # Avoid cache from past tests
    shop = get_default_shop()
    configuration_key = "saved_variation_templates"
    assert configuration.get(shop, configuration_key, None) is None
    product = create_product("test_sku", shop, default_price=10, mode=ProductMode.VARIABLE_VARIATION_PARENT)
    assert product.is_variation_parent()
    initialize_admin_browser_test(browser, live_server, settings)
    browser.driver.set_window_size(800, 1000)
    url = reverse("shuup_admin:shop_product.edit_variation", kwargs={"pk": product.pk})
    browser.visit("%s%s" % (live_server, url + "#variables-section"))
    click_element(browser, '#variables-section > div:nth-child(1) > a:nth-child(2)')
    wait_until_condition(browser, lambda x: x.is_text_present("New template"))

    assert len(ProductVariationVariable.objects.filter(product=product)) == 0 # Size
    assert len(ProductVariationVariableValue.objects.all()) == 0  # Assert no variations are active
    click_element(browser, '.fa.fa-plus')

    wait_until_condition(browser, lambda x: x.is_text_present("New template"))
    browser.fill("variables-template_name", printable_gibberish())  # variables-template_name
    click_element(browser, '#save_template_name')
    wait_until_condition(browser, lambda x: not x.is_text_present("New template"))
    assert len(configuration.get(shop, configuration_key, [])) == 1
    click_element(browser, '#variables-section > div:nth-child(1) > a:nth-child(2)')
    click_element(browser, "#variation-variable-editor")
    browser.find_by_xpath('//*[@id="variation-variable-editor"]/div/div/select/option[2]').first.click()
    wait_until_condition(browser, lambda x: x.is_text_present("Add new variable"))
    click_element(browser, ".btn.btn-lg.btn-text")
    browser.find_by_xpath('//*[@id="product-variable-wrap"]/div/div[2]/div[1]/table/tbody[1]/tr/td[1]/input').first.fill("Size")
    click_element(browser, ".btn.btn-xs.btn-text")
    browser.find_by_xpath('//*[@id="product-variable-wrap"]/div/div[2]/div[1]/table/tbody[2]/tr/td[1]/input').first.fill("S")
    click_element(browser, "#id_variables-activate_template")  # Activate template
    click_element(browser, ".fa.fa-check-circle")  # Save

    assert len(ProductVariationVariable.objects.filter(product=product)) == 1 # Size
    assert len(ProductVariationVariableValue.objects.all()) == 1  # S

    click_element(browser, '#variables-section > div:nth-child(1) > a:nth-child(2)')
    click_element(browser, "#variation-variable-editor") # id_variables-data
    cache.clear()  # Avoid cache from past tests
    assert len(configuration.get(shop, configuration_key, [])) == 1

    browser.find_by_xpath('//*[@id="variation-variable-editor"]/div/div/select/option[2]').first.click()
    template_data = configuration.get(shop, configuration_key, [])[0].get('data')[0]
    browser_data = json.loads(browser.find_by_css("#id_variables-data").value).get('variable_values')[0]
    assert browser_data == template_data  # assert shown template data matches template data in the db
示例#33
0
def test_product_detail(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    product = create_product("test_sku", shop, default_price=10)
    initialize_admin_browser_test(browser, live_server, settings)

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

    # Test product save
    new_sku = "some-new-sku"
    browser.find_by_id("id_base-sku").fill(new_sku)
    browser.execute_script("window.scrollTo(0,0)")
    time.sleep(0.5)  # Otherwise other elements are still in the way, obscuring
    click_element(browser, "button[form='product_form']")

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

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

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

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

    # Make sure that the tabs are clickable in small devices
    original_size = browser.driver.get_window_size()
    browser.driver.set_window_size(480, 960)
    time.sleep(0.5)  # Otherwise other elements are still in the way, obscuring
    click_element(browser, "#product-images-section", header_height=960)
    click_element(browser, "#additional-details-section", header_height=960)
    browser.driver.set_window_size(original_size["width"],
                                   original_size["height"])
示例#34
0
def test_order_creator_view_1(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    get_default_payment_method()
    get_default_shipping_method()
    get_initial_order_status()
    supplier = get_default_supplier()
    person = create_random_person()
    person.shops.add(shop)

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

    initialize_admin_browser_test(browser, live_server, settings)
    _visit_order_creator_view(browser, live_server)
    _test_language_change(browser)
    _test_customer_data(browser, person)
    _test_regions(browser, person)
    _test_quick_add_lines(browser)
示例#35
0
def test_xtheme_plugin_form_language_order(admin_user, browser, live_server, settings, default_language):
    """
    Test that the first language option is the Parler default

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

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

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

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

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

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

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

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

            # check the languages order
            languages = [el.text for el in iframe.find_by_css("ul.editor-tabs li a")]
            assert languages[0] == default_language
示例#36
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
示例#37
0
def test_xtheme_edit_save_and_publish(admin_user, browser, live_server, settings):
    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Add some content only visible for person contacts
    text_content = "Some dummy content!"
    layout_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
    placeholder_name = "front_content"

    wait_until_condition(browser, lambda x: x.is_element_present_by_css(layout_selector))
    click_element(browser, layout_selector)
    with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
        wait_until_condition(iframe, lambda x: x.is_text_present("Edit Placeholder: %s" % placeholder_name))
        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("button.layout-add-row-btn"))
        click_element(iframe, "button.layout-add-row-btn")
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x))

        try:
            wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.layout-cell"))
        except selenium.common.exceptions.TimeoutException as e:  # Give the "Add new row" second chance
            click_element(iframe, "button.layout-add-row-btn")
            wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.layout-cell"))

        click_element(iframe, "div.layout-cell")

        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("select[name='general-plugin']"))
        iframe.select("general-plugin", "text")

        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.note-editable"))
        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("#id_plugin-text_en-editor-wrap"))
        iframe.execute_script(
            "$('#id_plugin-text_en-editor-wrap .summernote-editor').summernote('editor.insertText', '%s');" %
            text_content
        )

        click_element(iframe, "button.publish-btn")
        alert = iframe.get_alert()
        assert alert.text == "Are you sure you wish to publish changes made to this view?"
        alert.accept()

        time.sleep(1)

        alert = iframe.get_alert()
        assert alert.text == "You have changed the form. Do you want to save them before publishing?"
        alert.accept()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(text_content))
示例#38
0
def test_xtheme_edit_save_and_publish(admin_user, browser, live_server, settings):
    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Add some content only visible for person contacts
    text_content = "Some dummy content!"
    layout_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
    placeholder_name = "front_content"

    wait_until_condition(browser, lambda x: x.is_element_present_by_css(layout_selector))
    click_element(browser, layout_selector)
    with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
        wait_until_condition(iframe, lambda x: x.is_text_present("Edit Placeholder: %s" % placeholder_name))
        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("button.layout-add-row-btn"))
        click_element(iframe, "button.layout-add-row-btn")
        time.sleep(1)
        wait_until_condition(iframe, lambda x: page_has_loaded(x))

        try:
            wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.layout-cell"))
        except selenium.common.exceptions.TimeoutException as e:  # Give the "Add new row" second chance
            click_element(iframe, "button.layout-add-row-btn")
            wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.layout-cell"))

        click_element(iframe, "div.layout-cell")

        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("select[name='general-plugin']"))
        iframe.select("general-plugin", "text")

        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("div.note-editable"))
        wait_until_condition(iframe, lambda x: x.is_element_present_by_css("#id_plugin-text_en-editor-wrap"))
        iframe.execute_script(
            "$('#id_plugin-text_en-editor-wrap .summernote-editor').summernote('editor.insertText', '%s');" %
            text_content
        )

        click_element(iframe, "button.publish-btn")
        alert = iframe.get_alert()
        assert alert.text == "Are you sure you wish to publish changes made to this view?"
        alert.accept()

        time.sleep(1)

        alert = iframe.get_alert()
        assert alert.text == "You have changed the form. Do you want to save them before publishing?"
        alert.accept()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(text_content))
示例#39
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."))
    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."))
    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
示例#40
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
示例#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"))
示例#42
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"))
示例#43
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"))
示例#44
0
def test_product_detail(browser, admin_user, live_server, settings):
    shop = get_default_shop()
    product = create_product("test_sku", shop, default_price=10)
    initialize_admin_browser_test(browser, live_server, settings)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # check the active language
        assert language == iframe.find_by_css("ul.editor-tabs li.active a").first.text
示例#46
0
def test_xtheme_editor_form_picture(admin_user, browser, live_server, settings):
    """
    Test that is is possible to add image fron media browser
    """
    browser = initialize_admin_browser_test(browser, live_server, settings)
    browser.visit(live_server + "/")

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

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

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

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

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

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

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

        filer_image = factories.get_random_filer_image()

        wait_until_appeared(browser, "#id_plugin-text_en-editor-wrap button[aria-label='Picture']")
        click_element(browser, "#id_plugin-text_en-editor-wrap button[aria-label='Picture']")
        wait_until_condition(browser, lambda b: len(b.windows) == 2, timeout=20)

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

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

        # 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_plugin-text_en-editor-wrap .note-editable img[src='%s']" % filer_image.url, timeout=20)
示例#47
0
def test_xtheme_edit_front(admin_user, browser, live_server, settings):
    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Add some content only visible for person contacts
    person_contact_text_content = "This text is shown for person contacts only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-person-contact-layout", person_contact_text_content)

    browser.find_by_css("#admin-tools-menu li.dropdown").click()
    browser.find_by_css("a[href='/force-anonymous-contact/']").first.click()

    ## Add some content only visible for anonymous contacts
    anonymous_contact_text_content = "This text is shown for guests only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-anonymous-contact-layout", anonymous_contact_text_content)

    browser.find_by_css("#admin-tools-menu li.dropdown").click()
    browser.find_by_css("a[href='/force-company-contact/']").first.click()

    ### Add some content only visible for company contacts
    company_contact_text_content = "This text is shown for company contacts only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-company-contact-layout", company_contact_text_content)

    # Close edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Go to home and check content for anonymous contacts
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(person_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(company_contact_text_content))

    # Create user login and got check the content for person contact
    user = factories.create_random_user()
    password = "******"
    user.set_password(password)
    user.save()

    click_element(browser, "#login-dropdown")
    browser.fill("username", user.username)
    browser.fill("password", password)
    browser.find_by_css("ul.login button[type='submit']").click()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(person_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(company_contact_text_content))

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Create person contact to company and re-login and check the content for companies
    company = factories.create_random_company()
    company.members.add(get_person_contact(user))

    click_element(browser, "#login-dropdown")
    browser.fill("username", user.username)
    browser.fill("password", password)
    browser.find_by_css("ul.login button[type='submit']").click()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(company_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(person_contact_text_content))
示例#48
0
def test_xtheme_edit_product(admin_user, browser, live_server, settings):
    shop = factories.get_default_shop()
    supplier = factories.get_default_supplier()
    products = []
    for x in range(3):
        products.append(factories.create_product("test%s" % x, shop=shop, supplier=supplier, default_price=10))

    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user

    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Visit first product and edit the layout with custom text
    first_product = products.pop()
    first_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": first_product.pk, "slug": first_product.slug})
    )
    browser.visit(first_product_url)

    first_product_text_content = "This text is only visible for product %s." % first_product.name
    _edit_layout(
        browser,
        "product_extra_1",
        "#xt-ph-product_extra_1-xtheme-product-layout-%s" % first_product.pk,
        first_product_text_content
    )

    # Visit second product and edit the layout with custom text
    second_product = products.pop()
    second_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": second_product.pk, "slug": second_product.slug})
    )
    browser.visit(second_product_url)

    second_product_text_content = "This text is only visible for product %s." % second_product.name
    _edit_layout(
        browser,
        "product_extra_1",
        "#xt-ph-product_extra_1-xtheme-product-layout-%s" % second_product.pk,
        second_product_text_content
    )

    # Visit third product and edit common layout with text
    third_product = products.pop()
    third_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": third_product.pk, "slug": third_product.slug})
    )
    browser.visit(third_product_url)

    common_text_content = "This text is visible for all products."
    _edit_layout(
        browser, "product_extra_1", "#xt-ph-product_extra_1", common_text_content)

    # Close edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Let's revisit the product details as anonymous and check the placeholder content
    browser.visit(first_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(second_product_text_content))

    browser.visit(second_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: x.is_text_present(second_product_text_content))

    browser.visit(third_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(second_product_text_content))
示例#49
0
def test_xtheme_edit_product(admin_user, browser, live_server, settings):
    shop = factories.get_default_shop()
    supplier = factories.get_default_supplier()
    products = []
    for x in range(3):
        products.append(factories.create_product("test%s" % x, shop=shop, supplier=supplier, default_price=10))

    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user

    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Visit first product and edit the layout with custom text
    first_product = products.pop()
    first_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": first_product.pk, "slug": first_product.slug})
    )
    browser.visit(first_product_url)

    first_product_text_content = "This text is only visible for product %s." % first_product.name
    _edit_layout(
        browser,
        "product_extra_1",
        "#xt-ph-product_extra_1-xtheme-product-layout-%s" % first_product.pk,
        first_product_text_content
    )

    # Visit second product and edit the layout with custom text
    second_product = products.pop()
    second_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": second_product.pk, "slug": second_product.slug})
    )
    browser.visit(second_product_url)

    second_product_text_content = "This text is only visible for product %s." % second_product.name
    _edit_layout(
        browser,
        "product_extra_1",
        "#xt-ph-product_extra_1-xtheme-product-layout-%s" % second_product.pk,
        second_product_text_content
    )

    # Visit third product and edit common layout with text
    third_product = products.pop()
    third_product_url = "%s%s" % (
        live_server, reverse("shuup:product", kwargs={"pk": third_product.pk, "slug": third_product.slug})
    )
    browser.visit(third_product_url)

    common_text_content = "This text is visible for all products."
    _edit_layout(
        browser, "product_extra_1", "#xt-ph-product_extra_1", common_text_content)

    # Close edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Let's revisit the product details as anonymous and check the placeholder content
    browser.visit(first_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(second_product_text_content))

    browser.visit(second_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: x.is_text_present(second_product_text_content))

    browser.visit(third_product_url)
    wait_until_condition(browser, lambda x: x.is_text_present(common_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(first_product_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(second_product_text_content))
def initialize(browser, live_server, settings):
    initialize_admin_browser_test(browser, live_server, settings)
示例#51
0
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)
示例#52
0
def test_carousel_multi_slide(browser, admin_user, live_server, settings):
    shop = factories.get_default_shop()
    filer_image = factories.get_random_filer_image()

    initialize_admin_browser_test(browser, live_server, settings, shop=shop)
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))

    assert not Carousel.objects.exists()

    browser.visit(live_server + "/sa/carousels/new")
    wait_until_condition(browser, lambda x: x.is_text_present("New Carousel"))
    browser.fill("base-name", "Carrot")
    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")

    assert Carousel.objects.count() == 1
    carousel = Carousel.objects.first()

    browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk)
    wait_until_condition(browser, lambda x: x.is_text_present(carousel.name))
    click_element(browser, "a[href='#slides-section']")
    wait_until_appeared(browser, ".slide-add-new-panel")

    # add 4 slides
    click_element(browser, ".slide-add-new-panel")
    click_element(browser, ".slide-add-new-panel")
    click_element(browser, ".slide-add-new-panel")
    click_element(browser, ".slide-add-new-panel")

    wait_until_condition(browser, lambda x: x.is_text_present("Slide 3"))

    # delete slide3
    wait_until_appeared(browser, "a[href='#collapse3']")
    click_element(browser, "a[href='#collapse3']")
    wait_until_appeared(browser, "#collapse3 .btn-remove-slide")
    click_element(browser, "#collapse3 .btn-remove-slide")

    wait_until_condition(browser, lambda x: not x.is_text_present("Slide 3"))
    click_element(browser, "button[form='carousel_form']")

    wait_until_appeared(browser, "a[href='#slides-section'].errors")
    click_element(browser, "a[href='#slides-section']")

    for slide_id in [0, 1, 2]:
        wait_until_appeared(browser, "a[href='#collapse%d']" % (slide_id + 1))
        click_element(browser, "a[href='#collapse%d']" % (slide_id + 1))

        browser.find_by_css("[name='slides-%d-caption__en']" % slide_id).fill("Slide")
        click_element(browser, "[name='slides-%d-category_link'] + .select2" % slide_id)
        wait_until_appeared(browser, ".select2-container #select2-id_slides-%d-category_link-results li" % slide_id)
        click_element(browser, ".select2-container #select2-id_slides-%d-category_link-results li:last-child" % slide_id)

        browser.find_by_css("#id_slides-%d-image__en-dropzone" % slide_id).click()
        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]
        wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name)

    click_element(browser, "button[form='carousel_form']")
    wait_until_appeared(browser, "div[class='message success']")
示例#53
0
def test_xtheme_edit_front(admin_user, browser, live_server, settings):
    browser = initialize_admin_browser_test(browser, live_server, settings)  # Login to admin as admin user
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))

    # Start edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Add some content only visible for person contacts
    person_contact_text_content = "This text is shown for person contacts only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-person-contact-layout", person_contact_text_content)

    browser.find_by_css("#admin-tools-menu li.dropdown").click()
    browser.find_by_css("a[href='/force-anonymous-contact/']").first.click()

    ## Add some content only visible for anonymous contacts
    anonymous_contact_text_content = "This text is shown for guests only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-anonymous-contact-layout", anonymous_contact_text_content)

    browser.find_by_css("#admin-tools-menu li.dropdown").click()
    browser.find_by_css("a[href='/force-company-contact/']").first.click()

    ### Add some content only visible for company contacts
    company_contact_text_content = "This text is shown for company contacts only!"
    _edit_layout(
        browser, "front_content", "#xt-ph-front_content-xtheme-company-contact-layout", company_contact_text_content)

    # Close edit
    click_element(browser, ".xt-edit-toggle button[type='submit']")

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Go to home and check content for anonymous contacts
    browser.visit(live_server + "/")
    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(person_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(company_contact_text_content))

    # Create user login and got check the content for person contact
    user = factories.create_random_user()
    password = "******"
    user.set_password(password)
    user.save()

    click_element(browser, "#login-dropdown")
    browser.fill("username", user.username)
    browser.fill("password", password)
    browser.find_by_css("ul.login button[type='submit']").click()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(person_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(company_contact_text_content))

    # Logout
    click_element(browser, "div.top-nav i.menu-icon.fa.fa-user")
    click_element(browser, "a[href='/logout/']")

    # Create person contact to company and re-login and check the content for companies
    company = factories.create_random_company()
    company.members.add(get_person_contact(user))

    click_element(browser, "#login-dropdown")
    browser.fill("username", user.username)
    browser.fill("password", password)
    browser.find_by_css("ul.login button[type='submit']").click()

    wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
    wait_until_condition(browser, lambda x: x.is_text_present(company_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(anonymous_contact_text_content))
    wait_until_condition(browser, lambda x: not x.is_text_present(person_contact_text_content))
示例#54
0
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)
示例#55
0
def test_xtheme_plugin_form_language_order(admin_user, browser, live_server,
                                           settings, default_language):
    """
    Test that the first language option is the Parler default

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

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

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

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

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

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

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

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

            # check the languages order
            languages = [
                el.text for el in iframe.find_by_css("ul.editor-tabs li a")
            ]
            assert languages[0] == default_language