Пример #1
0
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"]
Пример #2
0
def test_admin(rf, admin_user):
    shop = get_default_shop()
    configuration.set(shop, "setup_wizard_complete", True)
    # just visit to make sure everything is ok
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200

    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Пример #3
0
def test_admin(rf, admin_user):
    shop = get_default_shop()
    configuration.set(shop, "setup_wizard_complete", True)
    # just visit to make sure everything is ok
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200

    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Пример #4
0
def test_dashboard_redirect(rf, admin_user, settings):
    settings.SHUUP_SETUP_WIZARD_PANE_SPEC = []
    shop = get_default_shop()
    shop.maintenance_mode = True
    shop.save()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 302
    assert response["Location"] == reverse("shuup_admin:home")

    shop.maintenance_mode = False
    shop.save()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Пример #5
0
def test_dashboard_redirect(rf, admin_user, settings):
    settings.SHUUP_SETUP_WIZARD_PANE_SPEC = []
    shop = get_default_shop()
    shop.maintenance_mode = True
    shop.save()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 302
    assert response["Location"] == reverse("shuup_admin:home")

    shop.maintenance_mode = False
    shop.save()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Пример #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'^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)
Пример #7
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard'),
        admin_url(r'^search/$', SearchView.as_view(), name='search'),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu'),
        admin_url(r'^login/$',
                  login,
                  kwargs={"template_name": "shuup/admin/auth/login.jinja"},
                  name='login',
                  require_authentication=False),
        admin_url(r'^logout/$',
                  auth_views.logout,
                  kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
                  name='logout',
                  require_authentication=False),
        admin_url(r'^set-language/$',
                  csrf_exempt(set_language),
                  name="set-language"),
    ])

    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)
Пример #8
0
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"]
Пример #9
0
def test_telemetry_is_sent_on_login(rf, admin_user):
    shop = get_default_shop()
    with patch.object(requests, "post", return_value=MockResponse("test")) as requestor:
        with override_settings(SHUUP_TELEMETRY_ENABLED=True):
            _backdate_installation_key(days=0)  # instance was created today
            request = apply_request_middleware(rf.get("/"), user=admin_user)
            view_func = DashboardView.as_view()
            response = view_func(request)
            sent = get_last_submission_time()

            response = view_func(request)
            assert get_last_submission_time() == sent

            response = view_func(request)
            assert get_last_submission_time() == sent

            assert len(requestor.mock_calls) == 1
Пример #10
0
def test_telemetry_is_sent_on_login(rf, admin_user):
    shop = get_default_shop()
    with patch.object(requests, "post", return_value=MockResponse("test")) as requestor:
        with override_settings(SHUUP_TELEMETRY_ENABLED=True):
            _backdate_installation_key(days=0)  # instance was created today
            request = apply_request_middleware(rf.get("/"), user=admin_user)
            view_func = DashboardView.as_view()
            response = view_func(request)
            sent = get_last_submission_time()

            response = view_func(request)
            assert get_last_submission_time() == sent

            response = view_func(request)
            assert get_last_submission_time() == sent

            assert len(requestor.mock_calls) == 1
Пример #11
0
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"]
Пример #12
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard'),
        admin_url(r'^home/$', HomeView.as_view(), name='home'),
        admin_url(r'^wizard/$', WizardView.as_view(), name='wizard'),
        admin_url(r'^tour/$', TourView.as_view(), name='tour'),
        admin_url(r'^search/$', SearchView.as_view(), name='search'),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu'),
        admin_url(
            r'^login/$',
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name='login',
            require_authentication=False
        ),
        admin_url(
            r'^logout/$',
            auth_views.logout,
            kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
            name='logout',
            require_authentication=False
        ),
        admin_url(
            r'^set-language/$',
            csrf_exempt(set_language),
            name="set-language"
        ),
    ])

    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)
Пример #13
0
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"]
Пример #14
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend(
        [
            admin_url(r"^$", DashboardView.as_view(), name="dashboard"),
            admin_url(r"^home/$", HomeView.as_view(), name="home"),
            admin_url(r"^wizard/$", WizardView.as_view(), name="wizard"),
            admin_url(r"^tour/$", TourView.as_view(), name="tour"),
            admin_url(r"^search/$", SearchView.as_view(), name="search"),
            admin_url(r"^select/$", MultiselectAjaxView.as_view(), name="select"),
            admin_url(r"^menu/$", MenuView.as_view(), name="menu"),
            admin_url(
                r"^login/$",
                login,
                kwargs={"template_name": "shuup/admin/auth/login.jinja"},
                name="login",
                require_authentication=False,
            ),
            admin_url(
                r"^logout/$",
                auth_views.logout,
                kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
                name="logout",
                require_authentication=False,
            ),
            admin_url(r"^set-language/$", csrf_exempt(set_language), name="set-language"),
        ]
    )

    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)
Пример #15
0
def test_front_error_handlers(rf):
    """
    Test that `SHUUP_ERROR_PAGE_HANDLERS_SPEC` installs error handlers that are overwriting custom ones.
    """
    with override_settings(
            DEBUG=False,
            SHUUP_ERROR_PAGE_HANDLERS_SPEC=[
                "shuup.front.error_handlers.FrontPageErrorHandler"
            ],
            MIDDLEWARE_CLASSES=[],  # For Django < 2
            MIDDLEWARE=[],
            TEMPLATES=
        [  # Overriden to be sure about the contents of our 500.jinja
            {
                "BACKEND":
                "django_jinja.backend.Jinja2",
                "DIRS": [
                    os.path.realpath(
                        os.path.join(os.path.dirname(__file__), "templates"))
                ],
                "OPTIONS": {
                    "match_extension": ".jinja",
                    "newstyle_gettext": True,
                },
                "NAME":
                "jinja2",
            }
        ]):
        with replace_urls([
                url("^aaargh/", errorful_view),
                url("^notfound/", notfound_view),
                url("^dash/", DashboardView.as_view()),
                url("^index/", IndexView.as_view()),
        ], {
                "handler404": four_oh_four,
                "handler500": handler500
        }):
            resolver = get_resolver(None)
            urlconf = resolver.urlconf_module
            handler = BaseHandler()
            handler.load_middleware()

            # test without installing the handler
            assert urlconf.handler404 == four_oh_four
            assert urlconf.handler500 == handler500

            # Test 500
            response = handler.get_response(rf.get("/aaargh/"))
            assert response.status_code == 500
            assert b"The best error" in response.content
            # Test 404
            response = handler.get_response(rf.get("/another_castle/"))
            assert response.status_code == 404
            assert b"flesh wound" in response.content

            # inject our custom error handlers
            install_error_handlers()
            assert urlconf.handler404 != four_oh_four
            assert urlconf.handler500 != handler500
            assert "miss something? 404" in force_text(
                urlconf.handler404(rf.get("/notfound/")).content)
            assert "intergalactic testing 500" in force_text(
                urlconf.handler500(rf.get("/aaargh/")).content)

            # Front must handle all possible apps
            error_handler = FrontPageErrorHandler()

            response = handler.get_response(rf.get("/aaargh/"))
            assert "intergalactic testing 500" in force_text(response.content)

            # simulate a view to check whether the handler can handle an
            # error of a non-front view, a front view and a admin view
            for path in ("/aaargh/", "/index/", "/dash/"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500)
                assert error_handler.can_handle_error(request, 400)
                assert error_handler.can_handle_error(request, 403)
                assert error_handler.can_handle_error(request, 404)

                # check the error handlers return the correct status and text
                for status, content in [
                    (500, "intergalactic testing 500"),
                    (400, "about 400"),
                    (403, "get out 403"),
                    (404, "miss something? 404"),
                ]:
                    response = error_handler.handle_error(request, status)
                    assert response.status_code == status
                    assert content in force_text(response.content)

            from django.conf import settings
            # front can't handle static and media paths
            for path in (settings.STATIC_URL + "mystaticfile",
                         settings.MEDIA_URL + "mymediafile"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500) is False
                assert error_handler.can_handle_error(request, 400) is False
                assert error_handler.can_handle_error(request, 403) is False
                assert error_handler.can_handle_error(request, 404) is False
Пример #16
0
def test_admin_error_handlers(rf):
    """
    Test that SHUUP_ERROR_PAGE_HANDLERS_SPEC installs error handlers that are overwriting custom ones.
    """
    with override_settings(
            DEBUG=False,
            SHUUP_ERROR_PAGE_HANDLERS_SPEC=[
                "shuup.admin.error_handlers.AdminPageErrorHandler"
            ],
            MIDDLEWARE_CLASSES=[],  # For Django 2
            MIDDLEWARE=[],
            TEMPLATES=
        [  # Overriden to be sure about the contents of our 500.jinja
            {
                "BACKEND":
                "django_jinja.backend.Jinja2",
                "DIRS": [
                    os.path.realpath(
                        os.path.join(os.path.dirname(__file__), "templates"))
                ],
                "OPTIONS": {
                    "match_extension": ".jinja",
                    "newstyle_gettext": True,
                },
                "NAME":
                "jinja2",
            }
        ]):
        with replace_urls([
                url("^aaargh/", errorful_view),
                url("^index/", IndexView.as_view()),
                url("^dash/", DashboardView.as_view()),
        ], {
                "handler404": four_oh_four,
                "handler500": handler500
        }):
            resolver = get_resolver(None)
            urlconf = resolver.urlconf_module
            handler = BaseHandler()
            handler.load_middleware()

            # test without installing the handler
            assert urlconf.handler404 == four_oh_four
            assert urlconf.handler500 == handler500

            # Test 500
            response = handler.get_response(rf.get("/aaargh/"))
            assert response.status_code == 500
            assert b"The best error" in response.content
            # Test 404
            response = handler.get_response(rf.get("/another_castle/"))
            assert response.status_code == 404
            assert b"flesh wound" in response.content

            # inject our custom error handlers
            install_error_handlers()

            # here the urlconfs will be the default handlers
            # because admin can't handle such requests
            # but the functions of the handlers are pointing to our factory view
            assert urlconf.handler404 != four_oh_four
            assert urlconf.handler500 != handler500
            assert "flesh wound" in force_text(
                urlconf.handler404(rf.get("/notfound/")).content)
            assert "The best error" in force_text(
                urlconf.handler500(rf.get("/aaargh/")).content)

            # Admin must handle only admin app errors
            error_handler = AdminPageErrorHandler()

            # simulate a view to check whether the handler can handle an error of a non-front view
            # Admin handler will check for the resolver_match and admin app only
            response = handler.get_response(rf.get("/aaargh/"))
            assert b"The best error" in response.content

            # can't handle non admin views neither media or static files
            from django.conf import settings
            for path in ("/aaargh/", "/index/",
                         settings.STATIC_URL + "mystaticfile",
                         settings.MEDIA_URL + "mymediafile"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500) is False
                assert error_handler.can_handle_error(request, 400) is False
                assert error_handler.can_handle_error(request, 403) is False
                assert error_handler.can_handle_error(request, 404) is False

            # simulate a view to check whether the handler can handle an error of an admin view
            request = rf.get("/dash/")
            assert error_handler.can_handle_error(request, 500) is False
            assert error_handler.can_handle_error(request, 400) is False
            assert error_handler.can_handle_error(request, 403) is False
            assert error_handler.can_handle_error(request, 404) is False

            # check the error handlers return the correct status and text
            for status, content in [
                (500, "admin 500"),
                (400, "admin 400"),
                (403, "admin 403"),
                (404, "admin 404"),
            ]:
                response = error_handler.handle_error(request, status)
                assert response.status_code == status
                assert content in force_text(response.content)
Пример #17
0
def test_front_error_handlers(rf):
    """
    Test that SHUUP_ERROR_PAGE_HANDLERS_SPEC installs error handlers overwriting custom ones
    """
    with override_settings(
        DEBUG=False,
        SHUUP_ERROR_PAGE_HANDLERS_SPEC=["shuup.front.error_handlers.FrontPageErrorHandler"],
        MIDDLEWARE_CLASSES=[],
        TEMPLATES=[  # Overriden to be sure about the contents of our 500.jinja
            {
                "BACKEND": "django_jinja.backend.Jinja2",
                "DIRS": [
                    os.path.realpath(os.path.join(os.path.dirname(__file__), "templates"))
                ],
                "OPTIONS": {
                    "match_extension": ".jinja",
                    "newstyle_gettext": True,
                },
                "NAME": "jinja2",
            }
        ]
    ):
        with replace_urls([
            url("^aaargh/", errorful_view),
            url("^notfound/", notfound_view),
            url("^dash/", DashboardView.as_view()),
            url("^index/", IndexView.as_view()),
        ], {"handler404": four_oh_four, "handler500": handler500}):
            resolver = get_resolver(None)
            urlconf = resolver.urlconf_module
            handler = BaseHandler()
            handler.load_middleware()

            # test without installing the handler
            assert urlconf.handler404 == four_oh_four
            assert urlconf.handler500 == handler500

            # Test 500
            response = handler.get_response(rf.get("/aaargh/"))
            assert response.status_code == 500
            assert b"The best error" in response.content
            # Test 404
            response = handler.get_response(rf.get("/another_castle/"))
            assert response.status_code == 404
            assert b"flesh wound" in response.content

            # inject our custom error handlers
            install_error_handlers()
            assert urlconf.handler404 != four_oh_four
            assert urlconf.handler500 != handler500
            assert "miss something? 404" in force_text(urlconf.handler404(rf.get("/notfound/")).content)
            assert "intergalactic testing 500" in force_text(urlconf.handler500(rf.get("/aaargh/")).content)

            # Front must handle all possible apps
            error_handler = FrontPageErrorHandler()

            response = handler.get_response(rf.get("/aaargh/"))
            assert "intergalactic testing 500" in force_text(response.content)

            # simulate a view to check whether the handler can handle an
            # error of a non-front view, a front view and a admin view
            for path in ("/aaargh/", "/index/", "/dash/"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500)
                assert error_handler.can_handle_error(request, 400)
                assert error_handler.can_handle_error(request, 403)
                assert error_handler.can_handle_error(request, 404)

                # check the error handlers return the correct status and text
                for status, content in [
                    (500, "intergalactic testing 500"),
                    (400, "about 400"),
                    (403, "get out 403"),
                    (404, "miss something? 404"),
                ]:
                    response = error_handler.handle_error(request, status)
                    assert response.status_code == status
                    assert content in force_text(response.content)

            from django.conf import settings
            # front can't handle static and media paths
            for path in (settings.STATIC_URL + "mystaticfile", settings.MEDIA_URL + "mymediafile"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500) is False
                assert error_handler.can_handle_error(request, 400) is False
                assert error_handler.can_handle_error(request, 403) is False
                assert error_handler.can_handle_error(request, 404) is False
Пример #18
0
def test_admin_error_handlers(rf):
    """
    Test that SHUUP_ERROR_PAGE_HANDLERS_SPEC installs error handlers overwriting custom ones
    """
    with override_settings(
        DEBUG=False,
        SHUUP_ERROR_PAGE_HANDLERS_SPEC=["shuup.admin.error_handlers.AdminPageErrorHandler"],
        MIDDLEWARE_CLASSES=[],
        TEMPLATES=[  # Overriden to be sure about the contents of our 500.jinja
            {
                "BACKEND": "django_jinja.backend.Jinja2",
                "DIRS": [
                    os.path.realpath(os.path.join(os.path.dirname(__file__), "templates"))
                ],
                "OPTIONS": {
                    "match_extension": ".jinja",
                    "newstyle_gettext": True,
                },
                "NAME": "jinja2",
            }
        ]
    ):
        with replace_urls([
            url("^aaargh/", errorful_view),
            url("^index/", IndexView.as_view()),
            url("^dash/", DashboardView.as_view()),
        ], {"handler404": four_oh_four, "handler500": handler500}):
            resolver = get_resolver(None)
            urlconf = resolver.urlconf_module
            handler = BaseHandler()
            handler.load_middleware()

            # test without installing the handler
            assert urlconf.handler404 == four_oh_four
            assert urlconf.handler500 == handler500

            # Test 500
            response = handler.get_response(rf.get("/aaargh/"))
            assert response.status_code == 500
            assert b"The best error" in response.content
            # Test 404
            response = handler.get_response(rf.get("/another_castle/"))
            assert response.status_code == 404
            assert b"flesh wound" in response.content

            # inject our custom error handlers
            install_error_handlers()

            # here the urlconfs will be the default handlers
            # because admin can't handle such requests
            # but the functions of the handlers are pointing to our factory view
            assert urlconf.handler404 != four_oh_four
            assert urlconf.handler500 != handler500
            assert "flesh wound" in force_text(urlconf.handler404(rf.get("/notfound/")).content)
            assert "The best error" in force_text(urlconf.handler500(rf.get("/aaargh/")).content)

            # Admin must handle only admin app errors
            error_handler = AdminPageErrorHandler()

            # simulate a view to check whether the handler can handle an error of a non-front view
            # Admin handler will check for the resolver_match and admin app only
            response = handler.get_response(rf.get("/aaargh/"))
            assert b"The best error" in response.content

            # can't handle non admin views neither media or static files
            from django.conf import settings
            for path in ("/aaargh/", "/index/", settings.STATIC_URL + "mystaticfile", settings.MEDIA_URL + "mymediafile"):
                request = rf.get(path)
                assert error_handler.can_handle_error(request, 500) is False
                assert error_handler.can_handle_error(request, 400) is False
                assert error_handler.can_handle_error(request, 403) is False
                assert error_handler.can_handle_error(request, 404) is False

            # simulate a view to check whether the handler can handle an error of an admin view
            request = rf.get("/dash/")
            assert error_handler.can_handle_error(request, 500) is False
            assert error_handler.can_handle_error(request, 400) is False
            assert error_handler.can_handle_error(request, 403) is False
            assert error_handler.can_handle_error(request, 404) is False

            # check the error handlers return the correct status and text
            for status, content in [
                (500, "admin 500"),
                (400, "admin 400"),
                (403, "admin 403"),
                (404, "admin 404"),
            ]:
                response = error_handler.handle_error(request, status)
                assert response.status_code == status
                assert content in force_text(response.content)
Пример #19
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)