2017-09-14 02:12:32 +08:00
|
|
|
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):
|
2017-11-28 21:12:28 +08:00
|
|
|
with connection.cursor() as 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'}]
|
|
|
|
)
|