def setUp(self):
        super(AdminTestManager, self).setUp()

        if not hasattr(self, 'site'):
            return

        # Try to clear the resolver cache
        if django.VERSION < (1, 7):
            # Django 1.4 - 1.6
            from django.core.urlresolvers import _resolver_cache
            _resolver_cache.clear()
        else:
            if django.VERSION < (1, 10):
                from django.core.urlresolvers import get_resolver
            else:
                from django.urls import get_resolver
            if hasattr(get_resolver, 'cache_clear'):
                get_resolver.cache_clear()

        # Store the old urls and make a copy
        self.old_urls = test_urls.urlpatterns
        test_urls.urlpatterns = copy.copy(test_urls.urlpatterns)

        # Add the site to the copy
        from django.conf.urls import include, url

        def safe_include(urls):
            if django.VERSION < (1, 9):
                return include(urls)
            return urls

        test_urls.urlpatterns += test_urls.mk_urlpatterns(
            url(r'^tagulous_tests_app/admin/', safe_include(self.site.urls)))
Ejemplo n.º 2
0
    def setUp(self):
        super(AdminTestManager, self).setUp()

        if not hasattr(self, 'site'):
            return

        # Try to clear the resolver cache
        if django.VERSION < (1, 7):
            # Django 1.4 - 1.6
            from django.core.urlresolvers import _resolver_cache
            _resolver_cache.clear()
        else:
            if django.VERSION < (1, 10):
                from django.core.urlresolvers import get_resolver
            else:
                from django.urls import get_resolver
            if hasattr(get_resolver, 'cache_clear'):
                get_resolver.cache_clear()

        # Store the old urls and make a copy
        self.old_urls = test_urls.urlpatterns
        test_urls.urlpatterns = copy.copy(
            test_urls.urlpatterns
        )

        # Add the site to the copy
        from django.conf.urls import include, url
        def safe_include(urls):
            if django.VERSION < (1, 9):
                return include(urls)
            return urls

        test_urls.urlpatterns += test_urls.mk_urlpatterns(
            url(r'^tagulous_tests_app/admin/', safe_include(self.site.urls))
        )
Ejemplo n.º 3
0
def patch_root_urlconf():
    try:
        reverse('djdt:render_panel')
    except NoReverseMatch:
        urlconf_module = import_module(settings.ROOT_URLCONF)
        urlconf_module.urlpatterns += patterns('',                      # noqa
            url(r'^__debug__/', include(debug_toolbar.urls)),
        )
        _resolver_cache.clear()
        _ns_resolver_cache.clear()
Ejemplo n.º 4
0
    def __getattr__(self, name):
        try:
            plugin_patterns = PLUGIN_URLS_SYNC_DICT["plugin_patterns"]
        except KeyError:
            # First time started or django-tools local sync cache was cleared
            # in this thread or in a other thread.

            log.debug("Clear django.core.urlresolvers cache")
            _resolver_cache.clear()  # Maps URLconf modules to RegexURLResolver instances.
            _ns_resolver_cache.clear()  # Maps namespaces to RegexURLResolver instances.
            _callable_cache.clear()  # Maps view and url pattern names to their view functions.

            # get the plugin url patterns fresh
            plugin_patterns = self._get_plugin_patterns()
            PLUGIN_URLS_SYNC_DICT["plugin_patterns"] = plugin_patterns

        return getattr(plugin_patterns, name)
Ejemplo n.º 5
0
    def test_all_urls_accounted_for(self):
        """
        Ensure all URLs that have not been explicitly excluded are present in
        self.covered_urls.
        """

        _resolver_cache.clear()
        seen_patterns = set()

        patterns = get_urlpatterns()

        original_resolve = RegexURLPattern.resolve

        def resolve_and_make_note(self, url, *args, **kwargs):
            match = original_resolve(self, url, *args, **kwargs)

            if match:
                seen_patterns.add(self)

            return match

        with patch('django.core.urlresolvers.RegexURLPattern.resolve',
                   resolve_and_make_note):
            for url in self.covered_urls + self.uncovered_urls:
                resolve(url.split('?')[0])

        all_patterns = extract_all_patterns_from_urlpatterns(
            patterns, self.uncovered_includes)

        not_accounted_for = [p for p in all_patterns
                             if p[1] not in seen_patterns]

        if not_accounted_for:
            raise self.failureException(
                'The following views are untested:\n\n{0}\n\n{1}'.format(
                    '\n'.join([
                        '{base} {_regex} ({name})'.format(
                            base=base, **pattern.__dict__
                        ) for base, pattern in not_accounted_for
                    ]),
                    IGNORE_TUTORIAL.format(name=self.__class__.__name__),
                )
            )
Ejemplo n.º 6
0
    def __getattr__(self, name):
        try:
            plugin_patterns = PLUGIN_URLS_SYNC_DICT["plugin_patterns"]
        except KeyError:
            # First time started or django-tools local sync cache was cleared
            # in this thread or in a other thread.

            log.debug("Clear django.core.urlresolvers cache")
            _resolver_cache.clear(
            )  # Maps URLconf modules to RegexURLResolver instances.
            _ns_resolver_cache.clear(
            )  # Maps namespaces to RegexURLResolver instances.
            _callable_cache.clear(
            )  # Maps view and url pattern names to their view functions.

            # get the plugin url patterns fresh
            plugin_patterns = self._get_plugin_patterns()
            PLUGIN_URLS_SYNC_DICT["plugin_patterns"] = plugin_patterns

        return getattr(plugin_patterns, name)
Ejemplo n.º 7
0
 def clear_url_caches():
     _resolver_cache.clear()
Ejemplo n.º 8
0
 def clear_url_caches():  # type: () -> None
     _resolver_cache.clear()