summaryrefslogtreecommitdiff
path: root/tests/backends/postgresql
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-09-13 20:12:32 +0200
committerGitHub <noreply@github.com>2017-09-13 20:12:32 +0200
commitc6a1faecc3d6e25597a7105df74f11678f2f2aac (patch)
tree84f7d7ce04ec478ba9652ecdf3728a259538864a /tests/backends/postgresql
parentc2ecef869ce46349e79c39610cd66a576d78289e (diff)
Refs #27090 -- Added real database sequence introspection.
Thanks Mariusz Felisiak for the Oracle part and Tim Graham for the review.
Diffstat (limited to 'tests/backends/postgresql')
-rw-r--r--tests/backends/postgresql/test_introspection.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/backends/postgresql/test_introspection.py b/tests/backends/postgresql/test_introspection.py
new file mode 100644
index 0000000000..cfa801a77f
--- /dev/null
+++ b/tests/backends/postgresql/test_introspection.py
@@ -0,0 +1,23 @@
+import unittest
+
+from django.db import connection
+from django.test import TestCase
+
+from ..models import Person
+
+
+@unittest.skipUnless(connection.vendor == 'postgresql', "Test only for PostgreSQL")
+class DatabaseSequenceTests(TestCase):
+ def test_get_sequences(self):
+ cursor = connection.cursor()
+ seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table)
+ self.assertEqual(
+ seqs,
+ [{'table': Person._meta.db_table, 'column': 'id', 'name': 'backends_person_id_seq'}]
+ )
+ cursor.execute('ALTER SEQUENCE backends_person_id_seq RENAME TO pers_seq')
+ seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table)
+ self.assertEqual(
+ seqs,
+ [{'table': Person._meta.db_table, 'column': 'id', 'name': 'pers_seq'}]
+ )