aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTom Christie2014-08-19 10:11:10 +0100
committerTom Christie2014-08-19 10:11:10 +0100
commite385a7b8eb6e538698f28128e43fe8bfaefd4e97 (patch)
tree3f1cac50c40ec77a0bc5537f1a04628901a4d2ce /tests
parent2aad8e4b35c3552a065347d7eccad8bd51938783 (diff)
parent48b66ec2a2b744f170034adbdaaa1588e6c14e11 (diff)
downloaddjango-rest-framework-e385a7b8eb6e538698f28128e43fe8bfaefd4e97.tar.bz2
Merge master
Diffstat (limited to 'tests')
-rw-r--r--tests/test_authentication.py9
-rw-r--r--tests/test_fields.py18
-rw-r--r--tests/test_serializer.py2
-rw-r--r--tests/test_testing.py11
4 files changed, 39 insertions, 1 deletions
diff --git a/tests/test_authentication.py b/tests/test_authentication.py
index 5b97d60b..f5bfc5e6 100644
--- a/tests/test_authentication.py
+++ b/tests/test_authentication.py
@@ -551,6 +551,15 @@ class OAuth2Tests(TestCase):
self.assertEqual(response.status_code, 401)
@unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed')
+ def test_get_form_with_wrong_authorization_header_token_missing(self):
+ """Ensure that a missing token lead to the correct HTTP error status code"""
+ auth = "Bearer"
+ response = self.csrf_client.get('/oauth2-test/', {}, HTTP_AUTHORIZATION=auth)
+ self.assertEqual(response.status_code, 401)
+ response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth)
+ self.assertEqual(response.status_code, 401)
+
+ @unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed')
def test_get_form_passing_auth(self):
"""Ensure GETing form over OAuth with correct client credentials succeed"""
auth = self._create_authorization_header()
diff --git a/tests/test_fields.py b/tests/test_fields.py
index 73b15641..97ef016f 100644
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -1002,3 +1002,21 @@ class BooleanField(TestCase):
bool_field = serializers.BooleanField(required=True)
self.assertFalse(BooleanRequiredSerializer(data={}).is_valid())
+
+
+class SerializerMethodFieldTest(TestCase):
+ """
+ Tests for the SerializerMethodField field_to_native() behavior
+ """
+ class SerializerTest(serializers.Serializer):
+ def get_my_test(self, obj):
+ return obj.my_test[0:5]
+
+ class Example():
+ my_test = 'Hey, this is a test !'
+
+ def test_field_to_native(self):
+ s = serializers.SerializerMethodField('get_my_test')
+ s.initialize(self.SerializerTest(), 'name')
+ result = s.field_to_native(self.Example(), None)
+ self.assertEqual(result, 'Hey, ')
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
index 6a1a3521..7d57fcf0 100644
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -686,7 +686,7 @@ class ModelValidationTests(TestCase):
photo_serializer = PhotoSerializer(instance=photo, data={'album': ''}, partial=True)
self.assertFalse(photo_serializer.is_valid())
self.assertTrue('album' in photo_serializer.errors)
- self.assertEqual(photo_serializer.errors['album'], photo_serializer.error_messages['required'])
+ self.assertEqual(photo_serializer.errors['album'], [photo_serializer.error_messages['required']])
def test_foreign_key_with_partial(self):
"""
diff --git a/tests/test_testing.py b/tests/test_testing.py
index e2e4e217..1b126e00 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -99,6 +99,17 @@ class TestAPITestClient(TestCase):
self.assertEqual(response.status_code, 403)
self.assertEqual(response.data, expected)
+ def test_can_logout(self):
+ """
+ `logout()` reset stored credentials
+ """
+ self.client.credentials(HTTP_AUTHORIZATION='example')
+ response = self.client.get('/view/')
+ self.assertEqual(response.data['auth'], 'example')
+ self.client.logout()
+ response = self.client.get('/view/')
+ self.assertEqual(response.data['auth'], b'')
+
class TestAPIRequestFactory(TestCase):
def test_csrf_exempt_by_default(self):