mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Failed test with assertion fix
This commit is contained in:
parent
1125c438d3
commit
ad8fd98905
|
@ -61,7 +61,6 @@ class BaseSerializer(Field):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, instance=None, data=None, **kwargs):
|
def __init__(self, instance=None, data=None, **kwargs):
|
||||||
assert data is not None
|
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
self._initial_data = data
|
self._initial_data = data
|
||||||
self.partial = kwargs.pop('partial', False)
|
self.partial = kwargs.pop('partial', False)
|
||||||
|
@ -150,6 +149,7 @@ class BaseSerializer(Field):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
def is_valid(self, raise_exception=False):
|
def is_valid(self, raise_exception=False):
|
||||||
|
assert self._initial_data is not None
|
||||||
assert not hasattr(self, 'restore_object'), (
|
assert not hasattr(self, 'restore_object'), (
|
||||||
'Serializer `%s.%s` has old-style version 2 `.restore_object()` '
|
'Serializer `%s.%s` has old-style version 2 `.restore_object()` '
|
||||||
'that is no longer compatible with REST framework 3. '
|
'that is no longer compatible with REST framework 3. '
|
||||||
|
|
|
@ -34,6 +34,11 @@ class TestSerializer:
|
||||||
serializer = self.Serializer()
|
serializer = self.Serializer()
|
||||||
assert serializer.data == {'char': '', 'integer': None}
|
assert serializer.data == {'char': '', 'integer': None}
|
||||||
|
|
||||||
|
def test_empty_serializer_validity(self):
|
||||||
|
serializer = self.Serializer()
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
serializer.is_valid()
|
||||||
|
|
||||||
def test_missing_attribute_during_serialization(self):
|
def test_missing_attribute_during_serialization(self):
|
||||||
class MissingAttributes:
|
class MissingAttributes:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user