• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python module_registry.replace_modules函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shuup.admin.module_registry.replace_modules函数的典型用法代码示例。如果您正苦于以下问题:Python replace_modules函数的具体用法?Python replace_modules怎么用?Python replace_modules使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了replace_modules函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: 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([ATestModule]):
        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)
开发者ID:suutari,项目名称:shoop,代码行数:27,代码来源:test_modules.py


示例2: 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()
        PermissionGroupForm(instance=group, prefix=None)

        assert not group.permissions.all()
        assert not group.user_set.all()

        data = {
            "name": "New Name",
            "members": [force_text(regular_user.pk)],
        }
        for permission in ARestrictedTestModule().get_required_permissions():
            data["perm:%s" % permission] = permission

        form = PermissionGroupForm(instance=group, prefix=None, data=data)
        form.save()

        assert group.name == "New Name"
        assert set(module_permissions) == get_permissions_from_group(group)
        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()
开发者ID:ruqaiya,项目名称:shuup,代码行数:33,代码来源:test_permission_groups_module.py


示例3: test_dashboard_blocks

def test_dashboard_blocks(rf):
    request = rf.get("/")
    with replace_modules([ATestModule]):
        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"])
开发者ID:suutari,项目名称:shoop,代码行数:7,代码来源:test_modules.py


示例4: test_reports_admin_permissions

def test_reports_admin_permissions(rf):
    shop = get_default_shop()  # We need a shop to exists
    staff_user = get_default_staff_user(shop)
    permission_group = get_default_permission_group()
    staff_user.groups = [permission_group]
    request = apply_request_middleware(rf.get("/"), user=staff_user)
    request.user = staff_user

    with replace_modules([ReportsAdminModule]):
        with override_provides("reports", REPORTS):
            extra_permissions = ReportsAdminModule().get_extra_permissions()
            assert len(extra_permissions) == 3
            assert SalesReport.identifier in extra_permissions
            assert TotalSales.identifier in extra_permissions
            assert SalesPerHour.identifier in extra_permissions
            with admin_only_urls():
                view_func = ReportView.as_view()
                response = view_func(request)
                response.render()
                response = view_func(request, pk=None)  # "new mode"
                response.render()
                assert response.content
                soup = BeautifulSoup(response.content)
                assert soup.find("div", {"class": "content-block"}).text == "No reports available"
                expected_report_identifiers = []
                for report_cls in [SalesReport, TotalSales, SalesPerHour]:
                    expected_report_identifiers.append(report_cls.identifier)
                    set_permissions_for_group(permission_group, [report_cls.identifier])

                    response = view_func(request, pk=None)  # "new mode"
                    response.render()
                    assert response.content
                    soup = BeautifulSoup(response.content)
                    for option in soup.find("select", {"id": "id_report"}).findAll("option"):
                        assert option["value"] in expected_report_identifiers
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_admin_permissions.py


示例5: 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(ShuupAdminAppConfig.provides["admin_module"]):
        assert all(get_module_urls())
        assert get_menu_entry_categories(request)
开发者ID:suutari,项目名称:shoop,代码行数:8,代码来源:test_modules.py


示例6: test_menu_entries

def test_menu_entries(rf, admin_user):
    request = rf.get("/")
    request.user = admin_user
    with replace_modules([ATestModule]):
        categories = get_menu_entry_categories(request)
        assert categories

        test_category_menu_entries = [cat for cat in categories if cat.name == "Test"][0]
        assert any(me.text == "OK" for me in test_category_menu_entries)
开发者ID:suutari,项目名称:shoop,代码行数:9,代码来源:test_modules.py


示例7: test_search

def test_search(client, rf):
    if "shuup.guide" not in settings.INSTALLED_APPS:
        pytest.skip("Need shuup.guide in INSTALLED_APPS")
    request = rf.get("/")
    search_term = "customer"
    request.session = client.session
    with replace_modules([GuideAdminModule]):
        with override_settings(SHUUP_GUIDE_FETCH_RESULTS=False):
            results = get_search_results(request, search_term)
            assert [r for r in results if search_term in r.text]
开发者ID:ruqaiya,项目名称:shuup,代码行数:10,代码来源:test_search_results.py


示例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
开发者ID:NamiStudio,项目名称:shuup,代码行数:12,代码来源:test_product_module.py


示例9: test_dashboard_blocks_permissions

def test_dashboard_blocks_permissions(rf, client):
    with replace_modules([ARestrictedTestModule]):
        permissions = set(["shuup.add_product", "shuup.delete_product", "shuup.change_product"])
        request = rf.get("/")
        request.user = StaffUser()
        request.session = client.session
        view = DashboardView(request=request)
        assert not view.get_context_data()["blocks"]

        request.user.permissions = permissions 
        view = DashboardView(request=request)
        assert view.get_context_data()["blocks"]
开发者ID:suutari,项目名称:shoop,代码行数:12,代码来源:test_modules.py


示例10: 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
开发者ID:NamiStudio,项目名称:shuup,代码行数:12,代码来源:test_product_module.py


示例11: 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([CategoryModule, ImportAdminModule, ProductModule, MediaModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        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
开发者ID:ruqaiya,项目名称:shuup,代码行数:13,代码来源:test_product_module.py


示例12: 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([CategoryModule, ImportAdminModule, ProductModule, MediaModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        with admin_only_urls():
            default_product = get_default_product()
            model_url = get_model_url(default_product, shop=get_shop(request))
            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
开发者ID:ruqaiya,项目名称:shuup,代码行数:13,代码来源:test_product_module.py


示例13: test_campaigned_product_view

def test_campaigned_product_view(rf, admin_user):
    shop = get_default_shop()
    product = create_product("test-product", shop, default_price=200)
    shop_product = product.get_shop_instance(shop)

    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([ProductModule]):
        with admin_only_urls():
            render_product_view(product, request)
            product2 = create_product("test-product2")

            render_product_view(product2, request)  # should not break even though shop_product is not available
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:13,代码来源:test_admin.py


示例14: test_campaigned_product_view

def test_campaigned_product_view(rf, admin_user):
    shop = get_default_shop()
    product = create_product("test-product", shop, default_price=200)
    shop_product = product.get_shop_instance(shop)

    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([CategoryModule, ImportAdminModule, ProductModule, MediaModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        with admin_only_urls():
            render_product_view(shop_product, request)
            product2 = create_product("test-product2", shop)
            sp2 = product2.get_shop_instance(shop)
            render_product_view(sp2, request)  # should not break even though shop_product is not available
开发者ID:ruqaiya,项目名称:shuup,代码行数:14,代码来源:test_admin.py


示例15: test_currency_edit_view_works_at_all

def test_currency_edit_view_works_at_all(rf, admin_user):
    get_default_shop()  # We need a shop to exists
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    request.user = admin_user

    currency = get_default_currency()

    with replace_modules([CurrencyModule]):
        view_func = CurrencyEditView.as_view()
        response = view_func(request, pk=currency.pk)
        response.render()
        assert (currency.code in force_text(response.content))
        response = view_func(request, pk=None)  # "new mode"
        response.render()
        assert response.content
开发者ID:ruqaiya,项目名称:shuup,代码行数:15,代码来源:test_currency_module.py


示例16: 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
开发者ID:NamiStudio,项目名称:shuup,代码行数:15,代码来源:test_product_module.py


示例17: 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
开发者ID:gurch101,项目名称:shuup,代码行数:16,代码来源:test_tax_module.py


示例18: test_dashboard_blocks_permissions

def test_dashboard_blocks_permissions(rf, client):
    with replace_modules([ARestrictedTestModule]):
        request = rf.get("/")
        request.user = get_default_staff_user(get_default_shop())  # Dashboard permission is added by default
        request.session = client.session
        view = DashboardView(request=request)
        assert not view.get_context_data()["blocks"]

        # By default there is only dashboard permission so to be
        # able to see some blocks permission to some admin module
        # providing dashboard bocks needed.
        set_permissions_for_group(
            request.user.groups.first(),
            set("dashboard") | set(ARestrictedTestModule().get_required_permissions())
        )
        view = DashboardView(request=request)
        assert view.get_context_data()["blocks"]
开发者ID:ruqaiya,项目名称:shuup,代码行数:17,代码来源:test_modules.py


示例19: test_permissions_for_menu_entries

def test_permissions_for_menu_entries(rf, admin_user):
    request = rf.get("/")
    request.user = factories.get_default_staff_user()
    permission_group = request.user.groups.first()
    set_permissions_for_group(
        permission_group,
        set("dashboard") | set(ARestrictedTestModule().get_required_permissions())
    )

    with replace_modules([ARestrictedTestModule]):
        categories = get_menu_entry_categories(request)
        assert categories

        # Make sure category is displayed if user has correct permissions
        test_category_menu_entries = [cat for cat in categories if cat.name == "RestrictedTest"][0]
        assert any(me.text == "OK" for me in test_category_menu_entries)

        # No menu items should be displayed if user has no permissions
        set_permissions_for_group(permission_group, set())
        categories = get_menu_entry_categories(request)
        assert not categories
开发者ID:ruqaiya,项目名称:shuup,代码行数:21,代码来源:test_permissions.py


示例20: test_permissions_for_menu_entries

def test_permissions_for_menu_entries(rf, admin_user):
    permissions = set(["shuup.add_product", "shuup.delete_product", "shuup.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
开发者ID:millujye,项目名称:shuup,代码行数:22,代码来源:test_permissions.py



注:本文中的shuup.admin.module_registry.replace_modules函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python edit.OrderEditView类代码示例发布时间:2022-05-27
下一篇:
Python module_registry.get_modules函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap