def navigate_to_checkout(browser, product):
    wait_until_condition(browser,
                         lambda x: x.is_text_present("Newest Products"))
    wait_until_condition(browser, lambda x: x.is_text_present(product.name))

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

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

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

    click_element(browser,
                  "a[href='/checkout/']")  # click link that leads to checkout
Пример #2
0
def _add_primary_category(browser, shop):
    assert Category.objects.count() == 0
    select_id = "id_shop%s-primary_category" % shop.pk
    browser.execute_script(
        '$("#%s").parent().find("span.quick-add-btn a.btn").click();' %
        select_id)

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

    wait_until_condition(browser,
                         condition=lambda x: not x.is_element_present_by_id(
                             "create-object-overlay"))
    check_category_count(browser, 1)
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#%s option" % select_id)) == 2)
    wait_until_condition(
        browser, lambda x: len(
            x.find_by_css("#%s option[selected='selected']" % select_id)) == 1)
Пример #3
0
def change_addresses(live_server, browser, order):
    edit_url = reverse("wshop_admin:order.edit-addresses",
                       kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, edit_url))
    order_edited_log_entries = order.log_entries.filter(
        identifier=ADDRESS_EDITED_LOG_IDENTIFIER).count()
    wait_until_condition(
        browser, condition=lambda x: x.is_text_present("Edit Addresses"))
    # Do nothing just hit the save
    click_element(browser, "button[form='edit-addresses']")
    assert order.log_entries.filter(identifier=ADDRESS_EDITED_LOG_IDENTIFIER
                                    ).count() == order_edited_log_entries

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

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

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

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

    # Now update both same time
    browser.visit("%s%s" % (live_server, edit_url))
    wait_until_condition(
        browser, condition=lambda x: x.is_text_present("Edit Addresses"))
    click_element(browser, "#billing-to-shipping")
    new_name = "%s (edited)" % order.billing_address.name
    browser.fill("billing_address-name", new_name)
    click_element(browser, "button[form='edit-addresses']")
    check_log_entries_count(browser, order, order_edited_log_entries + 4)
    order.refresh_from_db()
    assert new_name == order.shipping_address.name
    assert order.billing_address.name == order.shipping_address.name
    assert order.billing_address.email == order.shipping_address.email
Пример #4
0
def _test_customer_using_search(browser, person):
    click_element(browser, "#customer-search .select2")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.find_by_css(
        "input.select2-search__field").first.value = person.name
    wait_until_appeared(
        browser, ".select2-results__option:not([aria-live='assertive'])")
    browser.execute_script(
        '$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    wait_until_condition(
        browser, lambda x: len(x.find_by_css(".view-details-link")) == 1)
Пример #5
0
def set_status(browser, order, status):
    click_element(browser, "button.set-status-button")
    form_action = reverse("wshop_admin:order.set-status",
                          kwargs={"pk": order.pk})
    click_element(
        browser,
        "button[formaction='%s'][value='%s']" % (form_action, status.pk))
    wait_until_appeared(browser, "div[class='message success']")
    wait_until_condition(
        browser, condition=lambda x: x.is_text_present("Order %s" % order.pk))
    order.refresh_from_db()
    assert order.status.pk == status.pk
Пример #6
0
def _test_customer_data(browser, person):
    browser.driver.execute_script("window.scrollTo(0, 200);")
    # check defaults
    assert browser.find_by_css(
        "input[name='save-address']").first.checked == True
    assert browser.find_by_css(
        "input[name='ship-to-billing-address']").first.checked == False
    assert browser.find_by_css(
        "input[name='order-for-company']").first.checked == False
    assert not browser.find_by_css(
        "input[name='billing-tax_number']").first['required']
    browser.find_by_css("input[name=ship-to-billing-address]").check()
    assert browser.find_by_css(
        "input[name=ship-to-billing-address]").first.checked
    browser.find_by_css("input[name='order-for-company']").check()
    assert browser.find_by_css("input[name='order-for-company']").first.checked
    wait_until_condition(
        browser, lambda x: x.find_by_css("input[name='billing-tax_number']").
        first['required'])
    assert len(browser.find_by_css("input[name='shipping-name']")
               ) == 0, "shipping address column is hidden"

    browser.find_by_css("input[name='order-for-company']").uncheck()
    click_element(browser, "#select-existing-customer")
    browser.windows.current = browser.windows[1]
    wait_until_appeared(browser, "a")
    # click second row - first row is admin
    browser.find_by_css("tbody tr")[1].find_by_css("a").click()

    # Wait until there is only one window left
    # after that is safe to switch the current window
    # back and test the results of the customer pick.
    wait_until_condition(browser,
                         lambda x: len(browser.windows) == 1,
                         timeout=30)
    browser.windows.current = browser.windows[0]
    # check fields were set
    wait_until_condition(
        browser, lambda x: x.find_by_name("billing-name").value == person.name)
    assert browser.find_by_name("billing-name").value == person.name
    assert browser.find_by_name(
        "billing-street").value == person.default_billing_address.street
    assert browser.find_by_name(
        "billing-city").value == person.default_billing_address.city
    assert browser.find_by_name(
        "billing-country").value == person.default_billing_address.country
    click_element(browser, "#clear-customer")
    wait_until_condition(
        browser, lambda x: "new customer" in x.find_by_css(
            "#customer-description").text)
Пример #7
0
def _activate_basket_campaign_through_coupon(browser, category, shop):
    # We should already be at basket so let's verify the total
    wait_until_condition(
        browser, lambda x: "110.53" in x.find_by_css("div.total-price strong").
        first.text)

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

    wait_until_condition(browser, lambda x: x.is_text_present(coupon_code))
    wait_until_condition(
        browser, lambda x: "-€22.11" in x.find_by_css(
            "div.product-sum h4.price").last.text)
    wait_until_condition(
        browser, lambda x: "€88.42" in x.find_by_css("div.total-price strong").
        first.text)
Пример #8
0
def _test_confirm(browser):
    total = sum([
        decimal.Decimal(total_el.value)
        for total_el in browser.find_by_css("input[name='total']")
    ])
    assert str(total) in browser.find_by_css(
        ".order-footer h2").text, "order total is correct"
    click_element(browser, ".order-footer button")
    wait_until_appeared(browser,
                        ".btn-danger")  # wait until the back button appears
    assert len(
        browser.find_by_css("table tbody tr")
    ) == 4, "1 line items, 2 methods, 1 total line shown in confirmation table"
    # click confirm
    click_element(browser, ".btn-success")
    wait_until_appeared(browser, "#details-section")
    assert Order.objects.count() == 1, "order created"
Пример #9
0
def second_category_page_change(browser, live_server, shop, category):
    url = reverse("wshop:category",
                  kwargs={
                      "pk": category.pk,
                      "slug": category.slug
                  })
    browser.visit("%s%s" % (live_server, url))
    assert not browser.is_text_present(
        "Sort")  # Sort shouldn't be available since default configurations
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12)
    click_element(browser, "#next_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 1,
                         timeout=30)
    click_element(browser, "#previous_page a")
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 12,
                         timeout=30)
Пример #10
0
def show_sorts_for_the_category_only(browser, category):
    set_configuration(category=category, data={"sort_products_by_name": True})
    browser.reload()
    wait_until_condition(browser, lambda x: x.is_text_present("Sort"))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_sort option")) == 2)
    click_element(browser, "button[data-id='id_sort']")

    set_configuration(category=category,
                      data={
                          "sort_products_by_name": True,
                          "sort_products_by_name_ordering": 1,
                          "sort_products_by_price": True,
                          "sort_products_by_price_ordering": 2,
                          "sort_products_by_date_created": True,
                          "sort_products_by_date_created_ordering": 3
                      })
    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_sort option")) == 5)
Пример #11
0
def _test_add_lines(browser):
    line_items_before = browser.find_by_id("lines").find_by_css(
        '.list-group-item')
    click_element(browser, "#add-line")
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#lines .list-group-item")) ==
        len(line_items_before) + 1)

    # Make sure that the lines is present before
    # selecting product for the order line.
    original_window_name = browser.windows.current.name
    wait_until_condition(
        browser, lambda x: x.is_element_present_by_css(
            "#lines .list-group-item:last-child a"))
    click_element(browser, "#lines .list-group-item:last-child a")
    browser.windows.current = browser.windows[1]
    wait_until_appeared(browser, "a")
    browser.find_by_css("tbody tr")[1].find_by_css("a").click()

    # Wait until there is only one window left
    # after that is safe to switch the current window
    # back and test the results of the product pick.
    wait_until_condition(browser,
                         lambda x: len(browser.windows) == 1,
                         timeout=30)
    browser.windows.current = browser.windows[0]
    browser.windows.current.close_others()
    wait_until_condition(
        browser,
        lambda x: browser.windows.current.name == original_window_name,
        timeout=30)

    wait_until_condition(
        browser, lambda x: x.find_by_css(
            '#lines .list-group-item:last-child input[name="total"]').first.
        value == "10")
    last_line_item = browser.find_by_css("#lines .list-group-item:last-child")
    assert last_line_item.find_by_css(
        'input[name="quantity"]').first.value == "1", "1 piece added"
    assert last_line_item.find_by_css(
        'input[name="total"]').first.value == "10", "line item total is 10"
Пример #12
0
def second_category_sort_test(browser, live_server, shop, category):
    url = reverse("wshop:category",
                  kwargs={
                      "pk": category.pk,
                      "slug": category.slug
                  })
    browser.visit("%s%s" % (live_server, url))

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

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

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

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

    browser.reload()
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css(".product-card")) == 13,
                         timeout=30)
Пример #13
0
def test_generic_script_template(browser, admin_user, live_server, settings, script_template_cls):
    initialize(browser, live_server, settings)

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

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

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

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

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

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

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

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert len(serialized_steps[0]["conditions"]) == 0
    assert serialized_steps[0]["actions"][0]["recipient"]["variable"] == "customer_email"
    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "custom subject!"
    assert "NEW CONTENT" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]
def guest_ordering_test(browser, live_server):
    browser.fill("login-username", "test-username")
    click_element(browser, "button[name='login']")
    wait_until_appeared(browser,
                        "div.form-group.passwordinput.required.has-error")
    browser.fill("login-password", "test-password")
    click_element(browser, "button[name='login']")
    wait_until_condition(
        browser, lambda x: x.is_text_present(
            "Please enter a correct username and password."))
    wait_until_appeared(browser, "div.alert.alert-danger")

    click_element(browser,
                  "button[data-id='id_checkout_method_choice-register']")
    click_element(browser, "li[data-original-index='0'] a")
    click_element(browser,
                  "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_condition(browser,
                         lambda x: x.is_text_present("Checkout: Addresses"))
    url = reverse("wshop:checkout", kwargs={"phase": "checkout_method"})
    browser.visit("%s%s" % (live_server, url))
Пример #15
0
def _test_create_full_refund(browser, live_server, order):
    url = reverse("wshop_admin:order.create-refund", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(
        browser, lambda x: x.is_text_present("Refunded: %s" % format_money(
            order.shop.create_price("0.00"))))
    wait_until_condition(
        browser, lambda x: x.is_text_present("Remaining: %s" % format_money(
            order.taxful_total_price)))
    url = reverse("wshop_admin:order.create-full-refund",
                  kwargs={"pk": order.pk})
    click_element(browser, "a[href='%s']" % url)
    wait_until_condition(
        browser, lambda x: x.is_text_present(
            "Refund Amount: %s" % format_money(order.taxful_total_price)))
    click_element(browser, "#create-full-refund")
    _check_create_refund_link(browser, order, False)
    _check_order_details_visible(browser)
    order.refresh_from_db()
    assert not order.taxful_total_price
    assert order.is_paid()
    assert order.is_fully_shipped()
Пример #16
0
def test_dummy_script_template(browser, admin_user, live_server, settings):
    initialize(browser, live_server, settings)

    with override_provides("notify_script_template", ["wshop.testing.notify_script_templates:DummyScriptTemplate"]):
        url = reverse("wshop_admin:notify.script.list")
        browser.visit("%s%s" % (live_server, url))
        wait_until_condition(browser, lambda x: x.is_element_present_by_css("div.btn-toolbar a.btn.btn-info"))
        post_initialize()

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

        identifier = DummyScriptTemplate.identifier
        form_id = "form-" + identifier
        wait_until_condition(browser, lambda x: x.is_element_present_by_id(form_id))

        btn_create_css = "#{} button.btn.btn-success".format(form_id)
        wait_until_condition(browser, lambda x: x.is_element_present_by_css(btn_create_css))
        click_element(browser, btn_create_css)

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

        script = Script.objects.first()
        serialized_steps = script.get_serialized_steps()
        assert len(serialized_steps) == 1
        assert len(serialized_steps[0]["actions"]) == 0
        assert len(serialized_steps[0]["conditions"]) == 1
        assert serialized_steps[0]["conditions"][0]["v1"]["constant"]
        assert not serialized_steps[0]["conditions"][0]["v2"]["constant"]

        # edit the script
        url = reverse("wshop_admin:notify.script.edit", kwargs={"pk": script.pk})
        browser.visit("%s%s" % (live_server, url))
        wait_until_condition(browser, lambda b: b.is_text_present("Edit Script Information"))

        # should exist only a single button to edit the script content
        assert len(browser.find_by_css("div.btn-toolbar a.btn.btn-info")) == 1
        assert "Edit Script Contents" in browser.find_by_css("div.btn-toolbar a.btn.btn-info").first.text
Пример #17
0
def test_product_create(browser, admin_user, live_server, settings):
    activate("en")
    shop = get_default_shop()
    get_default_product_type()
    get_default_sales_unit()
    get_default_tax_class()
    configuration.set(None, "wshop_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("wshop_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, "wshop_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
Пример #18
0
def _test_quick_add_lines(browser):
    assert browser.find_by_css("input[name='auto-add']").first.checked == True
    # add line automatically just by searching and finding direct match
    click_element(browser, "#quick-add .select2")
    wait_until_condition(
        browser, lambda x: len(
            browser.find_by_css("#quick-add .select2-container--open")) == 1)
    browser.find_by_css(
        "input.select2-search__field").first.value = "test-sku1"
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == 1)
    line_items = browser.find_by_css("#lines .list-group-item")
    assert len(browser.find_by_css("#quick-add .select2-container--open")
               ) == 1, "select is open after add"
    assert line_items.first.find_by_css(
        'input[name="quantity"]').first.value == '1', "one piece added"

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

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

    # add line manually
    browser.uncheck("auto-add")
    click_element(browser, "#quick-add .select2")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.find_by_css(
        "input.select2-search__field").first.value = "test-sku0"
    wait_until_appeared(
        browser, ".select2-results__option:not([aria-live='assertive'])")
    browser.execute_script(
        '$($(".select2-results__option")[0]).trigger({type: "mouseup"})')
    wait_until_condition(
        browser, lambda x: len(x.find_by_css('#lines .list-group-item')) == 2)
    line_items = browser.find_by_id("lines").find_by_css('.list-group-item')
    assert len(line_items) == 2, "two line items exist"

    click_element(browser, "#lines .list-group-item:last-child .delete button")
    wait_until_condition(
        browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == 1)
Пример #19
0
def _test_refund_view(browser, live_server, order):
    url = reverse("wshop_admin:order.create-refund", kwargs={"pk": order.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(
        browser, lambda x: x.is_text_present("Refunded: %s" % format_money(
            order.shop.create_price("0.00"))))
    assert len(browser.find_by_css("#id_form-0-line_number option")
               ) == 12  # blank + arbitrary amount + num lines
    click_element(browser, "#select2-id_form-0-line_number-container")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.execute_script(
        '$($(".select2-results__option")[1]).trigger({type: "mouseup"})'
    )  # select arbitrary amount
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_form-0-text")))
    wait_until_condition(browser,
                         lambda x: len(x.find_by_css("#id_form-0-amount")))
    browser.find_by_css("#id_form-0-text").first.value = "test"
    browser.find_by_css("#id_form-0-amount").first.value = "900"
    click_element(browser, "#add-refund")
    click_element(browser, "#select2-id_form-1-line_number-container")
    wait_until_appeared(browser, "input.select2-search__field")
    browser.execute_script(
        '$($(".select2-results__option")[2]).trigger({type: "mouseup"})'
    )  # select first line
    assert decimal.Decimal(
        browser.find_by_css(
            "#id_form-1-amount").first.value) == decimal.Decimal("100.00")
    assert int(
        decimal.Decimal(
            browser.find_by_css("#id_form-1-quantity").first.value)) == 10
    click_element(browser, "button[form='create_refund']")
    _check_create_refund_link(browser, order,
                              True)  # can still refund quantity
    _check_order_details_visible(browser)
    order.refresh_from_db()
    assert not order.taxful_total_price
    assert order.is_paid()
    assert not order.is_fully_shipped()
Пример #20
0
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, "wshop_product_tour_complete", True)
    initialize_admin_browser_test(browser, live_server, settings)

    url = reverse("wshop_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)
Пример #21
0
def test_browser_checkout_horizontal(browser, live_server, settings):
    # initialize
    product_name = "Test Product"
    get_default_shop()
    pm = get_default_payment_method()
    sm = get_default_shipping_method()
    product = create_orderable_product(product_name, "test-123", price=100)
    OrderStatus.objects.create(identifier="initial",
                               role=OrderStatusRole.INITIAL,
                               name="initial",
                               default=True)

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

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

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

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

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

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

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

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

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

    wait_until_condition(
        browser, lambda x: x.is_text_present(
            "There were errors on submitted form fields. Please check them and try again."
        ))

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

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

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

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

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

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

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

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

    wait_until_condition(browser, lambda x: x.is_text_present(
        "Thank you for your order!"))  # order succeeded
Пример #22
0
def test_stock_alert_limit_script_template(browser, admin_user, live_server, settings):
    initialize(browser, live_server, settings)

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

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

    identifier = StockLimitEmailScriptTemplate.identifier
    form_id = "form-" + identifier
    wait_until_condition(browser, lambda x: x.is_element_present_by_id(form_id))

    button_selector = "#{} button.btn.btn-success".format(form_id)
    wait_until_condition(browser, lambda x: x.is_element_present_by_css(button_selector))
    click_element(browser, button_selector)

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

    subject = "custom subject!"
    recipient = "*****@*****.**"
    browser.find_by_id("id_en-subject").fill(subject)
    browser.find_by_id("id_base-recipient").fill(recipient)
    browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click()

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

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

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert serialized_steps[0]["actions"][0]["recipient"]["constant"] == recipient
    assert len(serialized_steps[0]["conditions"]) == 1
    assert serialized_steps[0]["conditions"][0]["v1"]["variable"] == "dispatched_last_24hs"
    assert not serialized_steps[0]["conditions"][0]["v2"]["constant"]
    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == subject

    # edit the script
    url = reverse("wshop_admin:notify.script.edit", kwargs={"pk": script.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda b: b.is_text_present("Edit Script Information"))

    # find the button to edit the script content through template editor
    browser.find_by_css("div.btn-toolbar a.btn.btn-info").last.click()
    edit_url = reverse("wshop_admin:notify.script-template-edit", kwargs={"pk": script.pk})
    wait_until_condition(browser, lambda b: b.url.endswith(edit_url))
    wait_until_condition(browser, lambda b: b.is_text_present("Configure the Script Template"))

    # fill form
    subject = "changed sub"
    recipient = "*****@*****.**"
    browser.find_by_id("id_en-subject").fill(subject)
    browser.find_by_id("id_base-recipient").fill(recipient)
    browser.uncheck("base-last24hrs")
    browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click()

    # hit save
    wait_until_condition(browser, lambda b: b.url.endswith(reverse("wshop_admin:notify.script.list")))

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

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert serialized_steps[0]["actions"][0]["recipient"]["constant"] == recipient
    assert len(serialized_steps[0]["conditions"]) == 0
    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == subject
Пример #23
0
def _change_status_filter(browser, to_value):
    picotable = browser.find_by_id("picotable")
    click_element(browser, "#picotable div.choice-filter")
    click_element(browser,
                  "#picotable div.choice-filter option[value='%s']" % to_value)
Пример #24
0
def basic_sorting_test(browser):
    # Sort from Z to A
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='1'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

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

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

    # Sort from A to Z
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='0'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="sku-2").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)
Пример #25
0
def sort_category_products_test(browser, category):
    # Lowest price first
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='2'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="test-sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    # Name from A-Z
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='0'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="test-sku-2").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

    # Name from Z-A
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='1'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        sku="test-sku-3").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)

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

    # Date created
    click_element(browser, "button[data-id='id_sort']")
    click_element(browser, "li[data-original-index='4'] a")
    expected_first_prod_id = "product-%s" % Product.objects.filter(
        shop_products__primary_category=category).order_by(
            "-created_on").first().id
    wait_until_condition(
        browser, lambda x: x.find_by_css(".product-card").first["id"] ==
        expected_first_prod_id)
Пример #26
0
def _goto_page(browser, page_number):
    click_element(browser, "a[rel='%s']" % page_number)
    wait_until_appeared(browser, "li.active a[rel='%s']" % page_number)
def register_test(browser, live_server, test_username, test_email,
                  test_password):
    click_element(browser,
                  "button[data-id='id_checkout_method_choice-register']")
    click_element(browser, "li[data-original-index='1'] a")
    click_element(browser,
                  "div.clearfix button.btn.btn-primary.btn-lg.pull-right")
    wait_until_condition(browser, lambda x: x.is_text_present("Register"))

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

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

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

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

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

    # There is no products on basket anymore so let's add one
    product = Product.objects.first()
    product_url = reverse("wshop:product",
                          kwargs={
                              "pk": product.pk,
                              "slug": product.slug
                          })
    browser.visit("%s%s" % (live_server, product_url))
    click_element(browser, "#add-to-cart-button-%s" %
                  product.pk)  # add product to basket

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

    browser.visit("%s%s" % (live_server, "/checkout/"))
def login_and_finish_up_the_checkout(browser, live_server, test_username,
                                     test_email, test_password):
    browser.fill("login-username", test_email)
    browser.fill("login-password", test_password)
    click_element(browser, "button[name='login']")

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

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

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

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

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

    wait_until_condition(
        browser, lambda x: x.is_text_present("This field is required."))

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

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

    pm = get_default_payment_method()
    sm = get_default_shipping_method()

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

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

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

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

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

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

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

    # Let's make sure the order now has a customer
    assert Order.objects.count() == 1
    order = Order.objects.first()
    assert order.customer == PersonContact.objects.filter(
        user__username=test_username).first()
    assert order.customer.name == customer_name
    assert order.customer.default_shipping_address is not None
    assert order.customer.default_billing_address is not None
    assert order.customer.user.username == test_username
Пример #29
0
def test_generic_custom_email_script_template(browser, admin_user, live_server, settings, script_template_cls):
    initialize(browser, live_server, settings)

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

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

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

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

    browser.execute_script("""
        $(document).ready(function(){
            // EN
            $("#id_en-subject").val("custom subject!");
            $('#lang-en .summernote-editor').summernote('editor.insertText', 'Hi');

            // FINNISH
            $('.nav.nav-tabs a[href="#lang-fi"]').tab('show');
            $("#id_fi-subject").val("FINNISH subject!");
            $('#lang-fi .summernote-editor').summernote('editor.insertText', 'Hi Finland!');
        });
    """)

    # fill form
    browser.select('base-send_to', 'other')
    browser.find_by_id("id_base-recipient").fill("*****@*****.**")
    browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click()

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

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

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert len(serialized_steps[0]["conditions"]) == 0
    assert serialized_steps[0]["actions"][0]["recipient"]["constant"] == "*****@*****.**"

    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "custom subject!"
    assert "Hi" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]
    assert serialized_steps[0]["actions"][0]["template_data"]["fi"]["subject"] == "FINNISH subject!"
    assert "Hi Finland!" in serialized_steps[0]["actions"][0]["template_data"]["fi"]["body"]

    # edit the script
    url = reverse("wshop_admin:notify.script.edit", kwargs={"pk": script.pk})
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser, lambda b: b.is_text_present("Edit Script Information"))

    # find the button to edit the script content through template editor
    browser.find_by_css("div.btn-toolbar a.btn.btn-info").last.click()
    edit_url = reverse("wshop_admin:notify.script-template-edit", kwargs={"pk": script.pk})
    wait_until_condition(browser, lambda b: b.url.endswith(edit_url))
    wait_until_condition(browser, lambda b: b.is_text_present("Configure the Script Template"))

    # fill form
    browser.execute_script("""
        $(document).ready(function(){
            $('#lang-en .summernote-editor').summernote('editor.insertText', 'Changed');
        });
    """)
    browser.find_by_id("id_en-subject").fill("changed subject!")
    browser.select('base-send_to', 'customer')
    browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click()

    # hit save
    wait_until_condition(browser, lambda b: b.url.endswith(reverse("wshop_admin:notify.script.list")))

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

    assert len(serialized_steps) == 1
    assert len(serialized_steps[0]["actions"]) == 1
    assert len(serialized_steps[0]["conditions"]) == 0
    assert serialized_steps[0]["actions"][0]["recipient"]["variable"] == "customer_email"

    assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "changed subject!"
    assert "Changed" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]
Пример #30
0
def _add_product_to_basket_from_category(live_server, browser, first_category,
                                         shop):
    url = reverse("wshop:category",
                  kwargs={
                      "pk": first_category.pk,
                      "slug": first_category.slug
                  })
    browser.visit("%s%s" % (live_server, url))
    wait_until_condition(browser,
                         lambda x: x.is_text_present(first_category.name))

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

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

    discount_amount = 5
    _create_catalog_category_campaign(first_category, shop, discount_amount)

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

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

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

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

    new_discount_amount = 10
    _create_catalog_category_campaign(first_category, shop,
                                      new_discount_amount)

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

    # Add product to basket and navigate to basket view
    click_element(browser, "#add-to-cart-button-%s" %
                  product.pk)  # add product to basket
    wait_until_appeared(browser, ".cover-wrap")
    wait_until_disappeared(browser, ".cover-wrap")
    click_element(
        browser,
        "#navigation-basket-partial")  # open upper basket navigation menu
    click_element(browser,
                  "a[href='/basket/']")  # click the link to basket in dropdown
    wait_until_condition(
        browser,
        lambda x: x.is_text_present("Shopping cart"))  # we are in basket page
    wait_until_condition(
        browser,
        lambda x: x.is_text_present(product.name))  # product is in basket