Skip to content

Commit

Permalink
32 - Django Rest Framework JWT & Curl Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Apr 29, 2016
1 parent d9f953f commit d9636f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/blog/curl_tests.py
@@ -0,0 +1,28 @@

'''
curl -X POST -d "username=cfe&password=learncode" http://127.0.0.1:8000/api/auth/token/
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY1ODI5fQ.OTX7CZFZqxhaUnU9Da13Ebh9FY_bHMeCF1ypr9hXjWw
curl -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY1ODI5fQ.OTX7CZFZqxhaUnU9Da13Ebh9FY_bHMeCF1ypr9hXjWw
" http://127.0.0.1:8000/api/comments/
curl -X POST -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY2MTc4fQ._i5wEqJ_OO8wNiVVNAWNPGjGaO7OzChY0UzONgw06D0" -H "Content-Type: application/json" -d '{"content":"some reply to another try"}' 'http://127.0.0.1:8000/api/comments/create/?slug=new-title&type=post&parent_id=13'
curl http://127.0.0.1:8000/api/comments/
curl -X POST -d "username=anotheruser123&password=anotheruser123" http://127.0.0.1:8000/api/auth/token/
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFub3RoZXJ1c2VyMTIzIiwidXNlcl9pZCI6NywiZW1haWwiOiJhbm90aGVydXNlcjEyM0BnbWFpbC5jb20iLCJleHAiOjE0NjE5NjY0ODF9.KZ991-PGIm63BKikMbDSdFStStJ6uu6WtsraAmbo7BQ
curl -X POST -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFub3RoZXJ1c2VyMTIzIiwidXNlcl9pZCI6NywiZW1haWwiOiJhbm90aGVydXNlcjEyM0BnbWFpbC5jb20iLCJleHAiOjE0NjE5NjY0ODF9.KZ991-PGIm63BKikMbDSdFStStJ6uu6WtsraAmbo7BQ" -H "Content-Type: application/json" -d '{"content":"my new reply to another try"}' 'http://127.0.0.1:8000/api/comments/create/?slug=new-title&type=post&parent_id=13'
'''
22 changes: 20 additions & 2 deletions src/blog/settings.py
Expand Up @@ -157,16 +157,34 @@
# 'rest_framework.parsers.JSONParser',
# )
"DEFAULT_AUTHENTICATION_CLASSES": (
'rest_framework.authentication.SessionAuthentication',
#'rest_framework.authentication.SessionAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
#'rest_framework.authentication.BasicAuthentication'

),
"DEFAULT_PERMISSION_CLASSES": (
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
'rest_framework.permissions.IsAuthenticated',
#'rest_framework.permissions.IsAuthenticatedOrReadOnly',
)
}


'''
curl -X POST -d "username=cfe&password=learncode" http://127.0.0.1:8000/api/auth/token/
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY1ODI5fQ.OTX7CZFZqxhaUnU9Da13Ebh9FY_bHMeCF1ypr9hXjWw
curl -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY1ODI5fQ.OTX7CZFZqxhaUnU9Da13Ebh9FY_bHMeCF1ypr9hXjWw
" http://127.0.0.1:8000/api/comments/
curl -X POST -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNmZSIsInVzZXJfaWQiOjEsImVtYWlsIjoiIiwiZXhwIjoxNDYxOTY2MTc4fQ._i5wEqJ_OO8wNiVVNAWNPGjGaO7OzChY0UzONgw06D0" -H "Content-Type: application/json" -d '{"content":"some reply to another try"}' 'http://127.0.0.1:8000/api/comments/create/?slug=new-title&type=post&parent_id=13'
curl http://127.0.0.1:8000/api/comments/
'''



Expand Down
4 changes: 4 additions & 0 deletions src/blog/urls.py
Expand Up @@ -19,6 +19,9 @@
from django.conf.urls.static import static
from django.contrib import admin


from rest_framework_jwt.views import obtain_jwt_token

from accounts.views import (login_view, register_view, logout_view)

urlpatterns = [
Expand All @@ -30,6 +33,7 @@
url(r'^login/', login_view, name='login'),
url(r'^logout/', logout_view, name='logout'),
url(r'^', include("posts.urls", namespace='posts')),
url(r'^api/auth/token/', obtain_jwt_token),
url(r'^api/users/', include("accounts.api.urls", namespace='users-api')),
url(r'^api/comments/', include("comments.api.urls", namespace='comments-api')),
url(r'^api/posts/', include("posts.api.urls", namespace='posts-api')),
Expand Down
Binary file modified src/db.sqlite3
Binary file not shown.

0 comments on commit d9636f5

Please sign in to comment.