authentik.lib.tests.test_urls_hot
Test hot URL ordering
1"""Test hot URL ordering""" 2 3from django.test import SimpleTestCase 4from django.urls import include, path, resolve, reverse 5from django.views import View 6 7from authentik.api.v3.urls import urlpatterns 8from authentik.flows.views.executor import FlowExecutorView 9from authentik.lib.utils.urls import hot_path, sort_hot 10 11 12class TestURLs(SimpleTestCase): 13 """Test hot URL ordering""" 14 15 def test_hot_sorted_first(self): 16 """Hot patterns come before all other patterns and still resolve""" 17 hot = [isinstance(pattern, hot_path) for pattern in urlpatterns] 18 self.assertTrue(hot[0]) 19 self.assertEqual(hot, sorted(hot, reverse=True)) 20 match = resolve(reverse("authentik_api:flow-executor", kwargs={"flow_slug": "foo"})) 21 self.assertEqual(match.func.view_class, FlowExecutorView) 22 23 def test_hot_include(self): 24 """Includes containing a hot pattern are sorted before other patterns""" 25 cold = path("a/", View.as_view()) 26 cold_include = path("b/", include([path("c/", View.as_view())])) 27 hot_include = path("", include([hot_path("d/", View.as_view())])) 28 self.assertEqual( 29 sort_hot([cold, cold_include, hot_include]), [hot_include, cold, cold_include] 30 )
class
TestURLs(django.test.testcases.SimpleTestCase):
13class TestURLs(SimpleTestCase): 14 """Test hot URL ordering""" 15 16 def test_hot_sorted_first(self): 17 """Hot patterns come before all other patterns and still resolve""" 18 hot = [isinstance(pattern, hot_path) for pattern in urlpatterns] 19 self.assertTrue(hot[0]) 20 self.assertEqual(hot, sorted(hot, reverse=True)) 21 match = resolve(reverse("authentik_api:flow-executor", kwargs={"flow_slug": "foo"})) 22 self.assertEqual(match.func.view_class, FlowExecutorView) 23 24 def test_hot_include(self): 25 """Includes containing a hot pattern are sorted before other patterns""" 26 cold = path("a/", View.as_view()) 27 cold_include = path("b/", include([path("c/", View.as_view())])) 28 hot_include = path("", include([hot_path("d/", View.as_view())])) 29 self.assertEqual( 30 sort_hot([cold, cold_include, hot_include]), [hot_include, cold, cold_include] 31 )
Test hot URL ordering
def
test_hot_sorted_first(self):
16 def test_hot_sorted_first(self): 17 """Hot patterns come before all other patterns and still resolve""" 18 hot = [isinstance(pattern, hot_path) for pattern in urlpatterns] 19 self.assertTrue(hot[0]) 20 self.assertEqual(hot, sorted(hot, reverse=True)) 21 match = resolve(reverse("authentik_api:flow-executor", kwargs={"flow_slug": "foo"})) 22 self.assertEqual(match.func.view_class, FlowExecutorView)
Hot patterns come before all other patterns and still resolve
def
test_hot_include(self):
24 def test_hot_include(self): 25 """Includes containing a hot pattern are sorted before other patterns""" 26 cold = path("a/", View.as_view()) 27 cold_include = path("b/", include([path("c/", View.as_view())])) 28 hot_include = path("", include([hot_path("d/", View.as_view())])) 29 self.assertEqual( 30 sort_hot([cold, cold_include, hot_include]), [hot_include, cold, cold_include] 31 )
Includes containing a hot pattern are sorted before other patterns