예제 #1
0
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
예제 #2
0
파일: test_urls.py 프로젝트: gurch101/shuup
def test_model_url():
    with admin_only_urls():
        with pytest.raises(NoModelUrl):
            get_model_url(Counter)  # That's silly!
        p = get_default_product()

        assert get_model_url(p)
예제 #3
0
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
예제 #4
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([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
예제 #5
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, 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
예제 #6
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, 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
예제 #7
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
예제 #8
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
예제 #9
0
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
예제 #10
0
파일: test_admin.py 프로젝트: ruqaiya/shuup
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
예제 #11
0
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,
                          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
예제 #12
0
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
예제 #13
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([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
예제 #14
0
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
예제 #15
0
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("/"), user=admin_user)
    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
예제 #16
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([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
예제 #17
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("/"))
    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
예제 #18
0
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
예제 #19
0
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