Ticket #24744: 24744-test.diff

File 24744-test.diff, 2.3 KB (added by Tim Graham, 4 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..da35c90 100644
    a b class Migration(migrations.Migration): 
    4949            bases=(models.Model,),
    5050        ),
    5151        migrations.CreateModel(
     52            name='FKToHStoreModel',
     53            fields=[
     54                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
     55                ('fk', models.ForeignKey('postgres_tests.HStoreModel')),
     56            ],
     57            options={
     58                'required_db_vendor': 'postgresql',
     59            },
     60            bases=(models.Model,),
     61        ),
     62        migrations.CreateModel(
    5263            name='OtherTypesArrayModel',
    5364            fields=[
    5465                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
  • tests/postgres_tests/models.py

    diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py
    index aafd529..cc3a2fd 100644
    a b class HStoreModel(PostgreSQLModel): 
    4444    field = HStoreField(blank=True, null=True)
    4545
    4646
     47class FKToHStoreModel(models.Model):
     48    fk = models.ForeignKey(HStoreModel)
     49
     50
    4751class CharFieldModel(models.Model):
    4852    field = models.CharField(max_length=16)
    4953
  • tests/postgres_tests/test_hstore.py

    diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
    index ed88e2f..98902b4 100644
    a b class TestQuerying(PostgresSQLTestCase): 
    114114            self.objs[:3]
    115115        )
    116116
     117    def test_fk_filter(self):
     118        from .models import FKToHStoreModel
     119        obj = FKToHStoreModel.objects.create(fk=self.objs[0])
     120        subquery = HStoreModel.objects.filter(field__a='b')
     121        # test passes with `list(subquery)` below.
     122        self.assertSequenceEqual(
     123            FKToHStoreModel.objects.filter(fk__in=subquery),
     124            [obj]
     125        )
     126
    117127
    118128class TestSerialization(PostgresSQLTestCase):
    119129    test_data = '[{"fields": {"field": "{\\"a\\": \\"b\\"}"}, "model": "postgres_tests.hstoremodel", "pk": null}]'
Back to Top