Skip to content

Commit 3e64e0f

Browse files
Merge branch 'master' into support-viewsets
2 parents 82421e5 + 7140f44 commit 3e64e0f

File tree

7 files changed

+72
-18
lines changed

7 files changed

+72
-18
lines changed

Diff for: .travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ env:
1111
- DJANGO_VERSION=1.8
1212
- DJANGO_VERSION=1.9
1313

14+
cache:
15+
- pip
16+
- directories:
17+
- rest_framework_docs/static/node_modules/
18+
19+
before_install:
20+
- nvm install 5
21+
1422
install:
1523
- cd rest_framework_docs/static/ && npm install && cd ../../
1624
- pip install -r requirements.txt

Diff for: codecov.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coverage:
2+
precision: 2
3+
round: down
4+
range: "70...100"
5+
6+
status:
7+
project: false
8+
patch: false
9+
changes: false
10+
11+
comment: off

Diff for: docs/templates.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To hide the GitHub badge from the page, just override it with an empty block.
3636
{% block jumbotron %}
3737
<div class="jumbotron">
3838
<h1>Project Title</h1>
39-
<h3>Documentantion of the project 'Example'.</h3>
39+
<h3>Documentation of the project 'Example'.</h3>
4040
</div>
4141
{% endblock %}
4242

@@ -65,7 +65,7 @@ File location: `templates/rest_framework_docs/docs.html`
6565
{% block jumbotron %}
6666
<div class="jumbotron">
6767
<h1>'Project Name' Web API</h1>
68-
<h3>Documentantion of the 'Project Name' Web API.</h3>
68+
<h3>Documentation of the 'Project Name' Web API.</h3>
6969
</div>
7070
{% endblock %}
7171

Diff for: rest_framework_docs/api_endpoint.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,27 @@ def __get_permissions_class__(self):
4949

5050
def __get_serializer_fields__(self):
5151
fields = []
52+
serializer = None
5253

53-
if hasattr(self.callback.cls, 'serializer_class') and hasattr(self.callback.cls.serializer_class, 'get_fields'):
54+
if hasattr(self.callback.cls, 'serializer_class'):
5455
serializer = self.callback.cls.serializer_class
55-
if hasattr(serializer, 'get_fields'):
56-
try:
57-
fields = [{
58-
"name": key,
59-
"type": str(field.__class__.__name__),
60-
"required": field.required
61-
} for key, field in serializer().get_fields().items()]
62-
except KeyError as e:
63-
self.errors = e
64-
fields = []
65-
66-
# FIXME:
67-
# Show more attibutes of `field`?
56+
57+
elif hasattr(self.callback.cls, 'get_serializer_class'):
58+
serializer = self.callback.cls.get_serializer_class(self.pattern.callback.cls())
59+
60+
if hasattr(serializer, 'get_fields'):
61+
try:
62+
fields = [{
63+
"name": key,
64+
"type": str(field.__class__.__name__),
65+
"required": field.required
66+
} for key, field in serializer().get_fields().items()]
67+
except KeyError as e:
68+
self.errors = e
69+
fields = []
70+
71+
# FIXME:
72+
# Show more attibutes of `field`?
6873

6974
return fields
7075

Diff for: tests/tests.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_index_view_with_endpoints(self):
2727
response = self.client.get(reverse('drfdocs'))
2828

2929
self.assertEqual(response.status_code, 200)
30-
self.assertEqual(len(response.context["endpoints"]), 10)
30+
self.assertEqual(len(response.context["endpoints"]), 11)
3131

3232
# Test the login view
3333
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
@@ -38,8 +38,16 @@ def test_index_view_with_endpoints(self):
3838
self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField")
3939
self.assertTrue(response.context["endpoints"][0].fields[0]["required"])
4040

41+
self.assertEqual(response.context["endpoints"][1].name_parent, "accounts")
42+
self.assertEqual(response.context["endpoints"][1].allowed_methods, ['POST', 'OPTIONS'])
43+
self.assertEqual(response.context["endpoints"][1].path, "/accounts/login2/")
44+
self.assertEqual(response.context["endpoints"][1].docstring, "A view that allows users to login providing their username and password. Without serializer_class")
45+
self.assertEqual(len(response.context["endpoints"][1].fields), 2)
46+
self.assertEqual(response.context["endpoints"][1].fields[0]["type"], "CharField")
47+
self.assertTrue(response.context["endpoints"][1].fields[0]["required"])
48+
4149
# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
42-
self.assertEqual(str(response.context["endpoints"][8].errors), "'test_value'")
50+
self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'")
4351

4452
def test_index_search_with_endpoints(self):
4553
response = self.client.get("%s?search=reset-password" % reverse("drfdocs"))

Diff for: tests/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
accounts_urls = [
88
url(r'^login/$', views.LoginView.as_view(), name="login"),
9+
url(r'^login2/$', views.LoginWithSerilaizerClassView.as_view(), name="login2"),
910
url(r'^register/$', views.UserRegistrationView.as_view(), name="register"),
1011
url(r'^reset-password/$', view=views.PasswordResetView.as_view(), name="reset-password"),
1112
url(r'^reset-password/confirm/$', views.PasswordResetConfirmView.as_view(), name="reset-password-confirm"),

Diff for: tests/views.py

+21
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,24 @@ def delete(self, request, *args, **kwargs):
111111
class OrganisationErroredView(generics.ListAPIView):
112112

113113
serializer_class = serializers.OrganisationErroredSerializer
114+
115+
116+
class LoginWithSerilaizerClassView(APIView):
117+
"""
118+
A view that allows users to login providing their username and password. Without serializer_class
119+
"""
120+
121+
throttle_classes = ()
122+
permission_classes = ()
123+
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
124+
renderer_classes = (renderers.JSONRenderer,)
125+
126+
def post(self, request):
127+
serializer = self.serializer_class(data=request.data)
128+
serializer.is_valid(raise_exception=True)
129+
user = serializer.validated_data['user']
130+
token, created = Token.objects.get_or_create(user=user)
131+
return Response({'token': token.key})
132+
133+
def get_serializer_class(self):
134+
return AuthTokenSerializer

0 commit comments

Comments
 (0)