diff options
| author | Paolo Melchiorre <paolo@melchiorre.org> | 2017-03-29 23:52:42 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-04-25 20:21:36 -0400 |
| commit | fcb5dbfec0542faaa1b0adad754a1caf1bcd65e2 (patch) | |
| tree | a81d7f63382578206e943e539165fecf43c00e64 /tests/postgres_tests | |
| parent | 98ee57e343206ef553de78b22be5e9a6dacb5060 (diff) | |
Fixed #27996 -- Added RandomUUID function and CryptoExtension to contrib.postgres.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/migrations/0001_setup_extensions.py | 6 | ||||
| -rw-r--r-- | tests/postgres_tests/migrations/0002_create_test_models.py | 7 | ||||
| -rw-r--r-- | tests/postgres_tests/models.py | 4 | ||||
| -rw-r--r-- | tests/postgres_tests/test_functions.py | 17 |
4 files changed, 30 insertions, 4 deletions
diff --git a/tests/postgres_tests/migrations/0001_setup_extensions.py b/tests/postgres_tests/migrations/0001_setup_extensions.py index d090ff7fd6..b00c6c0838 100644 --- a/tests/postgres_tests/migrations/0001_setup_extensions.py +++ b/tests/postgres_tests/migrations/0001_setup_extensions.py @@ -4,13 +4,14 @@ from django.db import migrations try: from django.contrib.postgres.operations import ( - BtreeGinExtension, CITextExtension, CreateExtension, HStoreExtension, - TrigramExtension, UnaccentExtension, + BtreeGinExtension, CITextExtension, CreateExtension, CryptoExtension, + HStoreExtension, TrigramExtension, UnaccentExtension, ) except ImportError: BtreeGinExtension = mock.Mock() CITextExtension = mock.Mock() CreateExtension = mock.Mock() + CryptoExtension = mock.Mock() HStoreExtension = mock.Mock() TrigramExtension = mock.Mock() UnaccentExtension = mock.Mock() @@ -24,6 +25,7 @@ class Migration(migrations.Migration): # Ensure CreateExtension quotes extension names by creating one with a # dash in its name. CreateExtension('uuid-ossp'), + CryptoExtension(), HStoreExtension(), TrigramExtension(), UnaccentExtension(), diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index 842848dd47..4cd37e5e43 100644 --- a/tests/postgres_tests/migrations/0002_create_test_models.py +++ b/tests/postgres_tests/migrations/0002_create_test_models.py @@ -192,6 +192,13 @@ class Migration(migrations.Migration): ] ), migrations.CreateModel( + name='UUIDTestModel', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('uuid', models.UUIDField(default=None, null=True)), + ] + ), + migrations.CreateModel( name='RangesModel', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index 15fb5ab4ee..001ed00d0c 100644 --- a/tests/postgres_tests/models.py +++ b/tests/postgres_tests/models.py @@ -171,3 +171,7 @@ class StatTestModel(models.Model): class NowTestModel(models.Model): when = models.DateTimeField(null=True, default=None) + + +class UUIDTestModel(models.Model): + uuid = models.UUIDField(default=None, null=True) diff --git a/tests/postgres_tests/test_functions.py b/tests/postgres_tests/test_functions.py index 620b561325..875a4b9520 100644 --- a/tests/postgres_tests/test_functions.py +++ b/tests/postgres_tests/test_functions.py @@ -1,10 +1,11 @@ +import uuid from datetime import datetime from time import sleep -from django.contrib.postgres.functions import TransactionNow +from django.contrib.postgres.functions import RandomUUID, TransactionNow from . import PostgreSQLTestCase -from .models import NowTestModel +from .models import NowTestModel, UUIDTestModel class TestTransactionNow(PostgreSQLTestCase): @@ -26,3 +27,15 @@ class TestTransactionNow(PostgreSQLTestCase): self.assertIsInstance(m1.when, datetime) self.assertEqual(m1.when, m2.when) + + +class TestRandomUUID(PostgreSQLTestCase): + + def test_random_uuid(self): + m1 = UUIDTestModel.objects.create() + m2 = UUIDTestModel.objects.create() + UUIDTestModel.objects.update(uuid=RandomUUID()) + m1.refresh_from_db() + m2.refresh_from_db() + self.assertIsInstance(m1.uuid, uuid.UUID) + self.assertNotEqual(m1.uuid, m2.uuid) |
