Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/test_relations_hyperlink.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.test import TestCase, override_settings
from django.urls import path

Expand Down Expand Up @@ -68,7 +69,6 @@ class Meta:
fields = ('url', 'name', 'nullable_source')


# TODO: Add test that .data cannot be accessed prior to .is_valid
@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedManyToManyTests(TestCase):
def setUp(self):
Expand Down Expand Up @@ -193,6 +193,15 @@ def test_reverse_many_to_many_create(self):
]
assert serializer.data == expected

def test_data_cannot_be_accessed_prior_to_is_valid(self):
"""Test that .data cannot be accessed prior to .is_valid for hyperlinked serializers."""
serializer = ManyToManySourceSerializer(
data={'name': 'test-source', 'targets': ['http://testserver/manytomanytarget/1/']},
context={'request': request}
)
with pytest.raises(AssertionError):
serializer.data


@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedForeignKeyTests(TestCase):
Expand Down
11 changes: 9 additions & 2 deletions tests/test_relations_pk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.test import TestCase

from rest_framework import serializers
Expand Down Expand Up @@ -94,8 +95,6 @@ class Meta:
fields = '__all__'


# TODO: Add test that .data cannot be accessed prior to .is_valid

class PKManyToManyTests(TestCase):
def setUp(self):
for idx in range(1, 4):
Expand Down Expand Up @@ -218,6 +217,14 @@ def test_reverse_many_to_many_create(self):
]
assert serializer.data == expected

def test_data_cannot_be_accessed_prior_to_is_valid(self):
"""Test that .data cannot be accessed prior to .is_valid for primary key serializers."""
serializer = ManyToManySourceSerializer(
data={'name': 'test-source', 'targets': [1]}
)
with pytest.raises(AssertionError):
serializer.data


class PKForeignKeyTests(TestCase):
def setUp(self):
Expand Down
Loading