mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Test wrapped TypeError/ValueError handling
This commit is contained in:
parent
7c834f25e4
commit
ecadfc3220
|
@ -206,6 +206,27 @@ class TestHyperlinkedRelatedField(APISimpleTestCase):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
field.to_internal_value('http://example.org/example/doesnotexist/')
|
field.to_internal_value('http://example.org/example/doesnotexist/')
|
||||||
|
|
||||||
|
def hyperlinked_related_queryset_error(self, exc_type):
|
||||||
|
class QuerySet:
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
raise exc_type
|
||||||
|
|
||||||
|
field = serializers.HyperlinkedRelatedField(
|
||||||
|
view_name='example',
|
||||||
|
lookup_field='name',
|
||||||
|
queryset=QuerySet(),
|
||||||
|
)
|
||||||
|
with pytest.raises(serializers.ValidationError) as excinfo:
|
||||||
|
field.to_internal_value('http://example.org/example/doesnotexist/')
|
||||||
|
msg = excinfo.value.detail[0]
|
||||||
|
assert msg == 'Invalid hyperlink - Object does not exist.'
|
||||||
|
|
||||||
|
def test_hyperlinked_related_queryset_type_error(self):
|
||||||
|
self.hyperlinked_related_queryset_error(TypeError)
|
||||||
|
|
||||||
|
def test_hyperlinked_related_queryset_value_error(self):
|
||||||
|
self.hyperlinked_related_queryset_error(ValueError)
|
||||||
|
|
||||||
|
|
||||||
class TestHyperlinkedIdentityField(APISimpleTestCase):
|
class TestHyperlinkedIdentityField(APISimpleTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user