def test_get_data_dict_force_value_with_json_serializer(): product = factories.get_default_product() with pytest.raises(TypeError): json.dumps(get_data_dict(product)) json.dumps(get_data_dict(product, force_text_for_value=True))
def test_product_tour(browser, admin_user, live_server, settings): shop = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") admin_user_2 = factories.create_random_user(is_staff=True, is_superuser=True) admin_user_2.set_password("password") admin_user_2.save() product = factories.get_default_product() shop_product = product.get_shop_instance(shop) shop.staff_members.add(admin_user) shop.staff_members.add(admin_user_2) for user in [admin_user, admin_user_2]: initialize_admin_browser_test(browser, live_server, settings, username=user.username, tour_complete=False) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) browser.visit(live_server + "/sa/products/%d/" % shop_product.pk) wait_until_condition(browser, lambda x: x.is_text_present(shop_product.product.name)) # as this is added through javascript, add an extra timeout wait_until_condition(browser, lambda x: x.is_text_present("You are adding a product."), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") category_targets = [ "a.shepherd-enabled[href='#basic-information-section']", "a.shepherd-enabled[href='#additional-details-section']", "a.shepherd-enabled[href='#manufacturer-section']", "a.shepherd-enabled[href*='-additional-section']", "a.shepherd-enabled[href='#product-media-section']", "a.shepherd-enabled[href='#product-images-section']", "a.shepherd-enabled[href='#contact-group-pricing-section']", "a.shepherd-enabled[href='#contact-group-discount-section']" ] # Scroll top before starting to click. For some reason the first # item is not found without this. For Firefox or Chrome the browser # does not do any extra scroll which could hide the first item. # Steps are scrollTo false on purpose since the scrollTo true is the # config which does not work in real world. browser.execute_script("window.scrollTo(0,0)") for target in category_targets: try: wait_until_condition(browser, lambda x: x.is_element_present_by_css(target)) browser.find_by_css(".shepherd-button.btn-primary").last.click() except ElementNotInteractableException: move_to_element(browser, ".shepherd-button.btn-primary") wait_until_condition(browser, lambda x: x.is_element_present_by_css(target)) browser.find_by_css(".shepherd-button.btn-primary").last.click() wait_until_condition(browser, lambda x: is_tour_complete(shop, "product", user)) # check whether the tour is shown again browser.visit(live_server + "/sa/products/%d/" % shop_product.pk) wait_until_condition(browser, lambda x: not x.is_text_present("You are adding a product."), timeout=20) assert is_tour_complete(shop2, "product", user) is False browser.visit(live_server + "/logout") browser.visit(live_server + "/sa")
def _create_order(shop, customer): p1 = factories.create_product("test", shop=shop, supplier=factories.get_default_supplier()) order = factories.create_order_with_product(factories.get_default_product(), factories.get_default_supplier(), 2, 10, shop=shop) factories.add_product_to_order(order, factories.get_default_supplier(), p1, 2, 5) order.customer = customer order.save() return order
def test_product_price_range_filter(): shop = factories.get_default_shop() product = factories.get_default_product() category = factories.get_default_category() shop_product = product.get_shop_instance(shop) shop_product.default_price_value = 10 shop_product.categories.add(category) shop_product.save() client = SmartClient() config = { "filter_products_by_price": True, "filter_products_by_price_range_min": 5, "filter_products_by_price_range_max": 15, "filter_products_by_price_range_size": 5 } set_configuration(category=category, data=config) url = reverse('E-Commerce:category', kwargs={'pk': category.pk, 'slug': category.slug}) response, soup = client.response_and_soup(url) assert response.status_code == 200 assert soup.find(id="product-%d" % product.id) price_range_select = soup.find(id="id_price_range") # as the configuration is not set to override shop default configuration # this field shouldn't be there.. assert price_range_select is None # make the category configuration override the shop's default config config.update({"override_default_configuration": True}) set_configuration(category=category, data=config) url = reverse('E-Commerce:category', kwargs={'pk': category.pk, 'slug': category.slug}) response, soup = client.response_and_soup(url) assert response.status_code == 200 assert soup.find(id="product-%d" % product.id) price_range_select = soup.find(id="id_price_range") price_ranges = price_range_select.find_all("option") assert len(price_ranges) == 4 # filter products with prices above $15 filtered_url = "{}?price_range={}".format(url, price_ranges[-1].attrs["value"]) response, soup = client.response_and_soup(filtered_url) assert response.status_code == 200 assert not soup.find(id="product-%d" % product.id) # explicitly disable the override config.update({"override_default_configuration": False}) set_configuration(category=category, data=config) url = reverse('E-Commerce:category', kwargs={'pk': category.pk, 'slug': category.slug}) response, soup = client.response_and_soup(url) assert response.status_code == 200 assert soup.find(id="product-%d" % product.id) price_range_select = soup.find(id="id_price_range") assert price_range_select is None
def test_thumbnail_cache(): image1 = factories.get_random_filer_image() image2 = factories.get_random_filer_image() media = ProductMedia.objects.create(product=factories.get_default_product(), file=image2) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(image1) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and cached_url == url cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(media) cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and cached_url == url img_url = "http://www.E-Commerce.com/logo.png" cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(img_url) cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and cached_url == url source = Thumbnailer(file=BytesIO(TEST_PNG), name="logo.png") source.url = '/media/logo.png' cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(source) cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and cached_url == url # check whether caches are bumped image1.save() cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url media.save() cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url media.delete() image1.delete() image2.delete()