Пример #1
0
    def process_request(request):

        resolver = URLResolver(RegexPattern(r'^/'), settings.ROOT_URLCONF)
        try:
            callback, callback_args, callback_kwargs = resolver.resolve(
                request.path)
            return callback(request, *callback_args, **callback_kwargs)
        except Resolver404 as e:
            pass
        except Http404 as e:
            return HttpResponseNotFound(str(e))

        return get_response(request)
Пример #2
0
def get_filtered_apps(resolve_url="/", no_args=True, debug=False, skip_fail=False):
    """
    Filter settings.INSTALLED_APPS and create a list
    of all Apps witch can resolve the given url >resolve_url<

    @param resolve_url: url used for RegexURLResolver
    @param no_args: Only views without args/kwargs ?
    @parm skip_fail: If True: raise exception if app is not importable

    Please look at:

        django_tools.django_tools_tests.test_installed_apps_utils

    with debug, some print messages would be created:

    e.g.: get_filtered_apps(debug=True)
    found 'django.contrib.admindocs' with urls.py
    found 'django.contrib.auth' with urls.py
    Skip 'django.contrib.auth': Can't handle root url.
    found 'django.contrib.flatpages' with urls.py
    ['django.contrib.admindocs']
    """
    root_apps = []
    for app_label in settings.INSTALLED_APPS:
        urls_pkg = f"{app_label}.urls"
        try:
            url_mod = import_module(urls_pkg)
        except ImportError as err:
            if debug:
                print(f"Skip {app_label!r}: has no urls.py")
            if str(err) == f"No module named '{urls_pkg}'":
                continue
            if not skip_fail:
                raise
        except Exception as err:
            if debug:
                print(f"Error importing {app_label!r}: {err}")
            if not skip_fail:
                raise
            else:
                continue

        if debug:
            print(f"found {app_label!r} with urls.py")

        try:
            urlpatterns = url_mod.urlpatterns
        except AttributeError:
            if debug:
                print(f"Skip {app_label!r}: urls.py has no 'urlpatterns'")
            continue

        resolver = URLResolver(RegexPattern(r'^'), urlpatterns)
        try:
            func, func_args, func_kwargs = resolver.resolve(resolve_url)
        except Resolver404 as err:
            if debug:
                print(f"Skip {app_label!r}: Can't handle root url. ({err})")
            continue
        if not no_args or func_args == () and func_kwargs == {}:
            root_apps.append(app_label)
    return root_apps
Пример #3
0
 def test_access_group_in_tenant(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/tenants/1/notification-groups/')
     self.assertEqual(resolve.func.__name__, "NotificationGroupViewSet")
Пример #4
0
 def test_access_index(self):
     url_resolver = URLResolver(RegexPattern(''), "backend.urls")
     resolve = url_resolver.resolve('/')
     self.assertEqual(resolve.func.__name__, "HomePageView")
Пример #5
0
 def test_access_monitors_in_resources_in_awsenvs_in_tenant(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve(
         'api/tenants/1/aws-environments/1/regions/ap-northeast-1/services/ec2/resources/i-123456789/monitors/'
     )
     self.assertEqual(resolve.func.__name__, "MonitorViewSet")
Пример #6
0
 def test_access_instances_in_awsenvs_in_tenant(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve(
         'api/tenants/1/aws-environments/1/resources/')
     self.assertEqual(resolve.func.__name__, "ResourceViewSet")
Пример #7
0
 def test_access_users_in_tenant(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/tenants/1/users/')
     self.assertEqual(resolve.func.__name__, "UserModeViewSet")
Пример #8
0
 def test_access_tenants(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/tenants/')
     self.assertEqual(resolve.func.__name__, "TenantModelViewSet")
Пример #9
0
 def test_access_event(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/event/')
     self.assertEqual(resolve.func.__name__, "event_execute")
Пример #10
0
 def test_access_notify(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/notify/')
     self.assertEqual(resolve.func.__name__, "notify")
Пример #11
0
 def test_access_reset_password(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/auth/reset/')
     self.assertEqual(resolve.func.__name__, "reset_password")
Пример #12
0
 def test_access_auth_refresh(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/auth/refresh/')
     self.assertEqual(resolve.func.__name__, "RefreshJSONWebToken")
Пример #13
0
 def test_access_logs_in_tenant(self):
     url_resolver = URLResolver(RegexPattern(''), "config.urls")
     resolve = url_resolver.resolve('api/tenants/1/logs/')
     self.assertEqual(resolve.func.__name__, "OperationLogModelViewSet")
 def resolve(self, path, pattern):
     url_resolver = URLResolver(RegexPattern(r'^/'), urlconf_name=[pattern])
     return url_resolver.resolve(path)