mirror of
https://github.com/django/django.git
synced 2025-09-01 08:17:37 +00:00
Fixed #28853 -- Updated connection.cursor() uses to use a context manager.
This commit is contained in:
parent
3308085838
commit
7a6fbf36b1
18 changed files with 234 additions and 257 deletions
|
@ -9,15 +9,15 @@ 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'}]
|
||||
)
|
||||
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'}]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue