本文整理汇总了Python中shoop.testing.utils.apply_request_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python apply_request_middleware函数的具体用法?Python apply_request_middleware怎么用?Python apply_request_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply_request_middleware函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_detail_contact_seed
def test_user_detail_contact_seed(rf):
get_default_shop()
contact = create_random_person()
# Using random data for name and email would need escaping when
# checking if it is rendered, therefore use something very basic instead
contact.name = "Matti Perustyyppi"
contact.email = "[email protected]"
contact.save()
view_func = UserDetailView.as_view()
# Check that fields populate . . .
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
# POST the password too to create the user . . .
post = extract_form_fields(BeautifulSoup(content))
post["password"] = "HELLO WORLD"
request.method = "POST"
request.POST = post
response = view_func(request)
assert response.status_code < 500
# Check this new user is visible in the details now
user = Contact.objects.get(pk=contact.pk).user
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request, pk=user.pk)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
示例2: test_basket_shipping_error
def test_basket_shipping_error(rf):
StoredBasket.objects.all().delete()
shop = get_default_shop()
supplier = get_default_supplier()
shipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.SHIPPED
)
unshipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.NOT_SHIPPED
)
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
# With a shipped product but no shipping methods, we oughta get an error
basket.add_product(supplier=supplier, shop=shop, product=shipped_product, quantity=1)
assert any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
basket.clear_all()
# But with an unshipped product, we should not
basket.add_product(supplier=supplier, shop=shop, product=unshipped_product, quantity=1)
assert not any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
示例3: 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"]
示例4: 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
示例5: 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
示例6: test_simple_search_no_results
def test_simple_search_no_results(rf):
with translation.override("xx"): # use built-in translation
get_default_shop()
view = SearchView.as_view()
resp = view(apply_request_middleware(rf.get("/", {"q": UNLIKELY_STRING})))
assert NO_RESULTS_FOUND_STRING in resp.rendered_content
resp = view(apply_request_middleware(rf.get("/")))
assert NO_RESULTS_FOUND_STRING not in resp.rendered_content
示例7: get_context
def get_context(rf, customer=None):
request = rf.get("/")
request.shop = get_default_shop()
apply_request_middleware(request)
if customer:
request.customer = customer
vars = {"request": request}
return get_jinja_context(**vars)
示例8: initialize_test
def initialize_test(rf):
shop = get_default_shop()
request = rf.get("/")
request.shop = shop
apply_request_middleware(request)
product1 = create_product("test-product1", shop=shop, default_price=120)
product2 = create_product("test-product2", shop=shop, default_price=180)
return (request, [product1, product2], shop.create_price)
示例9: test_modules_in_core_admin_work
def test_modules_in_core_admin_work(rf, admin_user):
get_default_shop()
request = rf.get("/")
apply_request_middleware(request, user=admin_user)
request = apply_request_middleware(rf.get("/"), user=admin_user)
with replace_modules(ShoopAdminAppConfig.provides["admin_module"]):
assert all(get_module_urls())
assert get_menu_entry_categories(request)
示例10: test_simple_search_view_works
def test_simple_search_view_works(rf):
view = SearchView.as_view()
prod = create_product(sku=UNLIKELY_STRING, shop=get_default_shop())
query = prod.name[:8]
# This test is pretty cruddy. TODO: Un-cruddify this test.
resp = view(apply_request_middleware(rf.get("/")))
assert query not in resp.rendered_content
resp = view(apply_request_middleware(rf.get("/", {"q": query})))
assert query in resp.rendered_content
示例11: test_basic_order
def test_basic_order(rf, admin_user, mode):
prices_include_tax = (mode == "taxful")
shop = get_shop(prices_include_tax=prices_include_tax)
request = rf.get('/')
request.shop = shop
apply_request_middleware(request)
product = get_default_product()
customer = get_person_contact(admin_user)
for x in range(10):
create_order(request, creator=admin_user, customer=customer, product=product)
assert Order.objects.filter(customer=customer).count() == 10
示例12: initialize_test
def initialize_test(rf, include_tax=False):
shop = get_shop_with_tax(include_tax=include_tax)
group = get_default_customer_group()
customer = create_random_person()
customer.groups.add(group)
customer.save()
request = rf.get("/")
request.shop = shop
apply_request_middleware(request)
request.customer = customer
return request, shop, group
示例13: test_contact_set_is_active
def test_contact_set_is_active(rf, admin_user):
get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
assert contact.is_active
request = apply_request_middleware(rf.post("/", {"set_is_active": "0"}), user=admin_user)
view_func = ContactDetailView.as_view()
response = view_func(request, pk=contact.pk)
assert response.status_code < 500 and not Contact.objects.get(pk=contact.pk).is_active
request = apply_request_middleware(rf.post("/", {"set_is_active": "1"}), user=admin_user)
view_func = ContactDetailView.as_view()
response = view_func(request, pk=contact.pk)
assert response.status_code < 500 and Contact.objects.get(pk=contact.pk).is_active
示例14: test_order_creation_adds_usage
def test_order_creation_adds_usage(rf, admin_user):
request, shop, group = initialize_test(rf, False)
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
source.add_line(
type=OrderLineType.OTHER, quantity=1, base_unit_price=source.create_price(10), require_verification=True
)
# add coupon
coupon = Coupon.objects.create(active=True, code="asdf")
campaign = BasketCampaign.objects.create(
active=True, shop=shop, name="test", public_name="test", discount_percentage="0.1", coupon=coupon
)
source.add_code(coupon.code)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = creator.create_order(source)
assert CouponUsage.objects.count() == 1
示例15: test_order_source_parentage
def test_order_source_parentage(rf, admin_user):
source = seed_source(admin_user)
product = get_default_product()
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
line_id="parent"
)
source.add_line(
type=OrderLineType.OTHER,
text="Child Line",
sku="KIDKIDKID",
quantity=1,
base_unit_price=source.create_price(5),
parent_line_id="parent"
)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = Order.objects.get(pk=creator.create_order(source).pk)
kid_line = order.lines.filter(sku="KIDKIDKID").first()
assert kid_line
assert kid_line.parent_line.product_id == product.pk