本文整理汇总了Python中shoop.admin.module_registry.replace_modules函数的典型用法代码示例。如果您正苦于以下问题:Python replace_modules函数的具体用法?Python replace_modules怎么用?Python replace_modules使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace_modules函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_permission_group_form_updates_members
def test_permission_group_form_updates_members(regular_user):
with replace_modules([ARestrictedTestModule]):
modules = [m for m in get_modules()]
test_module = modules[0]
module_permissions = test_module.get_required_permissions()
assert module_permissions
group = get_default_permission_group()
form = PermissionGroupForm(instance=group, prefix=None)
assert not group.permissions.all()
assert not group.user_set.all()
data = {
"name": "New Name",
"modules": [force_text(test_module.name)],
"members": [force_text(regular_user.pk)],
}
form = PermissionGroupForm(instance=group, prefix=None, data=data)
form.save()
module_permissions = [get_permission_object_from_string(m) for m in module_permissions]
assert group.name == "New Name"
assert set(module_permissions) == set(group.permissions.all())
assert regular_user in group.user_set.all()
form = PermissionGroupForm(instance=group, prefix=None, data={"name": "Name"})
form.save()
assert not group.permissions.all()
assert not group.user_set.all()
示例2: test_dashboard_blocks
def test_dashboard_blocks(rf):
request = rf.get("/")
with replace_modules([TestModule]):
block_ids = set()
for block in chain(*(m.get_dashboard_blocks(request) for m in get_modules())):
block_ids.add(block.id)
assert block_ids >= set(["test-0", "test-1", "test-2", "test-3", "test-4"])
示例3: test_url_auth
def test_url_auth(rf):
def did_disallow(view, request):
try:
return isinstance(view(request), HttpResponseRedirect)
except Problem as prob:
return True # Problems are fine here
with replace_modules([TestModule]):
urls = dict((u.name, u) for u in get_module_urls())
request = rf.get("/")
request.user = AnonymousUser()
assert did_disallow(urls["test-auth"].callback, request)
assert did_disallow(urls["test-perm"].callback, request)
assert not did_disallow(urls["test-unauth"].callback, request)
request.user = AuthenticatedUser()
assert did_disallow(urls["test-auth"].callback, request)
assert did_disallow(urls["test-perm"].callback, request)
assert not did_disallow(urls["test-unauth"].callback, request)
request.user = StaffUser()
assert not did_disallow(urls["test-auth"].callback, request)
assert did_disallow(urls["test-perm"].callback, request)
assert not did_disallow(urls["test-unauth"].callback, request)
request.user = SuperUser()
assert not did_disallow(urls["test-auth"].callback, request)
assert not did_disallow(urls["test-perm"].callback, request)
assert not did_disallow(urls["test-unauth"].callback, request)
示例4: 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)
示例5: test_search
def test_search(client, rf):
if "shoop.guide" not in settings.INSTALLED_APPS:
pytest.skip("Need shoop.guide in INSTALLED_APPS")
request = rf.get("/")
search_term = "customer"
request.session = client.session
with replace_modules([GuideAdminModule]):
with override_settings(SHOOP_GUIDE_FETCH_RESULTS=False):
results = get_search_results(request, search_term)
assert [r for r in results if search_term in r.text]
示例6: test_tax_edit_view_works_at_all
def test_tax_edit_view_works_at_all(rf, admin_user):
pytest.skip("it doesn't")
request = rf.get("/")
request.user = admin_user
with replace_modules([TaxModule]):
with admin_only_urls():
view_func = TaxClassEditView.as_view()
response = view_func(request, pk=default_tax.pk)
assert (default_tax.name in response.rendered_content) # it's probable the name is there
response = view_func(request, pk=None) # "new mode"
assert response.rendered_content # yeah, something gets rendered
示例7: test_product_edit_view_works_at_all
def test_product_edit_view_works_at_all(rf, admin_user):
get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
with replace_modules([ProductModule]):
with admin_only_urls():
default_product = get_default_product()
view_func = ProductEditView.as_view()
response = view_func(request, pk=default_product.pk)
assert (default_product.sku in response.rendered_content) # it's probable the SKU is there
response = view_func(request, pk=None) # "new mode"
assert response.rendered_content # yeah, something gets rendered
示例8: test_product_module_search
def test_product_module_search(rf, admin_user):
get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
with replace_modules([ProductModule]):
with admin_only_urls():
default_product = get_default_product()
model_url = get_model_url(default_product)
sku = default_product.sku
assert any(sr.url == model_url for sr in get_search_results(request, query=sku)) # Queries work
assert any(sr.is_action for sr in get_search_results(request, query=sku[:5])) # Actions work
assert empty_iterable(get_search_results(request, query=sku[:2])) # Short queries don't
示例9: test_product_edit_view_with_params
def test_product_edit_view_with_params(rf, admin_user):
get_default_shop()
sku = "test-sku"
name = "test name"
request = apply_request_middleware(rf.get("/", {"name": name, "sku": sku}), user=admin_user)
with replace_modules([ProductModule]):
with admin_only_urls():
view_func = ProductEditView.as_view()
response = view_func(request)
assert (sku in response.rendered_content) # it's probable the SKU is there
assert (name in response.rendered_content) # it's probable the name is there
示例10: test_product_edit_view_works_at_all
def test_product_edit_view_works_at_all(rf, admin_user):
shop = get_default_shop()
product = create_product("test-product", shop, default_price=200)
shop_product = product.get_shop_instance(shop)
shop_product.visibility_limit = ProductVisibility.VISIBLE_TO_GROUPS
shop_product.save()
request = apply_request_middleware(rf.get("/"), user=admin_user)
with replace_modules([ProductModule]):
with admin_only_urls():
view_func = ProductEditView.as_view()
response = view_func(request, pk=product.pk)
assert (product.sku in response.rendered_content) # it's probable the SKU is there
response = view_func(request, pk=None) # "new mode"
assert response.rendered_content # yeah, something gets rendered
示例11: test_tax_edit_view_works_at_all
def test_tax_edit_view_works_at_all(rf, admin_user):
get_default_shop() # We need a shop to exists
request = apply_request_middleware(rf.get("/"))
request.user = admin_user
default_tax_class = get_default_tax_class()
with replace_modules([TaxModule]):
with admin_only_urls():
view_func = TaxClassEditView.as_view()
response = view_func(request, pk=default_tax_class.pk)
response.render()
assert (default_tax_class.name in force_text(response.content))
response = view_func(request, pk=None) # "new mode"
response.render()
assert response.content
示例12: test_permissions_for_menu_entries
def test_permissions_for_menu_entries(rf, admin_user):
permissions = set(["shoop.add_product", "shoop.delete_product", "shoop.change_product"])
request = rf.get("/")
request.user = StaffUser()
request.user.permissions = permissions
with replace_modules([ARestrictedTestModule]):
modules = [m for m in get_modules()]
assert request.user.permissions == modules[0].get_required_permissions()
categories = get_menu_entry_categories(request)
assert categories
# Make sure category is displayed if user has correct permissions
test_category_menu_entries = categories.get("RestrictedTest")
assert any(me.text == "OK" for me in test_category_menu_entries)
# No menu items should be displayed if user has no permissions
request.user.permissions = []
categories = get_menu_entry_categories(request)
assert not categories
示例13: test_url_auth
def test_url_auth(rf):
def did_redirect(view, request):
return isinstance(view(request), HttpResponseRedirect)
with replace_modules([TestModule]):
urls = dict((u.name, u) for u in get_module_urls())
request = rf.get("/")
request.user = AnonymousUser()
assert did_redirect(urls["test-auth"].callback, request)
assert did_redirect(urls["test-perm"].callback, request)
assert not did_redirect(urls["test-unauth"].callback, request)
request.user = AuthenticatedUser()
assert did_redirect(urls["test-auth"].callback, request)
assert did_redirect(urls["test-perm"].callback, request)
assert not did_redirect(urls["test-unauth"].callback, request)
request.user = StaffUser()
assert not did_redirect(urls["test-auth"].callback, request)
assert did_redirect(urls["test-perm"].callback, request)
assert not did_redirect(urls["test-unauth"].callback, request)
request.user = SuperUser()
assert not did_redirect(urls["test-auth"].callback, request)
assert not did_redirect(urls["test-perm"].callback, request)
assert not did_redirect(urls["test-unauth"].callback, request)
示例14: test_menu_entries
def test_menu_entries(rf):
request = rf.get("/")
with replace_modules([TestModule]):
test_category_menu_entries = get_menu_entry_categories(request).get("Test")
assert any(me.text == "OK" for me in test_category_menu_entries)
示例15: test_notifications
def test_notifications(rf):
request = rf.get("/")
with replace_modules([TestModule]):
assert any(n.text == "OK" for n in chain(*(m.get_notifications(request) for m in get_modules())))