Ticket #24726: ticket_24726.diff

File ticket_24726.diff, 4.3 KB (added by Ederson Mota, 10 years ago)

Diff between django/django@master and edrmp/django@ticket_24726

  • 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):  
    148148            },
    149149            bases=(models.Model,),
    150150        ),
     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        ),
    151163    ]
    152164
    153165    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):  
    5252    field = models.TextField()
    5353
    5454
    55 # Only create this model for databases which support it
     55# Only create these models for databases which support it
    5656if connection.vendor == 'postgresql' and connection.pg_version >= 90200:
    5757    class RangesModel(PostgreSQLModel):
    5858        ints = IntegerRangeField(blank=True, null=True)
    if connection.vendor == 'postgresql' and connection.pg_version >= 90200:  
    6060        floats = FloatRangeField(blank=True, null=True)
    6161        timestamps = DateTimeRangeField(blank=True, null=True)
    6262        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)
    6367else:
    64     # create an object with this name so we don't have failing imports
     68    # create objects with these names so we don't have failing imports
    6569    class RangesModel(object):
    6670        pass
    6771
     72    class IntegerRangesArrayModel(object):
     73        pass
     74
    6875
    6976class ArrayFieldSubclass(ArrayField):
    7077    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  
    1313from . import PostgresSQLTestCase
    1414from .models import (
    1515    ArrayFieldSubclass, CharArrayModel, DateTimeArrayModel, IntegerArrayModel,
    16     NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel,
     16    NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel, IntegerRangesArrayModel
    1717)
    1818
    1919try:
     20    from psycopg2.extras import NumericRange
    2021    from django.contrib.postgres.fields import ArrayField
    2122    from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField
    2223except ImportError:
    class TestSaveLoad(PostgresSQLTestCase):  
    9798        self.assertEqual(instance.uuids, loaded.uuids)
    9899        self.assertEqual(instance.decimals, loaded.decimals)
    99100
     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
    100121
    101122class TestQuerying(PostgresSQLTestCase):
    102123
Back to Top