mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 08:59:54 +03:00
Add regression test for OverflowError in unique validation
This commit is contained in:
parent
373e521f36
commit
37b55ef4d5
|
@ -12,7 +12,7 @@ from collections import OrderedDict
|
||||||
|
|
||||||
import django
|
import django
|
||||||
import pytest
|
import pytest
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.core.validators import (
|
from django.core.validators import (
|
||||||
MaxValueValidator, MinLengthValidator, MinValueValidator
|
MaxValueValidator, MinLengthValidator, MinValueValidator
|
||||||
|
@ -1305,3 +1305,33 @@ class Issue6751Test(TestCase):
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
||||||
self.assertEqual(instance.char_field, 'value changed by signal')
|
self.assertEqual(instance.char_field, 'value changed by signal')
|
||||||
|
|
||||||
|
|
||||||
|
class OverflowModel(models.Model):
|
||||||
|
value = models.IntegerField(unique=True, validators=[
|
||||||
|
MaxValueValidator(9223372036854775807),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class Issue7314Test(TestCase):
|
||||||
|
|
||||||
|
def test_model(self):
|
||||||
|
"""
|
||||||
|
Assert that Django can validate the overflow model.
|
||||||
|
"""
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
OverflowModel(value=9223372036854775808).full_clean()
|
||||||
|
|
||||||
|
def test_serializer(self):
|
||||||
|
class TestSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = OverflowModel
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def validate_value(self, value):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
serializer = TestSerializer(data={'value': 9223372036854775808})
|
||||||
|
|
||||||
|
with self.assertRaises(serializers.ValidationError):
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user