Skip to content

Commit d455475

Browse files
author
Emmanouil Konstantinidis
committed
Test docstring
1 parent be05b9d commit d455475

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

rest_framework_docs/api_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
from django.contrib.admindocs.views import simplify_regex
23

34

@@ -24,7 +25,7 @@ def __get_allowed_methods__(self):
2425
return [m.upper() for m in self.callback.cls.http_method_names if hasattr(self.callback.cls, m)]
2526

2627
def __get_docstring__(self):
27-
return self.callback.cls.__doc__
28+
return inspect.getdoc(self.callback)
2829

2930
def __get_serializer_fields__(self):
3031
fields = []

tests/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_index_view_with_endpoints(self):
3333
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
3434
self.assertEqual(response.context["endpoints"][0].allowed_methods, ['POST', 'OPTIONS'])
3535
self.assertEqual(response.context["endpoints"][0].path, "/accounts/login/")
36+
self.assertEqual(response.context["endpoints"][0].docstring, "A view that allows users to login providing their username and password.")
3637
self.assertEqual(len(response.context["endpoints"][0].fields), 2)
3738
self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField")
3839
self.assertTrue(response.context["endpoints"][0].fields[0]["required"])

tests/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class TestView(TemplateView):
2020

2121

2222
class LoginView(APIView):
23+
"""
24+
A view that allows users to login providing their username and password.
25+
"""
2326

2427
throttle_classes = ()
2528
permission_classes = ()
@@ -42,6 +45,9 @@ class UserRegistrationView(generics.CreateAPIView):
4245

4346

4447
class UserProfileView(generics.RetrieveUpdateAPIView):
48+
"""
49+
An endpoint for users to view and update their profile information.
50+
"""
4551

4652
serializer_class = serializers.UserProfileSerializer
4753

0 commit comments

Comments
 (0)