Debian Codegraph @

tests/backends/postgresql/test_introspection.py

raw
1 import unittest
2
3 from django.db import connection
4 from django.test import TestCase
5
6 from ..models import Person
7
8
9 @unittest.skipUnless(connection.vendor == "postgresql", "Test only for PostgreSQL")
10 class DatabaseSequenceTests(TestCase):
11 def test_get_sequences(self):
12 with connection.cursor() as cursor:
13 seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table)
14 self.assertEqual(
15 seqs,
16 [
17 {
18 "table": Person._meta.db_table,
19 "column": "id",
20 "name": "backends_person_id_seq",
21 }
22 ],
23 )
24 cursor.execute("ALTER SEQUENCE backends_person_id_seq RENAME TO pers_seq")
25 seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table)
26 self.assertEqual(
27 seqs,
28 [{"table": Person._meta.db_table, "column": "id", "name": "pers_seq"}],
29 )
30
31 def test_get_sequences_old_serial(self):
32 with connection.cursor() as cursor:
33 cursor.execute("CREATE TABLE testing (serial_field SERIAL);")
34 seqs = connection.introspection.get_sequences(cursor, "testing")
35 self.assertEqual(
36 seqs,
37 [
38 {
39 "table": "testing",
40 "column": "serial_field",
41 "name": "testing_serial_field_seq",
42 }
43 ],
44 )