2017-09-14 02:12:32 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from django.db import connection
|
|
|
|
from django.test import TransactionTestCase
|
|
|
|
|
2020-02-24 21:21:50 +08:00
|
|
|
from ..models import Square
|
2017-09-14 02:12:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(connection.vendor == 'oracle', 'Oracle tests')
|
|
|
|
class DatabaseSequenceTests(TransactionTestCase):
|
|
|
|
available_apps = []
|
|
|
|
|
|
|
|
def test_get_sequences(self):
|
|
|
|
with connection.cursor() as cursor:
|
2020-02-24 21:21:50 +08:00
|
|
|
seqs = connection.introspection.get_sequences(cursor, Square._meta.db_table, Square._meta.local_fields)
|
2017-09-14 02:12:32 +08:00
|
|
|
self.assertEqual(len(seqs), 1)
|
|
|
|
self.assertIsNotNone(seqs[0]['name'])
|
2020-02-24 21:21:50 +08:00
|
|
|
self.assertEqual(seqs[0]['table'], Square._meta.db_table)
|
2017-09-14 02:12:32 +08:00
|
|
|
self.assertEqual(seqs[0]['column'], 'id')
|
|
|
|
|
|
|
|
def test_get_sequences_manually_created_index(self):
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
with connection.schema_editor() as editor:
|
2020-02-24 21:21:50 +08:00
|
|
|
editor._drop_identity(Square._meta.db_table, 'id')
|
|
|
|
seqs = connection.introspection.get_sequences(cursor, Square._meta.db_table, Square._meta.local_fields)
|
|
|
|
self.assertEqual(seqs, [{'table': Square._meta.db_table, 'column': 'id'}])
|
2017-09-14 02:12:32 +08:00
|
|
|
# Recreate model, because adding identity is impossible.
|
2020-02-24 21:21:50 +08:00
|
|
|
editor.delete_model(Square)
|
|
|
|
editor.create_model(Square)
|