mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
@@ -20,6 +20,7 @@ from awx.main import migrations
|
|||||||
from awx.main.utils.profiling import AWXProfiler
|
from awx.main.utils.profiling import AWXProfiler
|
||||||
from awx.main.utils.common import memoize
|
from awx.main.utils.common import memoize
|
||||||
from awx.urls import get_urlpatterns
|
from awx.urls import get_urlpatterns
|
||||||
|
from awx.main.utils.named_url_graph import reset_counters
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.middleware')
|
logger = logging.getLogger('awx.main.middleware')
|
||||||
@@ -112,6 +113,7 @@ class URLModificationMiddleware(MiddlewareMixin):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _named_url_to_pk(cls, node, resource, named_url):
|
def _named_url_to_pk(cls, node, resource, named_url):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
reset_counters()
|
||||||
if node.populate_named_url_query_kwargs(kwargs, named_url):
|
if node.populate_named_url_query_kwargs(kwargs, named_url):
|
||||||
match = node.model.objects.filter(**kwargs).first()
|
match = node.model.objects.filter(**kwargs).first()
|
||||||
if match:
|
if match:
|
||||||
|
|||||||
@@ -265,3 +265,14 @@ class TestConvertNamedUrl:
|
|||||||
URLModificationMiddleware._convert_named_url(f'/api/{prefix}v2/organizations/test_org/inventories/')
|
URLModificationMiddleware._convert_named_url(f'/api/{prefix}v2/organizations/test_org/inventories/')
|
||||||
== f'/api/{prefix}v2/organizations/{test_org.pk}/inventories/'
|
== f'/api/{prefix}v2/organizations/{test_org.pk}/inventories/'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_named_job_template(self):
|
||||||
|
org = Organization.objects.create(name='test_org')
|
||||||
|
tpl = JobTemplate.objects.create(name='test_tpl', organization=org)
|
||||||
|
|
||||||
|
# first, cause a '404' - we want to verify that no state from previous requests is carried over when named
|
||||||
|
# urls are resolved
|
||||||
|
assert URLModificationMiddleware._convert_named_url('/api/v2/job_templates/test/tpl++test_org/') == '/api/v2/job_templates/test/tpl++test_org/'
|
||||||
|
|
||||||
|
# try to resolve a valid url - it should succeed
|
||||||
|
assert URLModificationMiddleware._convert_named_url('/api/v2/job_templates/test_tpl++test_org/') == f'/api/v2/job_templates/{tpl.pk}/'
|
||||||
|
|||||||
Reference in New Issue
Block a user