def categories_filter_test(browser, first_cat, second_cat, third_cat): # Add all products in second category to also in first category for shop_product in ShopProduct.objects.filter( primary_category=second_cat): shop_product.categories.add(first_cat) # Add one product including first_cat also to third_cat shop_product = ShopProduct.objects.filter( primary_category=first_cat).last() shop_product.categories.add(third_cat) # Activate categories filter for current category which is the first one set_configuration(category=first_cat, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "filter_products_by_category": True }) browser.reload() wait_until_condition( browser, lambda x: x.is_element_present_by_id("categories-%s" % third_cat.id)) browser.execute_script("$('#categories-%s').click();" % third_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) browser.execute_script("$('#categories-%s').click();" % second_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) browser.execute_script("$('#categories-%s').click();" % third_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12)
def test_category_product_filters_2(browser, live_server, settings): cache.clear() # Avoid cache from past tests shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db( ) # Activate limit page size changer for the shop set_configuration(shop=shop, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "limit_product_list_page_size": True }) # initialize test and go to front page browser = initialize_front_browser_test(browser, live_server) # check that front page actually loaded wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!")) url = reverse("wshop:category", kwargs={ "pk": first_cat.pk, "slug": first_cat.slug }) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present("First Category")) wait_until_condition(browser, lambda x: x.is_text_present("Sort")) assert not browser.is_text_present( "Manufacturers") # Since not in default configuration second_category_sort_test(browser, live_server, shop, second_cat) second_category_sort_with_price_filter(browser, second_cat)
def hide_sorts_for_shop(browser, shop): set_configuration(shop=shop, data={ "sort_products_by_name": False, "sort_products_by_price": False }) browser.reload() wait_until_condition(browser, lambda x: not x.is_text_present("sort"), timeout=20)
def manufacturer_filter_test(browser, category, manufacturer): wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3) set_configuration(category=category, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "filter_products_by_manufacturer": True }) browser.reload() wait_until_condition(browser, lambda x: x.is_text_present("Manufacturers")) browser.execute_script("$('#manufacturers-%s').click();" % manufacturer.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1)
def second_category_sort_with_price_filter(browser, category): set_configuration(category=category, data={ "filter_products_by_price": True, "filter_products_by_price_range_min": 5, "filter_products_by_price_range_max": 12, "filter_products_by_price_range_size": 3 }) browser.reload() wait_until_condition( browser, lambda x: len(x.find_by_css("#id_price_range option")) == 5) browser.select("price_range", "-5") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 4) browser.select("price_range", "12-") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2) browser.select("price_range", "8-11") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3)
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)
def form_valid(self, form): if self.name in form.forms: set_configuration(category=self.object, data=form[self.name].cleaned_data)
def variations_filter_test(browser, category): wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) # Activate categories filter for current category which is the first one set_configuration(category=category, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "filter_products_by_variation_value": True, "filter_products_by_variation_value_ordering": 1 }) def get_var_id(value): return value.replace(" ", "*") browser.reload() wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3) # Two brown products browser.execute_script("$('#variation_color-%s').click();" % get_var_id("Brown")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2) # Two brown L sized products browser.execute_script("$('#variation_size-%s').click();" % get_var_id("L")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2) # One brown big browser.execute_script("$('#variation_size-%s').click();" % get_var_id("Big")) browser.execute_script("$('#variation_size-%s').click();" % get_var_id("L")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) browser.execute_script("$('#variation_color-%s').click();" % get_var_id("Brown")) # unselect brown # Two Big or Black products browser.execute_script("$('#variation_color-%s').click();" % get_var_id("Black")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2) browser.execute_script("$('#variation_color-%s').click();" % get_var_id("Black")) # unselect black # Three Big or Pink products browser.execute_script("$('#variation_color-%s').click();" % get_var_id("Pink")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 0) # One pink product browser.execute_script("$('#variation_size-%s').click();" % get_var_id("Big")) browser.execute_script("$('#variation_size-%s').click();" % get_var_id("Brown")) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1)