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, "button.btn.btn-danger.btn-inverse") browser.get_alert().accept() wait_until_condition( browser, lambda x: not Snippet.objects.filter(shop=shop).exists())
def test_product_detail(browser, admin_user, live_server): shop = get_default_shop() product = create_product("test_sku", shop, default_price=10) initialize_admin_browser_test(browser, live_server) url = reverse("shuup_admin:product.edit", kwargs={"pk": product.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']") product.refresh_from_db() assert product.sku == 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() 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") click_element(browser, "#additional-details-section")
def test_product_create(browser, admin_user, live_server, settings): activate("en") shop = get_default_shop() get_default_product_type() get_default_sales_unit() get_default_tax_class() configuration.set(None, "shuup_product_tour_complete", True) object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test") initialize_admin_browser_test(browser, live_server, settings) browser.driver.set_window_size(1920, 1080) url = reverse("shuup_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) sku = "testsku" name = "Some product name" price_value = 10 short_description = "short but gold" browser.fill("base-sku", sku) browser.fill("base-name__en", name) browser.fill("base-short_description__en", short_description) browser.fill("shop%s-default_price_value" % shop.pk, price_value) configuration.set(None, "shuup_category_tour_complete", True) _add_primary_category(browser, shop) _add_additional_category(browser, shop) click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") product = Product.objects.filter(sku=sku).first() assert product.log_entries.filter(identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1 object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test") shop_product = product.get_shop_instance(shop) assert shop_product.categories.count() == 2
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")
def test_order_creator_view(browser, admin_user, live_server): 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() product0 = create_product("test-sku0", shop=shop, default_price=10, supplier=supplier) product1 = 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) _visit_order_creator_view(browser, live_server) _test_language_change(browser) _test_customer_data(browser, person) _test_regions(browser, person) _test_add_lines(browser) _test_quick_add_lines(browser) _test_methods(browser) _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")
def test_product_detail(browser, admin_user, live_server, settings): shop = get_default_shop() product = create_product("test_sku", shop, default_price=10) configuration.set(None, "shuup_product_tour_complete", True) 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']") wait_until_condition(browser, condition=lambda x: x.is_text_present("Product edited")) 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)
def test_product_create(browser, admin_user, live_server): 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) url = reverse("shuup_admin:product.new") browser.visit("%s%s" % (live_server, url)) sku = "testsku" name = "Some product name" price_value = 10 browser.fill("base-sku", sku) browser.fill("base-name__en", name) browser.fill("shop%s-default_price_value" % shop.pk, price_value) 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")
def test_product_detail(browser, admin_user, live_server, settings): shop = get_default_shop() product = create_product("test_sku", shop, default_price=10) configuration.set(None, "shuup_product_tour_complete", True) initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:product.edit", kwargs={"pk": product.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']") product.refresh_from_db() assert product.sku == 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() 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)
def test_product_create(browser, admin_user, live_server, settings): activate("en") shop = get_default_shop() get_default_product_type() get_default_sales_unit() get_default_tax_class() configuration.set(None, "shuup_product_tour_complete", True) object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test") initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) sku = "testsku" name = "Some product name" price_value = 10 short_description = "short but gold" browser.fill("base-sku", sku) browser.fill("base-name__en", name) browser.fill("base-short_description__en", short_description) browser.fill("shop%s-default_price_value" % shop.pk, price_value) configuration.set(None, "shuup_category_tour_complete", True) _add_primary_category(browser, shop) _add_additional_category(browser, shop) click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") product = Product.objects.filter(sku=sku).first() assert product.log_entries.filter(identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1 object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test") shop_product = product.get_shop_instance(shop) assert shop_product.categories.count() == 2
def test_menu_small_device(browser, admin_user, live_server, settings): get_default_shop() initialize_admin_browser_test(browser, live_server, settings) browser.driver.set_window_size(480, 960) browser.find_by_css("#menu-button").first.click() browser.find_by_css(".menu-list li").first.click() wait_until_condition(browser, lambda x: x.is_text_present("New product"))
def test_list_view(browser, admin_user, live_server): shop = get_default_shop() for i in range(0, 200): contact = create_random_person() contact.save() initialize_admin_browser_test(browser, live_server) _visit_contacts_list_view(browser, live_server) _test_pagination(browser) _set_settings(browser)
def test_list_view(browser, admin_user, live_server): shop = get_default_shop() for i in range(0, 200): contact = create_random_person() contact.save() initialize_admin_browser_test(browser, live_server) _visit_contacts_list_view(browser, live_server) _test_pagination(browser)
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) if list_view_settings[visit_type].get("test_pagination", False): _test_pagination(browser) _set_settings(browser, visit_type)
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)
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")) 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"))
def test_orders_list_view(browser, admin_user, live_server): shop = get_default_shop() for i in range(0, 10): order = create_empty_order(shop=shop) order.save() # Set last one canceled Order.objects.last().set_canceled() initialize_admin_browser_test(browser, live_server) _visit_orders_list_view(browser, live_server) _test_status_filter(browser) # Will set three orders from end canceled
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
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() configuration.set(None, "shuup_product_tour_complete", True) initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) sku = "testsku" name = "Some product name" price_value = 10 short_description = "short but gold" browser.fill("base-sku", sku) browser.fill("base-name__en", name) browser.fill("base-short_description__en", short_description) browser.fill("shop%s-default_price_value" % shop.pk, price_value) configuration.set(None, "shuup_category_tour_complete", True) wait_until_appeared(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) click_element(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) wait_until_appeared(browser, "#create-object-iframe") with browser.get_iframe('create-object-iframe') as iframe: assert Category.objects.count() == 0 wait_until_appeared(iframe, "input[name='base-name__en']") iframe.fill("base-name__en", "Test Category") time.sleep(3) # Let's just wait here to the iFrame to open fully (for Chrome and headless) wait_until_appeared(iframe, "button[form='category_form']") click_element(browser, "button[form='category_form']") wait_until_condition(browser, condition=lambda x: Category.objects.count() == 1, timeout=20) assert Category.objects.first().name == "Test Category" # click to edit the button click_element(browser, "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id) with browser.get_iframe('create-object-iframe') as iframe: wait_until_appeared(iframe, "input[name='base-name__en']") new_cat_name = "Changed Name" iframe.fill("base-name__en", new_cat_name) time.sleep(3) # Let's just wait here to the iFrame to open fully (for Chrome and headless) wait_until_appeared(iframe, "button[form='category_form']") click_element(iframe, "button[form='category_form']") wait_until_condition(browser, condition=lambda x: Category.objects.first().name == new_cat_name, timeout=20) click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']")
def test_menu(browser, admin_user, live_server, settings): shop = get_default_shop() initialize_admin_browser_test(browser, live_server, settings) browser.find_by_css(".menu-list li").first.click() wait_until_condition(browser, lambda x: x.is_text_present("New product")) # Make sure that the menu is clickable in small devices browser.driver.set_window_size(480, 960) browser.find_by_css("#menu-button").first.click() browser.find_by_css(".menu-list li").first.click() wait_until_condition(browser, lambda x: x.is_text_present("New product"))
def test_product_create(browser, admin_user, live_server, settings): activate("en") shop = get_default_shop() get_default_product_type() get_default_sales_unit() get_default_tax_class() configuration.set(None, "shuup_product_tour_complete", True) object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test") initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) 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) configuration.set(None, "shuup_category_tour_complete", True) _add_primary_category(browser, shop) _add_additional_category(browser, shop) move_to_element(browser, "button[form='product_form']") try: click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") except selenium.common.exceptions.WebDriverException as e: # TODO: Revise! # Give a product save second chance it seems that the save can # lag a little and the success message doesn't happen fast # enough every single time. click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") product = Product.objects.filter(sku=sku).first() assert product.log_entries.filter( identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1 object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test") shop_product = product.get_shop_instance(shop) assert shop_product.categories.count() == 2
def test_product_detail(browser, admin_user, live_server, settings): activate(settings.PARLER_DEFAULT_LANGUAGE_CODE) shop = get_default_shop() order = create_empty_order(shop=shop) order.save() initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:order.detail", kwargs={"pk": order.pk}) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, condition=lambda x: x.is_text_present("Order %s" % order.pk)) change_addresses(live_server, browser, order) set_status(browser, order, OrderStatus.objects.get_default_processing()) assert order.can_set_complete() set_status(browser, order, OrderStatus.objects.get_default_complete())
def 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() 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)
def test_order_creator_view(browser, admin_user, live_server): 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() product0 = create_product("test-sku0", shop=shop, default_price=10, supplier=supplier) product1 = create_product("test-sku1", shop=shop, default_price=10, supplier=supplier) initialize_admin_browser_test(browser, live_server) _visit_order_creator_view(browser, live_server) _test_customer_data(browser, person) _test_add_lines(browser) _test_quick_add_lines(browser) _test_methods(browser) _test_confirm(browser)
def test_menu(browser, admin_user, live_server, settings): shop = get_default_shop() initialize_admin_browser_test(browser, live_server, settings) browser.find_by_css(".menu-list li").first.click() wait_until_condition( browser, lambda x: x.is_text_present("Add a product to see it in your store")) # Make sure that the menu is clickable in small devices browser.driver.set_window_size(480, 960) browser.find_by_css("#menu-button").first.click() browser.find_by_css(".menu-list li").first.click() wait_until_condition( browser, lambda x: x.is_text_present("Add a product to see it in your store"))
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
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))
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() configuration.set(None, "shuup_product_tour_complete", True) 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_appeared( browser, "#id_base-description__en-editor-wrap button[aria-label='Picture']") click_element( browser, "#id_base-description__en-editor-wrap button[aria-label='Picture']") 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)
def test_order_creator_view(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() product0 = create_product("test-sku0", shop=shop, default_price=10, supplier=supplier) product1 = 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.maximize_window() _visit_order_creator_view(browser, live_server) _test_language_change(browser) _test_customer_data(browser, person) _test_regions(browser, person) _test_add_lines(browser) _test_quick_add_lines(browser) _test_methods(browser) _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")
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"))
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"))
def test_xtheme_edit_product(admin_user, browser, live_server, settings): browser = initialize_admin_browser_test( browser, live_server, settings) # Login to admin as admin user 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.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 test_dev_onboarding(browser, admin_user, live_server, settings): Shop.objects.first().delete( ) # Delete first hop 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) configuration.set(shop, "shuup_home_tour_complete", True) # Make home view tour complete 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
def test_menu(browser, admin_user, live_server, settings): get_default_shop() initialize_admin_browser_test(browser, live_server, settings) browser.find_by_css(".menu-list li").first.click() wait_until_condition(browser, lambda x: x.is_text_present("New product"))
def initialize(browser, live_server, settings): initialize_admin_browser_test(browser, live_server, settings)
def initialize(browser, live_server, settings): initialize_admin_browser_test(browser, live_server, settings) configuration.set(None, "shuup_product_tour_complete", True) Script.objects.all().delete()
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 permission_models = [Shop, Product, ShopProduct] for model in permission_models: for permission in get_default_model_permissions(model): manager_group.permissions.add(get_permission_object_from_string(permission)) get_default_product_type() get_default_sales_unit() get_default_tax_class() configuration.set(None, "shuup_product_tour_complete", True) 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) configuration.set(None, "shuup_category_tour_complete", True) 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: %s" % ", ".join(get_default_model_permissions(Category)) 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 for permission in get_default_model_permissions(Category): manager_group.permissions.add(get_permission_object_from_string(permission)) # 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 for permission in get_default_model_permissions(Category): manager_group.permissions.remove(get_permission_object_from_string(permission)) # 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): shuup.change_category" wait_until_condition(iframe, condition=lambda x: x.is_text_present(error)) # close iframe click_element(browser, "#create-object-overlay a.close-btn") for permission in get_default_model_permissions(Category): manager_group.permissions.add(get_permission_object_from_string(permission)) 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)
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))