Ticket #24726: ticket_24726.diff
File ticket_24726.diff, 4.3 KB (added by , 10 years ago) |
---|
-
tests/postgres_tests/migrations/0002_create_test_models.py
diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index 106818a..21c060d 100644
a b class Migration(migrations.Migration): 148 148 }, 149 149 bases=(models.Model,), 150 150 ), 151 migrations.CreateModel( 152 name='IntegerRangesArrayModel', 153 fields=[ 154 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 155 ('int_ranges', ArrayField(IntegerRangeField(), null=True, blank=True)), 156 ('bigint_ranges', ArrayField(BigIntegerRangeField(), null=True, blank=True)), 157 ], 158 options={ 159 'required_db_vendor': 'postgresql', 160 }, 161 bases=(models.Model,), 162 ), 151 163 ] 152 164 153 165 def apply(self, project_state, schema_editor, collect_sql=False): -
tests/postgres_tests/models.py
diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index aafd529..36c52bf 100644
a b class TextFieldModel(models.Model): 52 52 field = models.TextField() 53 53 54 54 55 # Only create th is modelfor databases which support it55 # Only create these models for databases which support it 56 56 if connection.vendor == 'postgresql' and connection.pg_version >= 90200: 57 57 class RangesModel(PostgreSQLModel): 58 58 ints = IntegerRangeField(blank=True, null=True) … … if connection.vendor == 'postgresql' and connection.pg_version >= 90200: 60 60 floats = FloatRangeField(blank=True, null=True) 61 61 timestamps = DateTimeRangeField(blank=True, null=True) 62 62 dates = DateRangeField(blank=True, null=True) 63 64 class IntegerRangesArrayModel(PostgreSQLModel): 65 int_ranges = ArrayField(IntegerRangeField(), blank=True, null=True) 66 bigint_ranges = ArrayField(BigIntegerRangeField(), blank=True, null=True) 63 67 else: 64 # create an object with this nameso we don't have failing imports68 # create objects with these names so we don't have failing imports 65 69 class RangesModel(object): 66 70 pass 67 71 72 class IntegerRangesArrayModel(object): 73 pass 74 68 75 69 76 class ArrayFieldSubclass(ArrayField): 70 77 def __init__(self, *args, **kwargs): -
tests/postgres_tests/test_array.py
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 895c910..c75190b 100644
a b from django.utils import timezone 13 13 from . import PostgresSQLTestCase 14 14 from .models import ( 15 15 ArrayFieldSubclass, CharArrayModel, DateTimeArrayModel, IntegerArrayModel, 16 NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel, 16 NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel, IntegerRangesArrayModel 17 17 ) 18 18 19 19 try: 20 from psycopg2.extras import NumericRange 20 21 from django.contrib.postgres.fields import ArrayField 21 22 from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField 22 23 except ImportError: … … class TestSaveLoad(PostgresSQLTestCase): 97 98 self.assertEqual(instance.uuids, loaded.uuids) 98 99 self.assertEqual(instance.decimals, loaded.decimals) 99 100 101 def test_integer_ranges_passed_as_tuples(self): 102 instance = IntegerRangesArrayModel( 103 int_ranges=[(10, 20), (30, 40), ], 104 bigint_ranges=[(7000000000, 10000000000), (50000000000, 70000000000)] 105 ) 106 instance.save() 107 loaded = IntegerRangesArrayModel.objects.get() 108 self.assertEqual(instance.int_ranges, loaded.int_ranges) 109 self.assertEqual(instance.bigint_ranges, loaded.bigint_ranges) 110 111 def test_integer_ranges_passed_as_numericrange_instances(self): 112 instance = IntegerRangesArrayModel( 113 int_ranges=[NumericRange(10, 20), NumericRange(30, 40), ], 114 bigint_ranges=[NumericRange(7000000000, 10000000000), NumericRange(50000000000, 70000000000)] 115 ) 116 instance.save() 117 loaded = IntegerRangesArrayModel.objects.get() 118 self.assertEqual(instance.int_ranges, loaded.int_ranges) 119 self.assertEqual(instance.bigint_ranges, loaded.bigint_ranges) 120 100 121 101 122 class TestQuerying(PostgresSQLTestCase): 102 123