当前位置: 首页>>代码示例>>Python>>正文


Python module_registry.replace_modules函数代码示例

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


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


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