diff --git a/hybridrouter/tests/conftest.py b/hybridrouter/tests/conftest.py index 403cb4c..200164b 100644 --- a/hybridrouter/tests/conftest.py +++ b/hybridrouter/tests/conftest.py @@ -34,7 +34,11 @@ def pytest_exception_interact(node, call, report): return urls_list = list_urls(all_urls, prefix="http://localhost/") - urls_text = "\n".join(urls_list) + + if urls_list and isinstance(urls_list, list): + urls_text = "\n".join(urls_list) + else: + urls_text = "Aucune URL disponible." if hasattr(report, "longrepr"): report.longrepr = f"{report.longrepr}\n\nAvailable URLs:\n{urls_text}" diff --git a/hybridrouter/tests/test_hybrid_router.py b/hybridrouter/tests/test_hybrid_router.py index d99d524..ce4642e 100644 --- a/hybridrouter/tests/test_hybrid_router.py +++ b/hybridrouter/tests/test_hybrid_router.py @@ -11,7 +11,7 @@ from .conftest import recevoir_test_url_resolver from .models import Item from .views import ItemView, item_view -from .viewsets import ItemViewSet, SlugItemViewSet +from .viewsets import ItemViewSet, SlugItemViewSet, EmptyViewSet def create_urlconf(router): @@ -602,3 +602,17 @@ def test_no_intermediate_view_with_nested_router(hybrid_router, db): # Les URLs du routeur imbriqué devraient être accessibles response = APIClient().get("/items/subitems/") assert response.status_code == status.HTTP_200_OK + + +def test_get_viewset_urls_with_empty_mapping(hybrid_router, db): + hybrid_router.register("empty", EmptyViewSet, basename="empty") + + urlconf = create_urlconf(hybrid_router) + + with override_settings(ROOT_URLCONF=urlconf): + resolver = get_resolver(urlconf) + recevoir_test_url_resolver(resolver.url_patterns) + + urls = hybrid_router.get_urls() + + assert len(urls) == 0 diff --git a/hybridrouter/tests/viewsets.py b/hybridrouter/tests/viewsets.py index 8d75a2c..7e99750 100644 --- a/hybridrouter/tests/viewsets.py +++ b/hybridrouter/tests/viewsets.py @@ -1,4 +1,4 @@ -from rest_framework.viewsets import ModelViewSet +from rest_framework.viewsets import ModelViewSet, ViewSet from .models import Item from .serializers import ItemSerializer @@ -12,3 +12,7 @@ class SlugItemViewSet(ModelViewSet): queryset = Item.objects.all() serializer_class = ItemSerializer lookup_field = "name" + + +class EmptyViewSet(ViewSet): + pass