Skip to content

Commit 66bc1ab

Browse files
committed
Fix validator tests to handle database-specific integer range validators
1 parent 10a3fc0 commit 66bc1ab

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/test_validators.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66
from django import VERSION as django_version
7-
from django.db import DataError, models
7+
from django.db import DataError, connection, models
88
from django.test import TestCase
99

1010
from rest_framework import serializers
@@ -742,8 +742,11 @@ def test_single_field_uniq_validators(self):
742742
UniqueConstraint with single field must be transformed into
743743
field's UniqueValidator
744744
"""
745-
# Django 5 includes Max and Min values validators for IntegerField
746-
extra_validators_qty = 2 if django_version[0] >= 5 else 0
745+
# Backends like PostgreSQL add Min/Max validators for IntegerField;
746+
# SQLite does not because it has no fixed integer range.
747+
has_int_range = connection.ops.integer_field_range('IntegerField')[0] is not None
748+
extra_validators_qty = 2 if has_int_range else 0
749+
747750
serializer = UniqueConstraintSerializer()
748751
assert len(serializer.validators) == 2
749752
validators = serializer.fields['global_id'].validators

0 commit comments

Comments
 (0)