mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 04:31:21 -03:30
Django's url resolver and pattern classes have been renamed in 2.0+
They are now URLResolver and URLPattern, respectively. The API has changed as well, but fortunately it looks like what we are doing here doesn't depend on anything that was changed.
This commit is contained in:
parent
25c14382db
commit
f24b08316d
@ -6,7 +6,7 @@ from unittest.mock import PropertyMock
|
||||
from awx.api.urls import urlpatterns as api_patterns
|
||||
|
||||
# Django
|
||||
from django.urls import RegexURLResolver, RegexURLPattern
|
||||
from django.urls import URLResolver, URLPattern
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -20,24 +20,24 @@ def all_views():
|
||||
'''
|
||||
returns a set of all views in the app
|
||||
'''
|
||||
patterns = set([])
|
||||
url_views = set([])
|
||||
patterns = set()
|
||||
url_views = set()
|
||||
# Add recursive URL patterns
|
||||
unprocessed = set(api_patterns)
|
||||
while unprocessed:
|
||||
to_process = unprocessed.copy()
|
||||
unprocessed = set([])
|
||||
unprocessed = set()
|
||||
for pattern in to_process:
|
||||
if hasattr(pattern, 'lookup_str') and not pattern.lookup_str.startswith('awx.api'):
|
||||
continue
|
||||
patterns.add(pattern)
|
||||
if isinstance(pattern, RegexURLResolver):
|
||||
if isinstance(pattern, URLResolver):
|
||||
for sub_pattern in pattern.url_patterns:
|
||||
if sub_pattern not in patterns:
|
||||
unprocessed.add(sub_pattern)
|
||||
# Get view classes
|
||||
for pattern in patterns:
|
||||
if isinstance(pattern, RegexURLPattern) and hasattr(pattern.callback, 'view_class'):
|
||||
if isinstance(pattern, URLPattern) and hasattr(pattern.callback, 'view_class'):
|
||||
url_views.add(pattern.callback.view_class)
|
||||
return url_views
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user