mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 16:10:50 +03:00
Add test for PUT with session auth+csrf
This commit is contained in:
parent
7a87fc87c2
commit
a99a449c88
|
@ -1,11 +1,9 @@
|
||||||
from django.conf.urls.defaults import patterns
|
from django.conf.urls.defaults import patterns
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth import login
|
|
||||||
from django.test import Client, TestCase
|
from django.test import Client, TestCase
|
||||||
|
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
|
|
||||||
from djangorestframework.compat import RequestFactory
|
|
||||||
from djangorestframework.views import View
|
from djangorestframework.views import View
|
||||||
from djangorestframework import permissions
|
from djangorestframework import permissions
|
||||||
|
|
||||||
|
@ -14,8 +12,12 @@ import base64
|
||||||
|
|
||||||
class MockView(View):
|
class MockView(View):
|
||||||
permissions = ( permissions.IsAuthenticated, )
|
permissions = ( permissions.IsAuthenticated, )
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
return {'a':1, 'b':2, 'c':3}
|
return {'a': 1, 'b': 2, 'c': 3}
|
||||||
|
|
||||||
|
def put(self, request):
|
||||||
|
return {'a': 1, 'b': 2, 'c': 3}
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^$', MockView.as_view()),
|
(r'^$', MockView.as_view()),
|
||||||
|
@ -83,8 +85,13 @@ class SessionAuthTests(TestCase):
|
||||||
response = self.non_csrf_client.post('/', {'example': 'example'})
|
response = self.non_csrf_client.post('/', {'example': 'example'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_put_form_session_auth_passing(self):
|
||||||
|
"""Ensure PUTting form over session authentication with logged in user and CSRF token passes."""
|
||||||
|
self.non_csrf_client.login(username=self.username, password=self.password)
|
||||||
|
response = self.non_csrf_client.put('/', {'example': 'example'})
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_post_form_session_auth_failing(self):
|
def test_post_form_session_auth_failing(self):
|
||||||
"""Ensure POSTing form over session authentication without logged in user fails."""
|
"""Ensure POSTing form over session authentication without logged in user fails."""
|
||||||
response = self.csrf_client.post('/', {'example': 'example'})
|
response = self.csrf_client.post('/', {'example': 'example'})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user