コード例 #1
0
def test_export_include(mock_urlconf_module, mock_included_module):
    # Setup urls to include
    mock_included_module.urlpatterns = [
        url(r"^red/$", View.as_view(), name="red"),
        url(r"^blue/$", View.as_view(), name="blue"),
    ]

    mock_urlconf_module.urlpatterns = [
        url(r"^colors/", include("mock_included_module"))
    ]
    assert export_urlconf.as_json("mock_urlconf_module") == [{
        "regex":
        "^colors/",
        "namespace":
        None,
        "app_name":
        None,
        "includes": [{
            "regex": "^red/$",
            "name": "red"
        }, {
            "regex": "^blue/$",
            "name": "blue"
        }],
    }]
コード例 #2
0
def test_export_regex(mock_urlconf_module):
    mock_urlconf_module.urlpatterns = [
        # 'url' is just an alias for 're_path'
        url(r"^login/$", View.as_view(), name="login"),
        re_path(r"^logout/$", View.as_view(), name="logout"),
    ]
    assert export_urlconf.as_json("mock_urlconf_module") == [
        {
            "regex": "^login/$",
            "name": "login"
        },
        {
            "regex": "^logout/$",
            "name": "logout"
        },
    ]
コード例 #3
0
def test_whitelist_and_blacklist(whitelist, blacklist, expected_url_names,
                                 mock_urlconf_module, mock_included_module):
    mock_included_module.app_name = "admin"
    mock_included_module.urlpatterns = [
        url(r"^secret-1/$", View.as_view(), name="secret-1"),
        url(r"^secret-2/$", View.as_view(), name="secret-2"),
        url(r"^db-edit/$", View.as_view(), name="db-edit"),
    ]

    mock_urlconf_module.urlpatterns = [
        url(r"^public-a/$", View.as_view(), name="public-a"),
        url(r"^public-b/$", View.as_view(), name="public-b"),
        url(r"^admin/$", include("mock_included_module", namespace="admin")),
    ]
    assert (export_urlconf.get_all_allowed_url_names(
        "mock_urlconf_module", whitelist=whitelist,
        blacklist=blacklist) == expected_url_names)
コード例 #4
0
def test_export_route(mock_urlconf_module):
    mock_urlconf_module.urlpatterns = [
        path("login/", View.as_view(), name="login")
    ]
    assert export_urlconf.as_json("mock_urlconf_module") == [{
        "route": "login/",
        "name": "login"
    }]
コード例 #5
0
def test_export_include_with_namespace(
    mock_urlconf_module,
    mock_included_module,
    app_name,
    namespace,
    expected_app_name,
    expected_namespace,
):
    # Maybe set app_name on included urls module
    if app_name:
        mock_included_module.app_name = app_name

    # Setup urls to include
    mock_included_module.urlpatterns = [
        url(r"^red/$", View.as_view(), name="red"),
        url(r"^blue/$", View.as_view(), name="blue"),
    ]

    # Maybe set a namespace for the included urls
    if namespace:
        mock_urlconf_module.urlpatterns = [
            url(r"^colors/",
                include("mock_included_module", namespace=namespace))
        ]
    else:
        mock_urlconf_module.urlpatterns = [
            url(r"^colors/", include("mock_included_module"))
        ]

    assert export_urlconf.as_json("mock_urlconf_module") == [{
        "regex":
        "^colors/",
        "namespace":
        expected_namespace,
        "app_name":
        expected_app_name,
        "includes": [{
            "regex": "^red/$",
            "name": "red"
        }, {
            "regex": "^blue/$",
            "name": "blue"
        }],
    }]
コード例 #6
0
ファイル: test_logger.py プロジェクト: snelis/auditlog
    def test_set_django_http_response(self):
        audit_log = DjangoAuditLogger()
        request = self.request_factory.get('/')
        response = View.as_view()(request)
        audit_log.set_django_http_response(response)

        self.assertEqual(audit_log.http_response['status_code'], 405)
        self.assertEqual(audit_log.http_response['reason'],
                         'Method Not Allowed')
        self.assertTrue('Allow' in audit_log.http_response['headers'])
        self.assertTrue('Content-Type' in audit_log.http_response['headers'])
コード例 #7
0
def test_export_locale_prefix_pattern(mock_urlconf_module):
    mock_urlconf_module.urlpatterns = i18n_patterns(
        url(r"^$", View.as_view(), name="index"))
    assert export_urlconf.as_json("mock_urlconf_module") == [{
        "isLocalePrefix":
        True,
        "classPath":
        "django.urls.resolvers.LocalePrefixPattern",
        "includes": [{
            "regex": "^$",
            "name": "index"
        }],
    }]
コード例 #8
0
def test_export_multi_language_without_country(mock_urlconf_module):
    mock_urlconf_module.urlpatterns = [
        url(lazy(_get_color_url_pattern, str)(), View.as_view(), name="color")
    ]
    assert export_urlconf.as_json("mock_urlconf_module",
                                  language_without_country=True) == [{
                                      "regex": {
                                          "en": "^color/$",
                                          "fr": "^couleur/$"
                                      },
                                      "name":
                                      "color"
                                  }]
コード例 #9
0
def test_export_custom_locale_prefix_pattern_class(mock_urlconf_module):
    mock_urlconf_module.urlpatterns = [
        URLResolver(CustomLocalePrefixPattern(),
                    [url(r"^$", View.as_view(), name="index")])
    ]
    assert export_urlconf.as_json("mock_urlconf_module") == [{
        "isLocalePrefix":
        True,
        "classPath":
        "tests.django_urlconf_export.test_export_urlconf.CustomLocalePrefixPattern",
        "includes": [{
            "regex": "^$",
            "name": "index"
        }],
    }]
コード例 #10
0
ファイル: test_middleware.py プロジェクト: snelis/auditlog
    def test_process_response(self, mocked_audit_log):
        """
        Assert that the response has been added to the audit log and
        that the log has been fired.
        """
        # prepare request
        request = self.request_factory.get('/')
        self.middleware.process_request(request)

        # prepare response
        response = View.as_view()(request)
        self.middleware.process_response(request, response)

        mocked_instance = mocked_audit_log.return_value
        mocked_instance.set_django_http_response.assert_called_with(response)
        mocked_instance.send_log.assert_called()
コード例 #11
0
    def test_process_response_without_audit_log(self, mocked_audit_log):
        """
        Assert that when the audit log does not exist, we do not try to call any
        methods on it
        """
        # prepare request (but don't pass through middleware, so that hasattr(request, 'audit_log') is False
        request = self.request_factory.get('/')
        self.assertFalse(hasattr(request, 'audit_log'), "Audit log should not have been attached to request")

        # prepare response
        response = View.as_view()(request)
        self.middleware.process_response(request, response)

        mocked_instance = mocked_audit_log.return_value
        mocked_instance.set_http_response.assert_not_called()
        mocked_instance.send_log.assert_not_called()
コード例 #12
0
"""server URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.views import View

urlpatterns = [
    url(r'^pn/', include('payment.urls')),
    url(r'^return/(?P<pk>\d+)$', View.as_view(), name="return_page"),
    url(r'^info/(?P<pk>\d+)$', View.as_view(), name="product_info"),
]
コード例 #13
0
ファイル: test_urls.py プロジェクト: tboulogne/django-cruds
 def setUp(self):
     super(TestUrls, self).setUp()
     self.view = View.as_view()
コード例 #14
0
ファイル: urls.py プロジェクト: KqSMea8/directory-components
from django.conf.urls import include, url
from django.views import View
from django.views.generic.base import RedirectView

import directory_components.views

admin_urls = [
    url(r"^thing/$", RedirectView.as_view(url='/login/'), name='thing'),
]

urlpatterns = [
    url(
        r'^$',
        View.as_view(),
        name='index',
    ),
    url(r'^admin/', include(admin_urls, namespace='admin', app_name='admin')),
    url(r"^robots\.txt$",
        directory_components.views.RobotsView.as_view(),
        name='robots'),
    url(r"^sitemap\.txt$", View.as_view(), name='sitemap'),
    url(r"^some/path/$", View.as_view(), name='some-path'),
    url(r'^i18n/', include('django.conf.urls.i18n')),
]
コード例 #15
0
from django.contrib import admin
from django.http import HttpResponse
from django.urls import path
from django.views import View


class DockerApp1View(View):
    http_method_names = ['get']

    def get(self, request):
        """
        This is DockerApp1's example View

        Khai, 25.06.2019
        """
        print("LOL?")
        return HttpResponse("DockerApp1 Greets You")


urlpatterns = [
    path('admin/', admin.site.urls),
    path('dockerapp1/views/test/', View.as_view())
]
コード例 #16
0
import great_components.views
import demo.views


admin_urls = [
    url(
        r"^thing/$",
        RedirectView.as_view(url='/login/'),
        name='thing'
    ),
]

urlpatterns = [
    url(
        r'^$',
        View.as_view(),
        name='index',
    ),
    url(r'^admin/', include(admin_urls)),
    url(
        r"^robots\.txt$",
        great_components.views.RobotsView.as_view(),
        name='robots'
    ),
    url(
        r'^404/$',
        demo.views.Trigger404View.as_view(),
        name='404',
    ),
    url(
        r'^500/$',
コード例 #17
0
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

from django.views import View

from rest_framework_simplejwt.views import TokenRefreshView


api_auth_urlpatterns = [
    path("social/", include("social.urls", namespace="social")),
    path("", include("rest_auth.urls")),
    path("token/refresh/", TokenRefreshView.as_view(), name="token-refresh"),
]


api_urlpatterns = [
    path("auth/", include((api_auth_urlpatterns, "backend"), namespace="auth")),
]


urlpatterns = [
    path("admin/", admin.site.urls),
    # API urls
    path("", include((api_urlpatterns, "backend-auth"), namespace="api")),
    path("connection_error/", View.as_view(), name="socialaccount_connections"),
    path("", include("django_prometheus.urls")),
]
コード例 #18
0
from django.conf.urls import url
from django.views import View

urlpatterns = [
    url(r'^$', View.as_view(), name="indexpage"),
]