Beispiel #1
0
def test_edit_object_view_errors(rf, admin_user):
    shop = factories.get_default_shop()
    view = EditObjectView.as_view()

    # missing params
    response = view(
        apply_request_middleware(rf.get(reverse("shuup_admin:edit")),
                                 user=admin_user,
                                 shop=shop))
    assert response.status_code == 400
    assert "Invalid object" in response.content.decode("utf-8")

    # invalid model
    response = _get_edit_object_view(rf, view, ".", None, admin_user, shop)
    assert response.status_code == 400
    assert "Invalid object" in response.content.decode("utf-8")

    # invalid object ID
    product = factories.create_product("p1", shop,
                                       factories.get_default_supplier())
    model = ".".join(ContentType.objects.get_for_model(product).natural_key())
    with pytest.raises(Http404) as error:
        _get_edit_object_view(rf, view, model, product.id + 10, admin_user,
                              shop)
    assert "Object not found" in str(error)

    # object has no admin url
    from shuup.core.models import ConfigurationItem
    config = ConfigurationItem.objects.create(shop=shop,
                                              key="test",
                                              value={"value": 123})
    model = ".".join(ContentType.objects.get_for_model(config).natural_key())
    with pytest.raises(Http404) as error:
        _get_edit_object_view(rf, view, model, config.id, admin_user, shop)
    assert "Object not found" in str(error)
Beispiel #2
0
def test_edit_object_view_errors(rf, admin_user):
    shop = factories.get_default_shop()
    view = EditObjectView.as_view()

    # missing params
    response = view(apply_request_middleware(rf.get(reverse("shuup_admin:edit")), user=admin_user, shop=shop))
    assert response.status_code == 400
    assert "Invalid object" in response.content.decode("utf-8")

    # invalid model
    response = _get_edit_object_view(rf, view, ".", None, admin_user, shop)
    assert response.status_code == 400
    assert "Invalid model" in response.content.decode("utf-8")

    # invalid object ID
    product = factories.create_product("p1", shop, factories.get_default_supplier())
    model = ".".join(ContentType.objects.get_for_model(product).natural_key())
    with pytest.raises(Http404) as error:
        _get_edit_object_view(rf, view, model, product.id + 10, admin_user, shop)
    assert "Object not found" in str(error)

    # object has no admin url
    from shuup.core.models import ConfigurationItem
    config = ConfigurationItem.objects.create(shop=shop, key="test", value={"value": 123})
    model = ".".join(ContentType.objects.get_for_model(config).natural_key())
    with pytest.raises(Http404) as error:
        _get_edit_object_view(rf, view, model, config.id, admin_user, shop)
    assert "Object not found" in str(error)
def test_edit_object_view(rf, admin_user, creator_fn):
    shop = factories.get_default_shop()
    view = EditObjectView.as_view()
    object_instance = creator_fn()
    model = ".".join(ContentType.objects.get_for_model(object_instance).natural_key())

    # correct shop
    response = _get_edit_object_view(rf, view, model, object_instance.id, admin_user, shop)
    assert response.status_code == 302

    urls = []

    try:
        urls.append(get_model_url(object_instance, kind="edit", user=admin_user, shop=shop))
    except NoModelUrl:
        pass

    try:
        urls.append(get_model_url(object_instance, kind="detail", user=admin_user, shop=shop))
    except NoModelUrl:
        pass

    assert response.url in urls

    # pass the mode query parameter
    response = _get_edit_object_view(rf, view, model, object_instance.id, admin_user, shop, mode="test")
    assert response.status_code == 302
    assert "mode=test" in response.url
Beispiel #4
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard', permissions=()),
        admin_url(r'^home/$', HomeView.as_view(), name='home', permissions=()),
        admin_url(r'^wizard/$', WizardView.as_view(), name='wizard', permissions=()),
        admin_url(r'^tour/$', TourView.as_view(), name='tour', permissions=()),
        admin_url(r'^search/$', SearchView.as_view(), name='search', permissions=()),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select', permissions=()),
        admin_url(r'^edit/$', EditObjectView.as_view(), name='edit', permissions=()),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu', permissions=()),
        admin_url(r'^toggle-menu/$', MenuToggleView.as_view(), name='menu_toggle', permissions=()),
        admin_url(
            r'^login/$',
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name='login',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^logout/$',
            auth_views.logout,
            kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
            name='logout',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^recover-password/(?P<uidb64>.+)/(?P<token>.+)/$',
            ResetPasswordView,
            name='recover_password',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^request-password/$',
            RequestPasswordView,
            name='request_password',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^set-language/$',
            csrf_exempt(set_language),
            name="set-language",
            permissions=()
        ),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u)

    # Add Django javascript catalog url
    urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog'))

    return tuple(urls)
def test_edit_object_view_no_permissions(rf):
    user = factories.create_random_user("en", is_staff=True)
    shop = factories.get_default_shop()
    shop.staff_members.add(user)

    view = EditObjectView.as_view()
    product = factories.create_product("p1", shop, factories.get_default_supplier())
    model = ".".join(ContentType.objects.get_for_model(product).natural_key())

    # no permission
    with pytest.raises(Problem) as error:
        _get_edit_object_view(rf, view, model, product.id, user, shop)
    assert "You do not have the required permission" in str(error)
Beispiel #6
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r"^$",
                  DashboardView.as_view(),
                  name="dashboard",
                  permissions=()),
        admin_url(r"^home/$", HomeView.as_view(), name="home", permissions=()),
        admin_url(r"^wizard/$",
                  WizardView.as_view(),
                  name="wizard",
                  permissions=()),
        admin_url(r"^tour/$", TourView.as_view(), name="tour", permissions=()),
        admin_url(r"^search/$",
                  SearchView.as_view(),
                  name="search",
                  permissions=()),
        admin_url(r"^select/$",
                  MultiselectAjaxView.as_view(),
                  name="select",
                  permissions=()),
        admin_url(r"^edit/$",
                  EditObjectView.as_view(),
                  name="edit",
                  permissions=()),
        admin_url(r"^menu/$", MenuView.as_view(), name="menu", permissions=()),
        admin_url(r"^toggle-menu/$",
                  MenuToggleView.as_view(),
                  name="menu_toggle",
                  permissions=()),
        admin_url(
            r"^stop-impersonating-staff/$",
            stop_impersonating_staff,
            name="stop-impersonating-staff",
            permissions=(),
        ),
        admin_url(
            r"^login/$",
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name="login",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(r"^logout/$",
                  LogoutView,
                  name="logout",
                  require_authentication=False,
                  permissions=()),
        admin_url(
            r"^recover-password/(?P<uidb64>.+)/(?P<token>.+)/$",
            ResetPasswordView,
            name="recover_password",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(
            r"^request-password/$",
            RequestPasswordView,
            name="request_password",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(r"^set-language/$",
                  csrf_exempt(set_language),
                  name="set-language",
                  permissions=()),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn(
                "Warning! Admin URL %r is not an `AdminRegexURLPattern`." % u)

    # Add Django javascript catalog url
    urls.append(url(r"^i18n.js$", javascript_catalog_all, name="js-catalog"))

    return tuple(urls)