本文整理汇总了Python中shuup.testing.factories.get_default_category函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_category函数的具体用法?Python get_default_category怎么用?Python get_default_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_category函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_shop_product_sample_data
def _get_shop_product_sample_data():
return {
"shop": get_default_shop().id,
"suppliers": [
get_default_supplier().id
],
"visibility": ShopProductVisibility.ALWAYS_VISIBLE.value,
"purchasable": False,
"visibility_limit": ProductVisibility.VISIBLE_TO_ALL.value,
"visibility_groups": [
create_random_contact_group().id,
create_random_contact_group().id,
],
"backorder_maximum": 0,
"purchase_multiple": 1,
"minimum_purchase_quantity": 1,
"limit_shipping_methods": False,
"limit_payment_methods": False,
"shipping_methods": [],
"payment_methods": [],
"primary_category": get_default_category().id,
"categories": [
get_default_category().id,
CategoryFactory().id
],
"default_price_value": 12.45,
"minimum_price_value": 5.35
}
开发者ID:suutari-ai,项目名称:shuup,代码行数:28,代码来源:test_products_api.py
示例2: 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
开发者ID:gurch101,项目名称:shuup,代码行数:33,代码来源:test_product_view.py
示例3: test_carousel_create
def test_carousel_create(browser, admin_user, live_server, settings):
shop = factories.get_default_shop()
filer_image = factories.get_random_filer_image()
factories.get_default_category()
initialize_admin_browser_test(browser, live_server, settings, shop=shop)
wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
assert not Carousel.objects.exists()
browser.visit(live_server + "/sa/carousels/new")
wait_until_condition(browser, lambda x: x.is_text_present("New Carousel"))
browser.fill("base-name", "Carrot")
click_element(browser, "button[form='carousel_form']")
wait_until_appeared(browser, "div[class='message success']")
assert Carousel.objects.count() == 1
carousel = Carousel.objects.first()
browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk)
wait_until_condition(browser, lambda x: x.is_text_present(carousel.name))
click_element(browser, "a[href='#slides-section']")
wait_until_appeared(browser, ".slide-add-new-panel")
# add 1 slide
click_element(browser, ".slide-add-new-panel")
wait_until_condition(browser, lambda x: x.is_text_present("Slide 1"))
wait_until_appeared(browser, "a[href='#collapse1']")
click_element(browser, "a[href='#collapse1']")
browser.find_by_css("#slide_1-en [name='slides-__slide_prefix__-caption__en']").fill("New Slide")
click_element(browser, "[name='slides-__slide_prefix__-category_link'] + .select2")
wait_until_appeared(browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li")
click_element(browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li:last-child")
browser.find_by_css("#slide_1-en [data-dropzone='true']").click()
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]
wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name)
click_element(browser, "button[form='carousel_form']")
wait_until_appeared(browser, "div[class='message success']")
开发者ID:ruqaiya,项目名称:shuup,代码行数:49,代码来源:test_carousel_edit.py
示例4: test_products_form_add
def test_products_form_add():
shop = get_default_shop()
category = get_default_category()
category.visibility = CategoryVisibility.VISIBLE_TO_LOGGED_IN
category.status = CategoryStatus.INVISIBLE
category.shops.add(shop)
category.save()
product = create_product("test_product", shop=shop)
shop_product = product.get_shop_instance(shop)
product_category = product.category
assert (product_category is None)
assert (category not in shop_product.categories.all())
data = {
"primary_products": ["%s" % product.id]
}
form = CategoryProductForm(shop=shop, category=category, data=data)
form.full_clean()
form.save()
shop_product.refresh_from_db()
product.refresh_from_db(())
assert (shop_product.primary_category == category)
assert (category in shop_product.categories.all())
assert (shop_product.visibility_limit.value == category.visibility.value)
assert (shop_product.visible == False)
assert (product.category is None)
开发者ID:NamiStudio,项目名称:shuup,代码行数:25,代码来源:test_category_module.py
示例5: test_category_deletion
def test_category_deletion(admin_user):
admin = get_person_contact(admin_user)
category = get_default_category()
category.children.create(identifier="foo")
shop_product = get_default_shop_product()
shop_product.categories.add(category)
shop_product.primary_category = category
shop_product.save()
configuration.set(None, get_all_seeing_key(admin), True)
assert category.status == CategoryStatus.VISIBLE
assert category.children.count() == 1
with pytest.raises(NotImplementedError):
category.delete()
category.soft_delete()
shop_product.refresh_from_db()
shop_product.product.refresh_from_db()
assert shop_product.categories.count() == 0
assert shop_product.primary_category is None
assert category.status == CategoryStatus.DELETED
assert category.children.count() == 0
# the child category still exists
assert Category.objects.all_visible(customer=admin).count() == 1
assert Category.objects.all_except_deleted().count() == 1
configuration.set(None, get_all_seeing_key(admin), False)
开发者ID:gurch101,项目名称:shuup,代码行数:29,代码来源:test_categories.py
示例6: test_category_product_in_basket_condition
def test_category_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
category = get_default_category()
product = create_product("The Product", shop=shop, default_price="200", supplier=supplier)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop)
shop_product = product.get_shop_instance(shop)
assert category not in shop_product.categories.all()
condition = CategoryProductsBasketCondition.objects.create(operator=ComparisonOperator.EQUALS, quantity=1)
condition.categories.add(category)
# No match the product does not have the category
assert not condition.matches(basket, [])
category.shop_products.add(shop_product)
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
condition.operator = ComparisonOperator.GTE
condition.save()
assert condition.matches(basket, [])
condition.excluded_categories.add(category)
assert not condition.matches(basket, [])
with pytest.raises(CampaignsInvalidInstanceForCacheUpdate):
update_filter_cache("test", shop)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:test_basket_category_products_campaigns.py
示例7: test_category_links_plugin_with_customer
def test_category_links_plugin_with_customer(rf, show_all_categories):
"""
Test plugin for categories that is visible for certain group
"""
shop = get_default_shop()
group = get_default_customer_group()
customer = create_random_person()
customer.groups.add(group)
customer.save()
request = rf.get("/")
request.shop = get_default_shop()
apply_request_middleware(request)
request.customer = customer
category = get_default_category()
category.status = CategoryStatus.VISIBLE
category.visibility = CategoryVisibility.VISIBLE_TO_GROUPS
category.visibility_groups.add(group)
category.shops.add(shop)
category.save()
vars = {"request": request}
context = get_jinja_context(**vars)
plugin = CategoryLinksPlugin({"categories": [category.pk], "show_all_categories": show_all_categories})
assert category.is_visible(customer)
assert category in plugin.get_context_data(context)["categories"]
customer_without_groups = create_random_person()
customer_without_groups.groups.clear()
assert not category.is_visible(customer_without_groups)
request.customer = customer_without_groups
context = get_jinja_context(**vars)
assert category not in plugin.get_context_data(context)["categories"]
开发者ID:NamiStudio,项目名称:shuup,代码行数:35,代码来源:test_plugins.py
示例8: test_category_create_with_parent
def test_category_create_with_parent(rf, admin_user):
shop = get_default_shop()
default_category = get_default_category()
default_category.shops.clear()
assert shop not in default_category.shops.all()
with override_settings(LANGUAGES=[("en", "en")]):
view = CategoryEditView.as_view()
cat_name = "Random name"
data = {
"base-name__en": cat_name,
"base-status": CategoryStatus.VISIBLE.value,
"base-visibility": CategoryVisibility.VISIBLE_TO_ALL.value,
"base-ordering": 1,
"base-parent": default_category.pk
}
assert Category.objects.count() == 1
request = apply_request_middleware(rf.post("/", data=data), user=admin_user, shop=shop)
response = view(request, pk=None)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
assert Category.objects.count() == 1
default_category.shops.add(shop)
request = apply_request_middleware(rf.post("/", data=data), user=admin_user, shop=shop)
response = view(request, pk=None)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
assert Category.objects.count() == 2
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:test_category_module.py
示例9: test_manufacturer_filter_get_fields
def test_manufacturer_filter_get_fields(rf):
shop = factories.get_default_shop()
request = apply_request_middleware(rf.get("/"))
assert ManufacturerProductListFilter().get_fields(request, None) is None
manufacturer = Manufacturer.objects.create(name="Random Brand Inc")
assert ManufacturerProductListFilter().get_fields(request, None) is None
category = factories.get_default_category()
product = factories.create_product("sku", shop=shop)
shop_product = product.get_shop_instance(shop=shop)
shop_product.primary_category = category
shop_product.save()
assert ManufacturerProductListFilter().get_fields(request, category) is None
# Now once we link manufacturer to product we should get
# form field for manufacturer
product.manufacturer = manufacturer
product.save()
form_field = ManufacturerProductListFilter().get_fields(request, category)[0][1]
assert form_field is not None
assert form_field.label == "Manufacturers"
assert len(form_field.queryset) == 1
with override_settings(SHUUP_FRONT_OVERRIDE_SORTS_AND_FILTERS_LABELS_LOGIC={"manufacturers": "Brands"}):
form_field = ManufacturerProductListFilter().get_fields(request, category)[0][1]
assert form_field is not None
assert form_field.label == "Brands"
assert len(form_field.queryset) == 1
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:test_manufacturer_filter.py
示例10: test_category_product_in_basket_condition
def test_category_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
category = get_default_category()
product = create_product("The Product", shop=shop, default_price="200", supplier=supplier)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
shop_product = product.get_shop_instance(shop)
assert category not in shop_product.categories.all()
condition = CategoryProductsBasketCondition.objects.create(
category=category, operator=ComparisonOperator.EQUALS, quantity=1)
# No match the product does not have the category
assert not condition.matches(basket, [])
shop_product.categories.add(category)
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
condition.operator = ComparisonOperator.GTE
condition.save()
assert condition.matches(basket, [])
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:27,代码来源:test_basket_category_products_campaigns.py
示例11: 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
开发者ID:suutari,项目名称:shoop,代码行数:34,代码来源:test_sorts_and_filters_admin.py
示例12: test_all_categories_view
def test_all_categories_view(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
category = get_default_category()
product = get_default_product()
request = apply_request_middleware(rf.get("/"))
_check_product_count(request, 0)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(category)
_check_product_count(request, 1)
# Create few categories for better test results
for i in range(10):
cat = Category.objects.create(name=printable_gibberish())
cat.shops.add(shop)
new_product_count = random.randint(1, 3) + 1
for i in range(1, new_product_count):
product = create_product("sku-%s" % i, shop=shop, supplier=supplier, default_price=10)
shop_product = product.get_shop_instance(shop)
# Add random categories expect default category which we will make
# hidden to make sure that products linked to hidden categories are
# not listed
shop_product.categories = Category.objects.exclude(id=category.pk).order_by("?")[:i]
_check_product_count(request, new_product_count)
category.status = CategoryStatus.INVISIBLE
category.save()
_check_product_count(request, new_product_count - 1)
开发者ID:ruqaiya,项目名称:shuup,代码行数:32,代码来源:test_all_categories.py
示例13: test_products_form_add_multiple_products
def test_products_form_add_multiple_products():
shop = get_default_shop()
category = get_default_category()
category.shops.add(shop)
product_ids = []
for x in range(0, 15):
product = create_product("%s" % x, shop=shop)
product_ids.append(product.id)
for x in range(0, 5):
product = create_product("parent_%s" % x, shop=shop, mode=ProductMode.SIMPLE_VARIATION_PARENT)
for y in range(0, 3):
child_product = create_product("child_%s_%s" % (x, y), shop=shop)
child_product.link_to_parent(product)
product_ids.append(product.id)
assert (category.shop_products.count() == 0)
data = {
"additional_products": ["%s" % product_id for product_id in product_ids]
}
form = CategoryProductForm(shop=shop, category=category, data=data)
form.full_clean()
form.save()
category.refresh_from_db()
assert (category.shop_products.count() == 35) # 15 normal products and 5 parents with 3 children each
开发者ID:gurch101,项目名称:shuup,代码行数:26,代码来源:test_category_module.py
示例14: test_products_form_remove
def test_products_form_remove():
shop = get_default_shop()
category = get_default_category()
category.shops.add(shop)
product = create_product("test_product", shop=shop)
shop_product = product.get_shop_instance(shop)
shop_product.primary_category = category
shop_product.save()
shop_product.categories.add(category)
shop_product.refresh_from_db()
assert (shop_product.primary_category == category)
assert (shop_product.categories.count() == 1)
assert (shop_product.categories.first() == category)
data = {
"remove_products": ["%s" % shop_product.id]
}
form = CategoryProductForm(shop=shop, category=category, data=data)
form.full_clean()
form.save()
category.refresh_from_db()
assert (category.shop_products.count() == 0)
shop_product.refresh_from_db()
assert (shop_product.primary_category is None)
assert (shop_product.categories.count() == 0)
开发者ID:gurch101,项目名称:shuup,代码行数:27,代码来源:test_category_module.py
示例15: test_category_filter
def test_category_filter(rf):
request, shop, group = initialize_test(rf, False)
cat = get_default_category()
cat_filter = CategoryFilter.objects.create()
cat_filter.categories.add(cat)
cat_filter.save()
assert cat_filter.values.first() == cat
category = Category.objects.create(
parent=None,
identifier="testcat",
name="catcat",
)
cat_filter.values = [cat, category]
cat_filter.save()
assert cat_filter.values.count() == 2
product = create_product("Just-A-Product-Too", shop, default_price="200")
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(cat)
shop_product.save()
assert cat_filter.filter_queryset(ShopProduct.objects.all()).exists() # filter matches
开发者ID:gurch101,项目名称:shuup,代码行数:25,代码来源:test_filters.py
示例16: test_category_removal
def test_category_removal():
product = get_product()
category = get_default_category()
product.category = category
product.save()
with pytest.raises(NotImplementedError):
category.delete()
assert Product.objects.filter(pk=product.pk).exists()
开发者ID:shawnadelic,项目名称:shuup,代码行数:8,代码来源:test_foreignkeys.py
示例17: test_shopproduct_primary_category_removal
def test_shopproduct_primary_category_removal():
product = get_product()
category = get_default_category()
sp = product.get_shop_instance(get_default_shop())
sp.primary_category = category
sp.save()
with pytest.raises(NotImplementedError):
category.delete()
assert ShopProduct.objects.filter(pk=sp.pk).exists()
开发者ID:shawnadelic,项目名称:shuup,代码行数:9,代码来源:test_foreignkeys.py
示例18: test_list_view
def test_list_view(rf, admin_user):
shop = factories.get_default_shop()
product = factories.create_product(sku="test", shop=shop)
shop_product = product.get_shop_instance(shop)
shop_product.primary_category = factories.get_default_category()
shop_product.save()
shop_product.categories.add(shop_product.primary_category)
view = load("shuup.admin.modules.products.views:ProductListView").as_view()
request = apply_request_middleware(rf.get("/", {
"jq": json.dumps({"perPage": 100, "page": 1})
}), user=admin_user)
response = view(request)
assert 200 <= response.status_code < 300
data = json.loads(response.content.decode("utf-8"))
product_data = [item for item in data["items"] if item["_id"] == shop_product.pk][0]
assert product_data["primary_category"] == factories.get_default_category().name
assert product_data["categories"] == factories.get_default_category().name
开发者ID:ruqaiya,项目名称:shuup,代码行数:19,代码来源:test_product_list_view.py
示例19: test_default_layout
def test_default_layout():
vc = _get_basic_view_config()
product = factories.create_product("test", name="Test product name")
category = factories.get_default_category()
placeholder_name = "wildhorse"
context = {"request": get_request(), "product": product, "category": category}
layout = vc.get_placeholder_layout(Layout, placeholder_name)
assert isinstance(layout, Layout)
assert layout.get_help_text({}) == layout.get_help_text(context)
_add_plugin_and_test_save(vc, layout, placeholder_name, context)
开发者ID:ruqaiya,项目名称:shuup,代码行数:12,代码来源:test_custom_layouts.py
示例20: test_price_info_cache_bump
def test_price_info_cache_bump(rf):
initial_price = 10
shop = factories.get_default_shop()
tax = factories.get_default_tax()
tax_class = factories.get_default_tax_class()
product = factories.create_product(
"product",
shop=shop,
supplier=factories.get_default_supplier(),
default_price=initial_price
)
request = apply_request_middleware(rf.get("/"))
def assert_cache_product():
cache_price_info(request, product, 1, product.get_price_info(request))
assert get_cached_price_info(request, product, 1).price == shop.create_price(initial_price)
def assert_nothing_is_cached():
# nothing is cached
assert get_cached_price_info(request, product, 1) is None
# cache the item
assert_nothing_is_cached()
assert_cache_product()
# cache bumped - the cache should be dropped - then, cache again
tax.save()
assert_nothing_is_cached()
assert_cache_product()
# cache bumped - the cache should be dropped - then, cache again
tax_class.save()
assert_nothing_is_cached()
assert_cache_product()
# cache bumped - the cache should be dropped - then, cache again
product.save()
assert_nothing_is_cached()
assert_cache_product()
shop_product = product.get_shop_instance(shop)
# cache bumped - the cache should be dropped - then, cache again
shop_product.save()
assert_nothing_is_cached()
assert_cache_product()
category = factories.get_default_category()
# cache bumped - the cache should be dropped - then, cache again
shop_product.categories.add(category)
assert_nothing_is_cached()
assert_cache_product()
开发者ID:ruqaiya,项目名称:shuup,代码行数:53,代码来源:test_price_info_cache.py
注:本文中的shuup.testing.factories.get_default_category函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论