aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests
diff options
context:
space:
mode:
authorTom Christie2012-01-11 17:22:56 +0000
committerTom Christie2012-01-21 17:47:33 +0000
commita99a449c8844e6f55f9a1ecb341701f2719117df (patch)
tree6fdd4b8609841d0dad24146762b4f222d0becaf2 /djangorestframework/tests
parent7a87fc87c2eb43509fa6d037c88707aaff7c9b2a (diff)
downloaddjango-rest-framework-a99a449c8844e6f55f9a1ecb341701f2719117df.tar.bz2
Add test for PUT with session auth+csrf
Diffstat (limited to 'djangorestframework/tests')
-rw-r--r--djangorestframework/tests/authentication.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/djangorestframework/tests/authentication.py b/djangorestframework/tests/authentication.py
index e6da4217..1835c523 100644
--- a/djangorestframework/tests/authentication.py
+++ b/djangorestframework/tests/authentication.py
@@ -1,11 +1,9 @@
from django.conf.urls.defaults import patterns
from django.contrib.auth.models import User
-from django.contrib.auth import login
from django.test import Client, TestCase
from django.utils import simplejson as json
-from djangorestframework.compat import RequestFactory
from djangorestframework.views import View
from djangorestframework import permissions
@@ -14,8 +12,12 @@ import base64
class MockView(View):
permissions = ( permissions.IsAuthenticated, )
+
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('',
(r'^$', MockView.as_view()),
@@ -83,8 +85,13 @@ class SessionAuthTests(TestCase):
response = self.non_csrf_client.post('/', {'example': 'example'})
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):
"""Ensure POSTing form over session authentication without logged in user fails."""
response = self.csrf_client.post('/', {'example': 'example'})
self.assertEqual(response.status_code, 403)
-