additional basename tests

This commit is contained in:
David Graves 2022-12-01 09:18:19 -06:00
parent 91a74068b3
commit d3954efc9c

View File

@ -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'