From d3954efc9cc15dae5c847f483e0c3bd1585dfb2d Mon Sep 17 00:00:00 2001 From: David Graves Date: Thu, 1 Dec 2022 09:18:19 -0600 Subject: [PATCH] additional basename tests --- tests/test_routers.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/test_routers.py b/tests/test_routers.py index aa7d4ca30..6b006242a 100644 --- a/tests/test_routers.py +++ b/tests/test_routers.py @@ -493,13 +493,12 @@ class TestViewInitkwargs(URLPatternsTestCase, TestCase): assert initkwargs['basename'] == 'routertestmodel' -class TestDuplicateBasename(TestCase): +class BasenameTestCase: def test_conflicting_autogenerated_basenames(self): """ Ensure 2 routers with the same model, and no basename specified throws an ImproperlyConfigured exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet) with pytest.raises(ImproperlyConfigured): @@ -513,7 +512,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with the same model, and no basename specified on 1 throws an ImproperlyConfigured exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet) with pytest.raises(ImproperlyConfigured): @@ -527,7 +525,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with the same model, and a distinct basename specified on the second router does not fail """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet) self.router.register(r'notes_kwduplicate', KWargedNoteViewSet, basename='routertestmodel_kwduplicate') self.router.register(r'notes_duplicate', NoteViewSet, basename='routertestmodel_duplicate') @@ -537,7 +534,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with the same model, and the same basename specified on both throws an ImproperlyConfigured exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet, basename='notes') with pytest.raises(ImproperlyConfigured): @@ -551,7 +547,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with the same model, and a distinct basename specified on each does not throw an exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet, basename='notes') self.router.register(r'notes_kwduplicate', KWargedNoteViewSet, basename='notes_kwduplicate') self.router.register(r'notes_duplicate', NoteViewSet, basename='notes_duplicate') @@ -561,7 +556,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with different models, and a distinct basename specified on each does not throw an exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet, basename='notes') self.router.register(r'notes_basename', BasenameViewSet, basename='notes_basename') @@ -570,7 +564,6 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with different models, and a conflicting basename specified throws an exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet) with pytest.raises(ImproperlyConfigured): self.router.register(r'notes_basename', BasenameViewSet, basename='routertestmodel') @@ -580,6 +573,21 @@ class TestDuplicateBasename(TestCase): Ensure 2 routers with different models, and a distinct basename specified on each does not throw an exception """ - self.router = SimpleRouter(trailing_slash=False) self.router.register(r'notes', NoteViewSet) self.router.register(r'notes_basename', BasenameViewSet) + + +class TestDuplicateBasenameSimpleRouter(BasenameTestCase, TestCase): + def setUp(self): + self.router = SimpleRouter(trailing_slash=False) + + +class TestDuplicateBasenameDefaultRouter(BasenameTestCase, TestCase): + def setUp(self): + self.router = DefaultRouter() + + +class TestDuplicateBasenameDefaultRouterRootViewName(BasenameTestCase, TestCase): + def setUp(self): + self.router = DefaultRouter() + self.router.root_view_name = 'nameable-root'