failed to test ViewSet reverse getting route name in Django Rest Framework
urls.py:
-sharp course chapter without lesson
course_chapter_router = DefaultRouter()
course_chapter_router.register(r"", courses.views.CourseChapterViewSet,
base_name="chapters")
-sharp URL Patterns
urlpatterns = [
-sharp course courses
url(r"^chapters/", include(course_chapter_router.urls)),
]
class GetAllChapterTest(TestCase):
def test_get_all_multi(self):
request = APIRequestFactory().get(reverse("chapters:chapters-list"))
print(request)
view = ChapterViewSet.as_view({"get": "retrieve"})
course = Course.objects.create(course_code="xadf", title="Python", brief="a dynamic langiage", description="similar to Java, C")
chapter = Chapter.objects.create(course=course, number=2, title="", description="Code Language")
print(chapter)
-sharpcourse = Course.objects.create(course_code="xadf", title="Python", brief="a dynamic langiage", description="similar to Java, C")
response = view(request, pk=chapter.pk)
print(response)