Add tests for qs_exists (#4822)

This commit is contained in:
Artem Muterko 2017-01-18 13:46:12 +02:00 committed by Tom Christie
parent 06a5bcc88e
commit 0a496a423d

View File

@ -1,10 +1,10 @@
import datetime
from django.db import models
from django.db import DataError, models
from django.test import TestCase
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from rest_framework.validators import UniqueValidator, qs_exists
def dedent(blocktext):
@ -429,3 +429,24 @@ class TestHiddenFieldUniquenessForDateValidation(TestCase):
validators = [<UniqueForDateValidator(queryset=HiddenFieldUniqueForDateModel.objects.all(), field='slug', date_field='published')>]
""")
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