Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tests/test_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import tempfile

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.validators import (
MaxLengthValidator, MaxValueValidator, MinLengthValidator,
Expand Down Expand Up @@ -1498,3 +1498,33 @@ class Meta:
serializer.save()

self.assertEqual(instance.char_field, 'value changed by signal')


class OverflowModel(models.Model):
value = models.IntegerField(unique=True, validators=[
MaxValueValidator(9223372036854775807),
])


class Issue7314Test(TestCase):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Issue7314Test(TestCase):
class Issue7134Test(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)
Comment on lines +1529 to +1530

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with self.assertRaises(serializers.ValidationError):
serializer.is_valid(raise_exception=True)
with self.assertRaises(serializers.ValidationError) as ctx:
serializer.is_valid(raise_exception=True)
# Check that the error code of the validation error
self.assertEqual(
[error.code for error in ctx.exception.detail['value']],
['max_value'],
)