From 9e0d60a68f2ea5b0cb26269d411735461c3b2403 Mon Sep 17 00:00:00 2001 From: Emad Mokhtar Date: Sun, 22 May 2016 11:40:00 +0300 Subject: [PATCH 1/9] Fix typo in documentation --- docs/templates.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/templates.md b/docs/templates.md index 30391e2..1702337 100755 --- a/docs/templates.md +++ b/docs/templates.md @@ -36,7 +36,7 @@ To hide the GitHub badge from the page, just override it with an empty block. {% block jumbotron %}

Project Title

-

Documentantion of the project 'Example'.

+

Documentation of the project 'Example'.

{% endblock %} @@ -65,7 +65,7 @@ File location: `templates/rest_framework_docs/docs.html` {% block jumbotron %}

'Project Name' Web API

-

Documentantion of the 'Project Name' Web API.

+

Documentation of the 'Project Name' Web API.

{% endblock %} From d1c843e0a66dda5ed79f0eb68d37d6e76ebe26ec Mon Sep 17 00:00:00 2001 From: Emad Mokhtar Date: Sun, 22 May 2016 14:14:18 +0300 Subject: [PATCH 2/9] Use get_serializer_class for Views without serlaizer_class attribute --- rest_framework_docs/api_endpoint.py | 33 +++++++++++++++++------------ tests/tests.py | 12 +++++++++-- tests/urls.py | 1 + tests/views.py | 21 ++++++++++++++++++ 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/rest_framework_docs/api_endpoint.py b/rest_framework_docs/api_endpoint.py index f37155c..526543a 100644 --- a/rest_framework_docs/api_endpoint.py +++ b/rest_framework_docs/api_endpoint.py @@ -37,22 +37,27 @@ def __get_permissions_class__(self): def __get_serializer_fields__(self): fields = [] + serializer = None - if hasattr(self.callback.cls, 'serializer_class') and hasattr(self.callback.cls.serializer_class, 'get_fields'): + if hasattr(self.callback.cls, 'serializer_class'): serializer = self.callback.cls.serializer_class - if hasattr(serializer, 'get_fields'): - try: - fields = [{ - "name": key, - "type": str(field.__class__.__name__), - "required": field.required - } for key, field in serializer().get_fields().items()] - except KeyError as e: - self.errors = e - fields = [] - - # FIXME: - # Show more attibutes of `field`? + + elif hasattr(self.callback.cls, 'get_serializer_class'): + serializer = self.callback.cls.get_serializer_class(self.callback.cls) + + if hasattr(serializer, 'get_fields'): + try: + fields = [{ + "name": key, + "type": str(field.__class__.__name__), + "required": field.required + } for key, field in serializer().get_fields().items()] + except KeyError as e: + self.errors = e + fields = [] + + # FIXME: + # Show more attibutes of `field`? return fields diff --git a/tests/tests.py b/tests/tests.py index afb58d0..57028b7 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -27,7 +27,7 @@ def test_index_view_with_endpoints(self): response = self.client.get(reverse('drfdocs')) self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.context["endpoints"]), 10) + self.assertEqual(len(response.context["endpoints"]), 11) # Test the login view self.assertEqual(response.context["endpoints"][0].name_parent, "accounts") @@ -38,8 +38,16 @@ def test_index_view_with_endpoints(self): self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField") self.assertTrue(response.context["endpoints"][0].fields[0]["required"]) + self.assertEqual(response.context["endpoints"][1].name_parent, "accounts") + self.assertEqual(response.context["endpoints"][1].allowed_methods, ['POST', 'OPTIONS']) + self.assertEqual(response.context["endpoints"][1].path, "/accounts/login2/") + self.assertEqual(response.context["endpoints"][1].docstring, "A view that allows users to login providing their username and password. Without serializer_class") + self.assertEqual(len(response.context["endpoints"][1].fields), 2) + self.assertEqual(response.context["endpoints"][1].fields[0]["type"], "CharField") + self.assertTrue(response.context["endpoints"][1].fields[0]["required"]) + # The view "OrganisationErroredView" (organisations/(?P[\w-]+)/errored/) should contain an error. - self.assertEqual(str(response.context["endpoints"][8].errors), "'test_value'") + self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'") def test_index_search_with_endpoints(self): response = self.client.get("%s?search=reset-password" % reverse("drfdocs")) diff --git a/tests/urls.py b/tests/urls.py index b226620..092973c 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -6,6 +6,7 @@ accounts_urls = [ url(r'^login/$', views.LoginView.as_view(), name="login"), + url(r'^login2/$', views.LoginWithSerilaizerClassView.as_view(), name="login2"), url(r'^register/$', views.UserRegistrationView.as_view(), name="register"), url(r'^reset-password/$', view=views.PasswordResetView.as_view(), name="reset-password"), url(r'^reset-password/confirm/$', views.PasswordResetConfirmView.as_view(), name="reset-password-confirm"), diff --git a/tests/views.py b/tests/views.py index c6987d0..64e0bec 100644 --- a/tests/views.py +++ b/tests/views.py @@ -111,3 +111,24 @@ def delete(self, request, *args, **kwargs): class OrganisationErroredView(generics.ListAPIView): serializer_class = serializers.OrganisationErroredSerializer + + +class LoginWithSerilaizerClassView(APIView): + """ + A view that allows users to login providing their username and password. Without serializer_class + """ + + throttle_classes = () + permission_classes = () + parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,) + renderer_classes = (renderers.JSONRenderer,) + + def post(self, request): + serializer = self.serializer_class(data=request.data) + serializer.is_valid(raise_exception=True) + user = serializer.validated_data['user'] + token, created = Token.objects.get_or_create(user=user) + return Response({'token': token.key}) + + def get_serializer_class(self): + return AuthTokenSerializer From 28fece65793661dfdb1c059cf8564bfb7b2a4c47 Mon Sep 17 00:00:00 2001 From: Emad Mokhtar Date: Wed, 25 May 2016 14:11:52 +0300 Subject: [PATCH 3/9] Fix the issue with Python 2.7 --- rest_framework_docs/api_endpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_docs/api_endpoint.py b/rest_framework_docs/api_endpoint.py index 526543a..8eb07c9 100644 --- a/rest_framework_docs/api_endpoint.py +++ b/rest_framework_docs/api_endpoint.py @@ -43,7 +43,7 @@ def __get_serializer_fields__(self): serializer = self.callback.cls.serializer_class elif hasattr(self.callback.cls, 'get_serializer_class'): - serializer = self.callback.cls.get_serializer_class(self.callback.cls) + serializer = self.callback.cls.get_serializer_class(self.pattern.callback.cls()) if hasattr(serializer, 'get_fields'): try: From d3993fa09ec6dbec0031c870b25e61ddc3bb5668 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Wed, 25 May 2016 23:40:27 +0100 Subject: [PATCH 4/9] Travis - Specify Node Version --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index ad912f0..a0ba61b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ env: - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 +node_js: + - "5" + install: - cd rest_framework_docs/static/ && npm install && cd ../../ - pip install -r requirements.txt From 9677d9cf54c829152d1ba4d8ad204fce30a68226 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Wed, 25 May 2016 23:45:25 +0100 Subject: [PATCH 5/9] Use nvm --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0ba61b..1028d74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ env: - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 -node_js: - - "5" +before_install: + - nvm install 5 install: - cd rest_framework_docs/static/ && npm install && cd ../../ From 3b2c00474e088abaaa364453a8e7e27648d1c4f2 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Wed, 25 May 2016 23:56:20 +0100 Subject: [PATCH 6/9] Travis Cache --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1028d74..8a61d83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,11 @@ env: - DJANGO_VERSION=1.8 - DJANGO_VERSION=1.9 +cache: + - pip + - directories: + - rest_framework_docs/static/node_modules/ + before_install: - nvm install 5 From 205f096af2206a9e3f5476024df1b7224554b0b0 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Thu, 26 May 2016 00:00:13 +0100 Subject: [PATCH 7/9] Codecov Settings --- codecov.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..4106c3e --- /dev/null +++ b/codecov.yml @@ -0,0 +1,11 @@ +coverage: + precision: 2 + round: down + range: "70...100" + + status: + project: false + patch: false + changes: false + +comment: off From cf0d3c4bae505b6f8e1899b665d2cc591d16db64 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Thu, 26 May 2016 20:28:36 +0100 Subject: [PATCH 8/9] Bump 0.0.10 --- rest_framework_docs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_docs/__init__.py b/rest_framework_docs/__init__.py index 9d1ffab..6820f36 100644 --- a/rest_framework_docs/__init__.py +++ b/rest_framework_docs/__init__.py @@ -1 +1 @@ -__version__ = '0.0.9' +__version__ = '0.0.10' From 7f7aa777382d9dbde1846786088c402b398fc203 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Thu, 26 May 2016 20:31:00 +0100 Subject: [PATCH 9/9] Release notes --- docs/changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index d98f5c4..c3ba453 100755 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -3,6 +3,11 @@ title: "Changelog" source_filename: "changelog" --- +### Release 0.0.10 + + - Use get_serializer_class for Views without serlaizer_class attribute [#92](https://github.com/ekonstantinidis/django-rest-framework-docs/pull/92) + + ### Release 0.0.9 - Support for more types of `ROOT_URLCONF`