本文整理汇总了Python中shuup.core.cache.clear函数的典型用法代码示例。如果您正苦于以下问题:Python clear函数的具体用法?Python clear怎么用?Python clear使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clear函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_orderable_variation_children
def test_get_orderable_variation_children(rf):
supplier = get_default_supplier()
shop = get_default_shop()
variable_name = "Color"
parent = create_product("test-sku-1", shop=shop)
variation_variable = ProductVariationVariable.objects.create(product=parent, identifier="color", name=variable_name)
red_value = ProductVariationVariableValue.objects.create(variable=variation_variable, identifier="red", value="Red")
blue_value =ProductVariationVariableValue.objects.create(variable=variation_variable, identifier="blue", value="Blue")
combinations = list(parent.get_all_available_combinations())
assert len(combinations) == 2
for combo in combinations:
assert not combo["result_product_pk"]
child = create_product("xyz-%s" % combo["sku_part"], shop=shop, supplier=get_default_supplier(), default_price=20)
child.link_to_parent(parent, combination_hash=combo["hash"])
combinations = list(parent.get_all_available_combinations())
assert len(combinations) == 2
parent.refresh_from_db()
assert parent.is_variation_parent()
request = apply_request_middleware(rf.get("/"))
cache.clear()
for time in range(2):
orderable_children, is_orderable = get_orderable_variation_children(parent, request, None)
assert len(orderable_children)
for var_variable, var_values in dict(orderable_children).items():
assert var_variable == variation_variable
assert red_value in var_values
assert blue_value in var_values
示例2: test_sorts_and_filter_in_category_edit
def test_sorts_and_filter_in_category_edit(rf, admin_user):
get_default_shop()
cache.clear()
activate("en")
with override_provides("front_extend_product_list_form", DEFAULT_FORM_MODIFIERS):
category = get_default_category()
view = CategoryEditView.as_view()
assert get_configuration(category=category) == settings.SHUUP_FRONT_DEFAULT_SORT_CONFIGURATION
data = {
"base-name__en": category.name,
"base-status": category.status.value,
"base-visibility": category.visibility.value,
"base-ordering": category.ordering,
"product_list_facets-sort_products_by_name": True,
"product_list_facets-sort_products_by_name_ordering": 6,
"product_list_facets-sort_products_by_price": False,
"product_list_facets-sort_products_by_price_ordering": 32,
"product_list_facets-filter_products_by_manufacturer": True,
"product_list_facets-filter_products_by_manufacturer_ordering": 1
}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=category.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
expected_configurations = {
"sort_products_by_name": True,
"sort_products_by_name_ordering": 6,
"sort_products_by_price": False,
"sort_products_by_price_ordering": 32,
"filter_products_by_manufacturer": True,
"filter_products_by_manufacturer_ordering": 1
}
assert get_configuration(category=category) == expected_configurations
示例3: test_shop_form_part
def test_shop_form_part(rf):
cache.clear()
shop = factories.get_default_shop()
request = apply_request_middleware(rf.get("/"))
# nothing changed
form_part = StripeConfigurationFormPart(request, shop)
form = list(form_part.get_form_defs())[0].instantiate(prefix="stripe")
assert form.has_changed() is False
assert not get_checkout_payment_details_message(shop)
assert not get_checkout_payment_phase_message(shop)
assert not get_checkout_saved_card_message(shop)
assert not get_saved_card_message(shop)
request = apply_request_middleware(rf.post("/"))
data = {
"stripe-checkout_payment_details_message": "A",
"stripe-checkout_payment_phase_message": "B",
"stripe-checkout_saved_card_message": "C",
"stripe-saved_card_message": "D"
}
form_part = StripeConfigurationFormPart(request, shop)
form = list(form_part.get_form_defs())[0].instantiate(prefix="stripe", data=data)
assert form.is_valid()
form_part.form_valid({StripeConfigurationFormPart.name: form})
assert get_checkout_payment_details_message(shop) == "A"
assert get_checkout_payment_phase_message(shop) == "B"
assert get_checkout_saved_card_message(shop) == "C"
assert get_saved_card_message(shop) == "D"
示例4: test_basic_order_flow
def test_basic_order_flow(with_company):
cache.clear()
create_default_order_statuses()
n_orders_pre = Order.objects.count()
populate_if_required()
c = SmartClient()
product_ids = _populate_client_basket(c)
addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"})
addresses_soup = c.soup(addresses_path)
inputs = fill_address_inputs(addresses_soup, with_company=with_company)
response = c.post(addresses_path, data=inputs)
assert response.status_code == 302 # Should redirect forth
methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"})
methods_soup = c.soup(methods_path)
assert c.post(methods_path, data=extract_form_fields(methods_soup)).status_code == 302 # Should redirect forth
confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"})
confirm_soup = c.soup(confirm_path)
Product.objects.get(pk=product_ids[0]).soft_delete()
assert c.post(confirm_path, data=extract_form_fields(confirm_soup)).status_code == 200 # user needs to reconfirm
data = extract_form_fields(confirm_soup)
data['product_ids'] = ','.join(product_ids[1:])
assert c.post(confirm_path, data=data).status_code == 302 # Should redirect forth
n_orders_post = Order.objects.count()
assert n_orders_post > n_orders_pre, "order was created"
示例5: test_simple_search_get_ids_works
def test_simple_search_get_ids_works(rf):
cache.clear()
prod = get_default_product()
bit = prod.name[:5]
request = apply_request_middleware(rf.get("/"))
assert prod.pk in get_search_product_ids(request, bit)
assert prod.pk in get_search_product_ids(request, bit) # Should use cache
示例6: initialize_admin_browser_test
def initialize_admin_browser_test(browser, live_server, settings, username="admin", password="password",
onboarding=False, language="en", shop=None, tour_complete=True):
if not onboarding:
settings.SHUUP_SETUP_WIZARD_PANE_SPEC = []
activate("en")
cache.clear()
shop = shop or get_default_shop()
if tour_complete:
from django.contrib.auth import get_user_model
user = get_user_model().objects.get(username=username)
set_tour_complete(shop, "dashboard", True, user)
set_tour_complete(shop, "home", True, user)
set_tour_complete(shop, "product", True, user)
set_tour_complete(shop, "category", True, user)
url = live_server + "/sa"
browser.visit(url)
browser.fill('username', username)
browser.fill('password', password)
browser.find_by_css(".btn.btn-primary.btn-lg.btn-block").first.click()
if not onboarding:
# set shop language to eng
browser.find_by_id("dropdownMenu").click()
browser.find_by_xpath('//a[@data-value="%s"]' % language).first.click()
return browser
示例7: test_product_descriptions
def test_product_descriptions(browser, live_server, settings):
activate("en")
cache.clear()
shop = get_default_shop()
product = create_product("product1",
shop=shop,
description="<b>My HTML description</b>",
short_description="some short of description instead",
supplier=get_default_supplier())
sp = ShopProduct.objects.get(product=product, shop=shop)
sp.primary_category = get_default_category()
sp.categories.add(get_default_category())
sp.save()
# initialize test and go to front page
browser = initialize_front_browser_test(browser, live_server)
# view product detail page
url = reverse("shuup:product", kwargs={"pk": product.pk, "slug": product.slug})
browser.visit("%s%s" % (live_server, url))
wait_until_condition(browser, lambda x: x.is_text_present(product.short_description))
assert product.description in browser.html
# ensure the version is in static files
assert "style.css?v=%s" % shuup.__version__ in browser.html
# product preview
url = reverse("shuup:xtheme_extra_view", kwargs={"view": "products"})
browser.visit("%s%s" % (live_server, url))
product_div_name = "product-{}".format(product.pk)
wait_until_condition(browser, lambda x: x.find_by_css("#{} button.btn".format(product_div_name)))
browser.execute_script("$('#{} button.btn').click();".format(product_div_name))
assert product.short_description == browser.find_by_css("#{} p.description".format(product_div_name))[0].html
示例8: test_simple_search_word_finder
def test_simple_search_word_finder(rf):
cache.clear()
view = SearchView.as_view()
name = "Savage Garden"
sku = UNLIKELY_STRING
prod = create_product(
sku=sku,
name=name,
keywords="truly, madly, deeply",
description="Descriptive text",
shop=get_default_shop()
)
resp = view(apply_request_middleware(rf.get("/")))
assert prod not in resp.context_data["object_list"], "No query no results"
partial_sku = sku[:int(len(sku)/2)]
valid_searches = ["Savage", "savage", "truly", "madly", "truly madly", "truly garden", "text", sku, partial_sku]
for query in valid_searches:
resp = view(apply_request_middleware(rf.get("/", {"q": query})))
assert name in resp.rendered_content
invalid_searches = ["saavage", "", sku[::-1]]
for query in invalid_searches:
resp = view(apply_request_middleware(rf.get("/", {"q": query})))
assert name not in resp.rendered_content
示例9: test_get_random_products_cache_bump
def test_get_random_products_cache_bump():
from shuup.front.template_helpers import general
supplier = get_default_supplier()
shop = get_default_shop()
products = [create_product("sku-%d" % x, supplier=supplier, shop=shop) for x in range(2)]
children = [create_product("SimpleVarChild-%d" % x, supplier=supplier, shop=shop) for x in range(2)]
for child in children:
child.link_to_parent(products[0])
context = get_jinja_context()
cache.clear()
set_cached_value_mock = mock.Mock(wraps=context_cache.set_cached_value)
def set_cache_value(key, value, timeout=None):
if "random_products" in key:
return set_cached_value_mock(key, value, timeout)
with mock.patch.object(context_cache, "set_cached_value", new=set_cache_value):
assert set_cached_value_mock.call_count == 0
assert general.get_random_products(context, n_products=10)
assert set_cached_value_mock.call_count == 1
# call again, the cache should be returned instead and the set_cached_value shouldn't be called again
assert general.get_random_products(context, n_products=10)
assert set_cached_value_mock.call_count == 1
# change a shop product, the cache should be bumped
ShopProduct.objects.filter(shop=shop).first().save()
assert general.get_random_products(context, n_products=10)
assert set_cached_value_mock.call_count == 2
示例10: test_get_listed_products_filter
def test_get_listed_products_filter():
context = get_jinja_context()
shop = get_default_shop()
supplier = get_default_supplier()
product_1 = create_product(
"test-sku-1",
supplier=supplier,
shop=shop,
)
product_2 = create_product(
"test-sku-2",
supplier=supplier,
shop=shop,
)
cache.clear()
from shuup.front.template_helpers import general
filter_dict = {"id": product_1.id}
for cache_test in range(2):
product_list = general.get_listed_products(context, n_products=2, filter_dict=filter_dict)
assert product_1 in product_list
assert product_2 not in product_list
for cache_test in range(2):
product_list = general.get_listed_products(context, n_products=2, filter_dict=filter_dict, orderable_only=False)
assert product_1 in product_list
assert product_2 not in product_list
示例11: test_get_listed_products_cache_bump
def test_get_listed_products_cache_bump():
supplier = get_default_supplier()
shop = get_default_shop()
product_1 = create_product("test-sku-1", supplier=supplier, shop=shop,)
from shuup.front.template_helpers import general
filter_dict = {"id": product_1.pk}
cache.clear()
context = get_jinja_context()
set_cached_value_mock = mock.Mock(wraps=context_cache.set_cached_value)
def set_cache_value(key, value, timeout=None):
if "listed_products" in key:
return set_cached_value_mock(key, value, timeout)
with mock.patch.object(context_cache, "set_cached_value", new=set_cache_value):
assert set_cached_value_mock.call_count == 0
for cache_test in range(2):
assert general.get_listed_products(context, n_products=2, filter_dict=filter_dict, orderable_only=False)
assert set_cached_value_mock.call_count == 1
# bump cache
product_1.save()
for cache_test in range(2):
assert general.get_listed_products(context, n_products=2, filter_dict=filter_dict, orderable_only=False)
assert set_cached_value_mock.call_count == 2
# use other filters
from django.db.models import Q
for cache_test in range(2):
assert general.get_listed_products(context, n_products=2, extra_filters=Q(translations__name__isnull=False))
assert set_cached_value_mock.call_count == 3
示例12: test_category_product_filters_2
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("shuup: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)
示例13: second_category_sort_test
def second_category_sort_test(browser, live_server, shop, category):
url = reverse("shuup: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()
cache.clear()
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()
cache.clear()
browser.reload()
wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30)
示例14: test_sorts_and_filter_in_shop_edit
def test_sorts_and_filter_in_shop_edit(rf, admin_user):
cache.clear()
activate("en")
with override_provides("front_extend_product_list_form", DEFAULT_FORM_MODIFIERS):
shop = get_default_shop()
view = ShopEditView.as_view()
assert get_configuration(shop=shop) == settings.SHUUP_FRONT_DEFAULT_SORT_CONFIGURATION
data = {
"base-name__en": shop.name,
"base-public_name__en": shop.public_name,
"base-status": shop.status.value,
"base-currency": shop.currency,
"base-prices_include_tax": shop.prices_include_tax,
"base-languages": "en",
"product_list_facets-sort_products_by_name": True,
"product_list_facets-sort_products_by_name_ordering": 11,
"product_list_facets-sort_products_by_price": False,
"product_list_facets-sort_products_by_price_ordering": 32,
"product_list_facets-filter_products_by_manufacturer": False,
"product_list_facets-filter_products_by_manufacturer_ordering": 1
}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=shop.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
expected_configurations = {
"sort_products_by_name": True,
"sort_products_by_name_ordering": 11,
"sort_products_by_price": False,
"sort_products_by_price_ordering": 32,
"filter_products_by_manufacturer": False,
"filter_products_by_manufacturer_ordering": 1
}
assert get_configuration(shop=shop) == expected_configurations
示例15: initialize_db
def initialize_db():
activate("en")
# initialize
cache.clear()
shop = get_default_shop()
for name, identifier in CATEGORY_DATA:
category = Category()
category.name = name
category.identifier = identifier
category.status = CategoryStatus.VISIBLE
category.save()
category.shops.add(shop)
for name, identifier in MANUFACTURER_DATA:
Manufacturer.objects.create(name=name, identifier=identifier)
first_cat = Category.objects.filter(identifier="cat-1").first()
second_cat = Category.objects.filter(identifier="cat-2").first()
third_cat = Category.objects.filter(identifier="cat-3").first()
assert first_cat.pk != second_cat.pk
for name, sku, price in FIRST_CATEGORY_PRODUCT_DATA:
product = create_orderable_product(name, sku, price=price)
shop_product = product.get_shop_instance(shop)
cat = Category.objects.first()
shop_product.primary_category = first_cat
shop_product.save()
shop_product.categories.add(first_cat)
# Add some variation products
add_variations(
shop, Product.objects.filter(sku="test-sku-1").first(),
["Black", "Yellow"], ["Big", "Small"]
)
add_variations(
shop, Product.objects.filter(sku="test-sku-2").first(),
["Brown", "Pink"], ["S", "L", "XL"]
)
add_variations(
shop, Product.objects.filter(sku="test-sku-3").first(),
["Brown", "Black"], ["S", "L", "XL", "Big"]
)
for i in range(1, 14):
product = create_orderable_product("Test product", "sku-%s" % i, price=i)
shop_product = product.get_shop_instance(shop)
cat = Category.objects.first()
shop_product.primary_category = second_cat
shop_product.save()
shop_product.categories.add(second_cat)
# Set manufacturer for first product only
first_manufacturer = Manufacturer.objects.first()
Product.objects.filter(sku="test-sku-1").update(manufacturer_id=first_manufacturer.id)
return shop, first_cat, second_cat, third_cat, first_manufacturer