本文整理汇总了Python中shuup.testing.utils.apply_request_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python apply_request_middleware函数的具体用法?Python apply_request_middleware怎么用?Python apply_request_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply_request_middleware函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: assert_config_value
def assert_config_value(rf, admin_user, form_id, key, value, expected_value, shop=None):
if not shop:
shop = get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
view_func = SystemSettingsView.as_view()
response = view_func(request)
assert response.status_code == 200
form_field = "%s-%s" % (form_id, key)
data = {form_field: value}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view_func(request)
assert response.status_code == 302
if expected_value == "unset":
expected_value = value
assert configuration.get(None, key) == expected_value
assert len(messages.get_messages(request)) == 1
# Double save the form and the configuration should still be unchanged
response = view_func(request)
assert response.status_code == 302
assert configuration.get(None, key) == expected_value
assert len(messages.get_messages(request)) == 2
return shop
开发者ID:ruqaiya,项目名称:shuup,代码行数:28,代码来源:test_settings.py
示例2: 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
示例3: init_test
def init_test(request, shop, prices):
apply_request_middleware(request)
parent = create_product("parent_product", shop=shop)
children = [create_product("child-%d" % price, shop=shop, default_price=price) for price in prices]
for child in children:
child.link_to_parent(parent)
return parent
开发者ID:suutari,项目名称:shoop,代码行数:7,代码来源:test_product_variation_child_pricing.py
示例4: test_save_cart_errors
def test_save_cart_errors(rf, regular_user):
get_default_shop()
request = apply_request_middleware(rf.post("/", {
"title": "test"
}))
response = CartSaveView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert response.status_code == 403, "can't save cart as anonymous user"
assert not data["ok"], "can't save cart without title"
customer = get_person_contact(regular_user)
request = apply_request_middleware(rf.post("/", {
"title": ""
}), customer=customer, user=regular_user)
response = CartSaveView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert response.status_code == 400
assert not data["ok"], "can't save cart without title"
request = apply_request_middleware(rf.post("/", {
"title": "test"
}), customer=customer, user=regular_user)
response = CartSaveView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert response.status_code == 400
assert not data["ok"], "can't save an empty cart"
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:test_saved_carts.py
示例5: test_edit_view_adding_messages_to_form_group
def test_edit_view_adding_messages_to_form_group(rf, admin_user):
get_default_shop() # obvious prerequisite
product = get_default_product()
view = ProductEditView.as_view()
request = apply_request_middleware(rf.get("/"), user=admin_user)
response = view(request, pk=product.pk)
response.render()
assert 200 <= response.status_code < 300
assert ProductEditView.add_form_errors_as_messages
content = force_text(response.content)
post = extract_form_fields(BeautifulSoup(content))
post_data = {
# Error in the base form part
"base-name__en": "",
}
post.update(post_data)
request = apply_request_middleware(rf.post("/", post), user=admin_user)
response = view(request, pk=product.pk)
errors = response.context_data["form"].errors
assert "base" in errors
assert "name__en" in errors["base"]
开发者ID:gurch101,项目名称:shuup,代码行数:25,代码来源:test_views.py
示例6: _test_happy_hours_delete_view
def _test_happy_hours_delete_view(rf, index):
shop = factories.get_shop(identifier="shop%s" % index, enabled=True)
staff_user = factories.create_random_user(is_staff=True)
shop.staff_members.add(staff_user)
happy_hour_name = "The Hour %s" % index
happy_hour = HappyHour.objects.create(name=happy_hour_name)
happy_hour.shops = [shop]
extra_happy_hour= HappyHour.objects.create(name="Extra Hour %s" % index)
extra_happy_hour.shops = [shop]
assert HappyHour.objects.filter(name=happy_hour_name).exists()
view_func = HappyHourDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
response = view_func(request, pk=happy_hour.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
assert not HappyHour.objects.filter(name=happy_hour_name).exists()
# Make sure that this staff can't remove other people discounts
other_exceptions = HappyHour.objects.exclude(shops=shop)
exception_count = other_exceptions.count()
for coupon in other_exceptions:
view_func = HappyHourDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
with pytest.raises(Http404):
response = view_func(request, pk=coupon.pk)
if hasattr(response, "render"):
response.render()
assert exception_count == HappyHour.objects.exclude(shops=shop).count()
开发者ID:ruqaiya,项目名称:shuup,代码行数:33,代码来源:test_happy_hours_admin.py
示例7: 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
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:test_simple_search.py
示例8: test_coupon_creation_for_supplier
def test_coupon_creation_for_supplier(rf, admin_user):
"""
To make things little bit more simple let's use only english as
a language.
"""
shop = get_default_shop()
supplier = Supplier.objects.create(identifier=admin_user.username)
another_superuser = create_random_user(is_superuser=True, is_staff=True)
supplier2 = Supplier.objects.create(identifier=another_superuser.username)
supplier_provider = "shuup.testing.supplier_provider.UsernameSupplierProvider"
with override_settings(LANGUAGES=[("en", "en")]):
with override_settings(SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC=supplier_provider):
view = CouponEditView.as_view()
data = {
"code": "OK",
"active": True,
"shop": shop.pk
}
coupons_before = Coupon.objects.count()
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
assert get_supplier(request) == supplier
response = view(request, pk=None)
assert response.status_code in [200, 302]
assert Coupon.objects.count() == (coupons_before + 1)
new_coupon = Coupon.objects.filter(supplier=supplier).first()
assert new_coupon
# Another superuser shouldn't see this campaign
request = apply_request_middleware(rf.post("/", data=data), user=another_superuser)
assert get_supplier(request) == supplier2
with pytest.raises(Http404):
response = view(request, pk=new_coupon.pk)
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_coupon_admin_with_supplier.py
示例9: test_lcfg
def test_lcfg(rf):
two_thirds = int(LayoutCellGeneralInfoForm.CELL_FULL_WIDTH * 2 / 3)
with plugin_override():
with override_current_theme_class(None):
theme = get_current_theme(get_default_shop())
cell = LayoutCell(theme, "text", sizes={"md": two_thirds, "sm": two_thirds})
lcfg = LayoutCellFormGroup(layout_cell=cell, theme=theme, request=apply_request_middleware(rf.get("/")))
assert "general" in lcfg.forms
assert "plugin" in lcfg.forms
assert not lcfg.is_valid() # Oh, we must've forgotten the text...
lcfg = LayoutCellFormGroup(
data={
"general-cell_width": "%d" % two_thirds,
"general-cell_align": " ",
"general-cell_extra_classes" : "newClass",
"plugin-text_*": "Hello, world!"
},
layout_cell=cell,
theme=theme,
request=apply_request_middleware(rf.get("/"))
)
assert lcfg.is_valid() # Let's see now!
lcfg.save()
assert cell.sizes["md"] == two_thirds
assert cell.extra_classes == "newClass"
assert cell.config["text"] == {FALLBACK_LANGUAGE_CODE: "Hello, world!"}
开发者ID:ruqaiya,项目名称:shuup,代码行数:27,代码来源:test_editor_forms.py
示例10: 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
示例11: test_product_edit_view_multipleshops
def test_product_edit_view_multipleshops(rf):
"""
Check whether a staff user from Shop A can see the product from Shop B
when the staff user is only attached to Shop A
"""
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
shop1 = get_default_shop()
shop2 = get_new_shop(identifier="shop2", domain="shop2", name="Shop 2")
shop2_staff = create_random_user(is_staff=True)
shop2.staff_members.add(shop2_staff)
product = create_product("shop1-product", shop=shop1)
shop_product = product.get_shop_instance(shop1)
request = apply_request_middleware(rf.get("/", HTTP_HOST=shop2.domain), user=shop2_staff)
view_func = ProductEditView.as_view()
with pytest.raises(Http404):
view_func(request, pk=shop_product.pk)
view_func = ProductListView.as_view()
payload = {"jq": json.dumps({"perPage": 100, "page": 1}), "shop": shop2.pk}
request = apply_request_middleware(rf.get("/", payload, HTTP_HOST=shop2.domain), user=shop2_staff)
response = view_func(request)
assert response.status_code == 200
data = json.loads(response.content.decode("utf-8"))
assert len(data["items"]) == 0
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:test_product_module.py
示例12: test_iframe_mode
def test_iframe_mode(rf, admin_user, extra_query_param, extra_query_value, expected_script):
get_default_shop()
view = load("shuup.admin.modules.categories.views:CategoryEditView").as_view()
request = apply_request_middleware(rf.get("/", {"mode": "iframe"}), user=admin_user)
response = view(request)
if hasattr(response, "render"):
response.render()
assert 200 <= response.status_code < 300
content = force_text(response.content)
post = extract_form_fields(BeautifulSoup(content, "lxml"))
post.update({
"base-name__en": "Name"
})
post.pop("base-image")
# save iframe mode
request = apply_request_middleware(rf.post("/", post), user=admin_user)
request.GET = request.GET.copy()
request.GET["mode"] = "iframe"
if extra_query_param:
request.GET[extra_query_param] = extra_query_value
response = view(request)
assert response.status_code == 302
client = Client()
client.login(username="admin", password="password")
response = client.get(response.url)
assert response.status_code == 200
assert expected_script in force_text(response.content)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:test_views.py
示例13: get_context
def get_context(rf, customer=None):
request = rf.get("/")
request.shop = factories.get_default_shop()
apply_request_middleware(request)
if customer:
request.customer = customer
return get_jinja_context(**{"request": request})
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:test_plugins.py
示例14: test_multishops_middleware
def test_multishops_middleware(rf, host):
with override_provides("xtheme", [
"shuup_tests.xtheme.utils:FauxTheme",
"shuup_tests.xtheme.utils:FauxTheme2"
]):
shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")
theme_settings_shop1 = ThemeSettings.objects.create(theme_identifier=FauxTheme.identifier, shop=shop1)
theme_settings_shop2 = ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier, shop=shop2)
request = rf.get("/")
request.META["HTTP_HOST"] = host
# should apply the correct shop and the template
apply_request_middleware(request)
if host == "shop-1.somedomain.com":
assert request.shop.id == shop1.id
assert get_middleware_current_theme().identifier == FauxTheme.identifier
assert get_middleware_current_theme().settings_obj.id == theme_settings_shop1.id
else:
assert request.shop.id == shop2.id
assert get_middleware_current_theme().identifier == FauxTheme2.identifier
assert get_middleware_current_theme().settings_obj.id == theme_settings_shop2.id
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:test_multishop.py
示例15: test_get_shop
def test_get_shop(rf, get_shop_fn):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
activate("en")
shop1 = Shop.objects.create(identifier="shop1", status=ShopStatus.ENABLED)
shop2 = Shop.objects.create(identifier="shop2", status=ShopStatus.ENABLED)
normal_user = factories.create_random_user()
staff_user = factories.create_random_user(is_staff=True)
request = apply_request_middleware(rf.post("/"), user=normal_user, skip_session=True)
# user not staff
assert get_shop_fn(request) is None
# staff user now
with pytest.raises(PermissionDenied) as exc:
request = apply_request_middleware(rf.post("/"), user=staff_user)
assert exc.value == "You are not a staff member of this shop"
# no shop set
assert get_shop_fn(request) is None
# adds the user to a shop
shop1.staff_members.add(staff_user)
request = apply_request_middleware(rf.post("/"), user=staff_user, skip_session=True)
assert get_shop_fn(request) == shop1
# adds the user to another shop
shop2.staff_members.add(staff_user)
# still the first shop as we do not set any
assert get_shop_fn(request) == shop1
for shop in [shop1, shop2]:
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
assert get_shop_fn(request) == shop
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_shop_provider.py
示例16: test_delete_payment
def test_delete_payment(admin_user, rf):
product = get_default_product()
shop_product = product.get_shop_instance(get_default_shop())
shop_product.default_price_value = 20
shop_product.save()
order = create_random_order(customer=create_random_person(), products=(product,), completion_probability=0)
payment_amount = order.taxful_total_price_value
# create a payment
view = OrderCreatePaymentView.as_view()
request = apply_request_middleware(rf.post("/", {"amount": payment_amount}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code == 302
order.refresh_from_db()
assert order.is_paid()
# delete the payment
payment = order.payments.last()
view = OrderDeletePaymentView.as_view()
request = apply_request_middleware(rf.post("/", {"payment": payment.pk}), user=admin_user)
response = view(request, pk=order.pk)
assert response.status_code == 302
order.refresh_from_db()
assert order.is_not_paid()
开发者ID:ruqaiya,项目名称:shuup,代码行数:27,代码来源:test_order_module.py
示例17: get_request_for_contact_tests
def get_request_for_contact_tests(rf):
activate("en")
request = rf.get("/")
request.shop = get_shop(prices_include_tax=True)
get_payment_method(request.shop)
apply_request_middleware(request)
return request
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:test_basket_contact_conditions.py
示例18: _test_exception_delete_view
def _test_exception_delete_view(rf, index):
shop = factories.get_shop(identifier="shop%s" % index, enabled=True)
staff_user = factories.create_random_user(is_staff=True)
shop.staff_members.add(staff_user)
exception_name = "Exception %s" % index
exception = AvailabilityException.objects.create(
name=exception_name, start_datetime=now(), end_datetime=now())
exception.shops = [shop]
extra_exception = AvailabilityException.objects.create(
name="Extra Exception %s" % index, start_datetime=now(), end_datetime=now())
extra_exception.shops = [shop]
assert AvailabilityException.objects.filter(name=exception_name).exists()
view_func = AvailabilityExceptionDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
response = view_func(request, pk=exception.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
assert not AvailabilityException.objects.filter(name=exception_name).exists()
# Make sure that this staff can't remove other people discounts
other_exceptions = AvailabilityException.objects.exclude(shops=shop)
exception_count = other_exceptions.count()
for coupon in other_exceptions:
view_func = AvailabilityExceptionDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
with pytest.raises(Http404):
response = view_func(request, pk=coupon.pk)
if hasattr(response, "render"):
response.render()
assert exception_count == AvailabilityException.objects.exclude(shops=shop).count()
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_exceptions_admin.py
示例19: test_parallel_baskets
def test_parallel_baskets(rf):
request = get_request_with_basket()
shop = get_default_shop()
customer = create_random_person()
request = rf.get("/")
request.shop = shop
apply_request_middleware(request)
request.customer = customer
basket_one = get_basket(request, basket_name="basket_one")
basket_two = get_basket(request, basket_name="basket_two")
product_one = get_default_product()
product_two = get_default_product()
product_two.sku = "derpy-hooves"
sales_unit = SalesUnit.objects.create(identifier="test-sales-partial", decimals=2, name="Partial unit")
product_two.sales_unit = sales_unit # Set the sales unit for the product
product_two.save()
basket_commands.handle_add(request, basket_one, product_id=product_one.pk, quantity=1)
basket_commands.handle_add(request, basket_two, product_id=product_two.pk, quantity=3.5)
assert basket_one.product_count == 1
assert basket_two.product_count == 3.5
开发者ID:suutari-ai,项目名称:shuup,代码行数:25,代码来源:test_basket_commands.py
示例20: test_region_views
def test_region_views(rf, admin_user):
get_default_shop()
view = load("shuup_shipping_table.admin.views.region.RegionListView").as_view()
request = apply_request_middleware(rf.get("/"), user=admin_user)
response = view(request)
assert response.status_code == 200
view = load("shuup_shipping_table.admin.views.region.RegionEditView").as_view()
request = apply_request_middleware(rf.get("/"), user=admin_user)
response = view(request)
assert response.status_code == 200
view = load("shuup_shipping_table.admin.views.region.RegionDeleteView").as_view()
request = apply_request_middleware(rf.post("/"), user=admin_user)
with pytest.raises(Http404):
response = view(request, pk=1)
view = load("shuup_shipping_table.admin.views.region.RegionImportView").as_view()
request = apply_request_middleware(rf.post("/"), user=admin_user)
response = view(request)
assert response.status_code == 302
view = load("shuup_shipping_table.admin.views.region.RegionExportView").as_view()
request = apply_request_middleware(rf.get("/"), user=admin_user)
response = view(request)
assert response.status_code == 200
开发者ID:rockho-team,项目名称:shuup-shipping-table,代码行数:28,代码来源:test_admin_views.py
注:本文中的shuup.testing.utils.apply_request_middleware函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论