mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Add failing test for fallback to pk-only optimization
Not sure if this is the right place to put the test or where the situation comes up in the real world when not using ORM hacks (like how we found it), but it *does* test the thing.
This commit is contained in:
parent
2709de1310
commit
fa5ad1d0d9
|
@ -3,7 +3,7 @@ import uuid
|
|||
import pytest
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from django.conf.urls import url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
||||
from django.test import override_settings
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
|
||||
|
@ -167,6 +167,22 @@ class TestHyperlinkedRelatedField(APISimpleTestCase):
|
|||
representation = self.field.to_representation(MockObject(pk=''))
|
||||
assert representation is None
|
||||
|
||||
def test_serialize_empty_relationship_attribute(self):
|
||||
class TestSerializer(serializers.Serializer):
|
||||
via_unreachable = serializers.HyperlinkedRelatedField(
|
||||
source='does_not_exist.unreachable',
|
||||
view_name='example',
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class TestSerializable:
|
||||
@property
|
||||
def does_not_exist(self):
|
||||
raise ObjectDoesNotExist
|
||||
|
||||
serializer = TestSerializer(TestSerializable())
|
||||
assert serializer.data == {'via_unreachable': None}
|
||||
|
||||
def test_hyperlinked_related_lookup_exists(self):
|
||||
instance = self.field.to_internal_value('http://example.org/example/foobar/')
|
||||
assert instance is self.queryset.items[0]
|
||||
|
|
Loading…
Reference in New Issue
Block a user