Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
enzofrnt committed Dec 8, 2024
1 parent 8e2130c commit 5339e9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hybridrouter/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
16 changes: 15 additions & 1 deletion hybridrouter/tests/test_hybrid_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion hybridrouter/tests/viewsets.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,3 +12,7 @@ class SlugItemViewSet(ModelViewSet):
queryset = Item.objects.all()
serializer_class = ItemSerializer
lookup_field = "name"


class EmptyViewSet(ViewSet):
pass

0 comments on commit 5339e9e

Please sign in to comment.