diff options
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/__init__.py | 2 | ||||
| -rw-r--r-- | rest_framework/request.py | 8 | ||||
| -rw-r--r-- | rest_framework/tests/relations_hyperlink.py (renamed from rest_framework/tests/hyperlink_relations.py) | 6 | ||||
| -rw-r--r-- | rest_framework/tests/relations_nested.py | 51 | ||||
| -rw-r--r-- | rest_framework/tests/relations_pk.py (renamed from rest_framework/tests/pk_relations.py) | 0 | ||||
| -rw-r--r-- | rest_framework/tests/request.py | 8 |
6 files changed, 71 insertions, 4 deletions
diff --git a/rest_framework/__init__.py b/rest_framework/__init__.py index d5cac5c6..02bc6fc1 100644 --- a/rest_framework/__init__.py +++ b/rest_framework/__init__.py @@ -1,3 +1,3 @@ -__version__ = '2.1.11' +__version__ = '2.1.12' VERSION = __version__ # synonym diff --git a/rest_framework/request.py b/rest_framework/request.py index 39c64321..b7133608 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -188,6 +188,14 @@ class Request(object): self._user, self._auth = self._authenticate() return self._auth + @auth.setter + def auth(self, value): + """ + Sets any non-user authentication information associated with the + request, such as an authentication token. + """ + self._auth = value + def _load_data_and_files(self): """ Parses the request content into self.DATA and self.FILES. diff --git a/rest_framework/tests/hyperlink_relations.py b/rest_framework/tests/relations_hyperlink.py index 9e8ecf70..53ce0074 100644 --- a/rest_framework/tests/hyperlink_relations.py +++ b/rest_framework/tests/relations_hyperlink.py @@ -78,7 +78,7 @@ class NullableForeignKeySourceSerializer(serializers.HyperlinkedModelSerializer) # TODO: Add test that .data cannot be accessed prior to .is_valid class HyperlinkedManyToManyTests(TestCase): - urls = 'rest_framework.tests.hyperlink_relations' + urls = 'rest_framework.tests.relations_hyperlink' def setUp(self): for idx in range(1, 4): @@ -186,7 +186,7 @@ class HyperlinkedManyToManyTests(TestCase): class HyperlinkedForeignKeyTests(TestCase): - urls = 'rest_framework.tests.hyperlink_relations' + urls = 'rest_framework.tests.relations_hyperlink' def setUp(self): target = ForeignKeyTarget(name='target-1') @@ -243,7 +243,7 @@ class HyperlinkedForeignKeyTests(TestCase): class HyperlinkedNullableForeignKeyTests(TestCase): - urls = 'rest_framework.tests.hyperlink_relations' + urls = 'rest_framework.tests.relations_hyperlink' def setUp(self): target = ForeignKeyTarget(name='target-1') diff --git a/rest_framework/tests/relations_nested.py b/rest_framework/tests/relations_nested.py new file mode 100644 index 00000000..3482c252 --- /dev/null +++ b/rest_framework/tests/relations_nested.py @@ -0,0 +1,51 @@ +from django.db import models +from django.test import TestCase +from rest_framework import serializers + + +# ForeignKey + +class ForeignKeyTarget(models.Model): + name = models.CharField(max_length=100) + + +class ForeignKeySource(models.Model): + name = models.CharField(max_length=100) + target = models.ForeignKey(ForeignKeyTarget, related_name='sources') + + +class ForeignKeySourceSerializer(serializers.ModelSerializer): + class Meta: + model = ForeignKeySource + + +class ForeignKeyTargetSerializer(serializers.ModelSerializer): + sources = ForeignKeySourceSerializer() + + class Meta: + model = ForeignKeyTarget + + +class ReverseForeignKeyTests(TestCase): + def setUp(self): + target = ForeignKeyTarget(name='target-1') + target.save() + new_target = ForeignKeyTarget(name='target-2') + new_target.save() + for idx in range(1, 4): + source = ForeignKeySource(name='source-%d' % idx, target=target) + source.save() + + def test_reverse_foreign_key_retrieve(self): + queryset = ForeignKeyTarget.objects.all() + serializer = ForeignKeyTargetSerializer(queryset) + expected = [ + {'id': 1, 'name': u'target-1', 'sources': [ + {'id': 1, 'name': u'source-1', 'target': 1}, + {'id': 2, 'name': u'source-2', 'target': 1}, + {'id': 3, 'name': u'source-3', 'target': 1}, + ]}, + {'id': 2, 'name': u'target-2', 'sources': [ + ]} + ] + self.assertEquals(serializer.data, expected) diff --git a/rest_framework/tests/pk_relations.py b/rest_framework/tests/relations_pk.py index e3360939..e3360939 100644 --- a/rest_framework/tests/pk_relations.py +++ b/rest_framework/tests/relations_pk.py diff --git a/rest_framework/tests/request.py b/rest_framework/tests/request.py index 2eb34cea..1f05ff8f 100644 --- a/rest_framework/tests/request.py +++ b/rest_framework/tests/request.py @@ -303,3 +303,11 @@ class TestUserSetter(TestCase): self.assertFalse(self.request.user.is_anonymous()) logout(self.request) self.assertTrue(self.request.user.is_anonymous()) + + +class TestAuthSetter(TestCase): + + def test_auth_can_be_set(self): + request = Request(factory.get('/')) + request.auth = 'DUMMY' + self.assertEqual(request.auth, 'DUMMY') |
