mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-13 05:06:53 +03:00
Add tests for qs_exists (#4822)
This commit is contained in:
parent
06a5bcc88e
commit
0a496a423d
|
@ -1,10 +1,10 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import DataError, models
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.validators import UniqueValidator
|
from rest_framework.validators import UniqueValidator, qs_exists
|
||||||
|
|
||||||
|
|
||||||
def dedent(blocktext):
|
def dedent(blocktext):
|
||||||
|
@ -429,3 +429,24 @@ class TestHiddenFieldUniquenessForDateValidation(TestCase):
|
||||||
validators = [<UniqueForDateValidator(queryset=HiddenFieldUniqueForDateModel.objects.all(), field='slug', date_field='published')>]
|
validators = [<UniqueForDateValidator(queryset=HiddenFieldUniqueForDateModel.objects.all(), field='slug', date_field='published')>]
|
||||||
""")
|
""")
|
||||||
assert repr(serializer) == expected
|
assert repr(serializer) == expected
|
||||||
|
|
||||||
|
|
||||||
|
class ValidatorsTests(TestCase):
|
||||||
|
|
||||||
|
def test_qs_exists_handles_type_error(self):
|
||||||
|
class TypeErrorQueryset(object):
|
||||||
|
def exists(self):
|
||||||
|
raise TypeError
|
||||||
|
assert qs_exists(TypeErrorQueryset()) is False
|
||||||
|
|
||||||
|
def test_qs_exists_handles_value_error(self):
|
||||||
|
class ValueErrorQueryset(object):
|
||||||
|
def exists(self):
|
||||||
|
raise ValueError
|
||||||
|
assert qs_exists(ValueErrorQueryset()) is False
|
||||||
|
|
||||||
|
def test_qs_exists_handles_data_error(self):
|
||||||
|
class DataErrorQueryset(object):
|
||||||
|
def exists(self):
|
||||||
|
raise DataError
|
||||||
|
assert qs_exists(DataErrorQueryset()) is False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user