コード例 #1
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
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)
コード例 #2
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
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(WshopAdminAppConfig.provides["admin_module"]):
        assert all(get_module_urls())
        assert get_menu_entry_categories(request)
コード例 #3
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
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"])
コード例 #4
0
def test_search(client, rf):
    if "wshop.guide" not in settings.INSTALLED_APPS:
        pytest.skip("Need wshop.guide in INSTALLED_APPS")
    request = rf.get("/")
    search_term = "customer"
    request.session = client.session
    with replace_modules([GuideAdminModule]):
        with override_settings(WSHOP_GUIDE_FETCH_RESULTS=False):
            results = get_search_results(request, search_term)
            assert [r for r in results if search_term in r.text]
コード例 #5
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
def test_search(rf):
    request = rf.get("/")
    with replace_modules([ATestModule]):
        assert any(sr.to_json()["text"] == "yes"
                   for sr in get_search_results(request, "yes"))
        assert any(
            sr.url == "/OK"
            for sr in get_search_results(request, "spooky"))  # Test aliases
        assert any(sr.target == "_blank"
                   for sr in get_search_results(request, "yes"))
コード例 #6
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
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)
コード例 #7
0
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,
                          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
コード例 #8
0
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,
                          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
コード例 #9
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
def test_dashboard_blocks_permissions(rf, client):
    with replace_modules([ARestrictedTestModule]):
        permissions = set([
            "wshop.add_product", "wshop.delete_product", "wshop.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"]
コード例 #10
0
ファイル: test_tax_module.py プロジェクト: vituocgia/wshop
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
コード例 #11
0
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]):
        with admin_only_urls():
            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
コード例 #12
0
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([CategoryModule, ImportAdminModule, ProductModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        with admin_only_urls():
            view_func = ProductEditView.as_view()
            response = view_func(request, pk=product.pk)
            response.render()
            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
コード例 #13
0
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()
コード例 #14
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
def test_notifications(rf):
    request = rf.get("/")
    with replace_modules([ATestModule]):
        assert any(n.text == "OK" for n in chain(*(m.get_notifications(request)
                                                   for m in get_modules())))
コード例 #15
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
def test_module_loading_and_urls():
    with replace_modules(
        [ATestModule, "wshop_tests.admin.fixtures.test_module:ATestModule"]):
        assert all(u.name.startswith("test") for u in get_module_urls())
コード例 #16
0
ファイル: test_modules.py プロジェクト: vituocgia/wshop
def test_activity(rf):
    with replace_modules([ATestModule]):
        request = rf.get("/")
        texts = [a.text for a in get_activity(request, 10)]
        # Check that activity is returned in newest-first order.
        assert texts == ["Latest", "Later", "Earlier", "Earliest"]