mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[2.0.x] Added assertion helpers for PostgreSQL's server-side cursor tests.
Backport of 6cb6382639 from master
			
			
This commit is contained in:
		| @@ -37,29 +37,28 @@ class ServerSideCursorsPostgres(TestCase): | |||||||
|             connection.settings_dict[setting] = kwargs[setting] |             connection.settings_dict[setting] = kwargs[setting] | ||||||
|             yield |             yield | ||||||
|  |  | ||||||
|     def test_server_side_cursor(self): |     def assertUsesCursor(self, queryset, num_expected=1): | ||||||
|         persons = Person.objects.iterator() |         next(queryset)  # Open a server-side cursor | ||||||
|         next(persons)  # Open a server-side cursor |  | ||||||
|         cursors = self.inspect_cursors() |         cursors = self.inspect_cursors() | ||||||
|         self.assertEqual(len(cursors), 1) |         self.assertEqual(len(cursors), num_expected) | ||||||
|         self.assertIn('_django_curs_', cursors[0].name) |  | ||||||
|         self.assertFalse(cursors[0].is_scrollable) |  | ||||||
|         self.assertFalse(cursors[0].is_holdable) |  | ||||||
|         self.assertFalse(cursors[0].is_binary) |  | ||||||
|  |  | ||||||
|     def test_server_side_cursor_many_cursors(self): |  | ||||||
|         persons = Person.objects.iterator() |  | ||||||
|         persons2 = Person.objects.iterator() |  | ||||||
|         next(persons)  # Open a server-side cursor |  | ||||||
|         next(persons2)  # Open a second server-side cursor |  | ||||||
|         cursors = self.inspect_cursors() |  | ||||||
|         self.assertEqual(len(cursors), 2) |  | ||||||
|         for cursor in cursors: |         for cursor in cursors: | ||||||
|             self.assertIn('_django_curs_', cursor.name) |             self.assertIn('_django_curs_', cursor.name) | ||||||
|             self.assertFalse(cursor.is_scrollable) |             self.assertFalse(cursor.is_scrollable) | ||||||
|             self.assertFalse(cursor.is_holdable) |             self.assertFalse(cursor.is_holdable) | ||||||
|             self.assertFalse(cursor.is_binary) |             self.assertFalse(cursor.is_binary) | ||||||
|  |  | ||||||
|  |     def asserNotUsesCursor(self, queryset): | ||||||
|  |         self.assertUsesCursor(queryset, num_expected=0) | ||||||
|  |  | ||||||
|  |     def test_server_side_cursor(self): | ||||||
|  |         self.assertUsesCursor(Person.objects.iterator()) | ||||||
|  |  | ||||||
|  |     def test_server_side_cursor_many_cursors(self): | ||||||
|  |         persons = Person.objects.iterator() | ||||||
|  |         persons2 = Person.objects.iterator() | ||||||
|  |         next(persons)  # Open a server-side cursor | ||||||
|  |         self.assertUsesCursor(persons2, num_expected=2) | ||||||
|  |  | ||||||
|     def test_closed_server_side_cursor(self): |     def test_closed_server_side_cursor(self): | ||||||
|         persons = Person.objects.iterator() |         persons = Person.objects.iterator() | ||||||
|         next(persons)  # Open a server-side cursor |         next(persons)  # Open a server-side cursor | ||||||
| @@ -70,13 +69,8 @@ class ServerSideCursorsPostgres(TestCase): | |||||||
|     def test_server_side_cursors_setting(self): |     def test_server_side_cursors_setting(self): | ||||||
|         with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=False): |         with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=False): | ||||||
|             persons = Person.objects.iterator() |             persons = Person.objects.iterator() | ||||||
|             next(persons)  # Open a server-side cursor |             self.assertUsesCursor(persons) | ||||||
|             cursors = self.inspect_cursors() |  | ||||||
|             self.assertEqual(len(cursors), 1) |  | ||||||
|             del persons  # Close server-side cursor |             del persons  # Close server-side cursor | ||||||
|  |  | ||||||
|         with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=True): |         with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=True): | ||||||
|             persons = Person.objects.iterator() |             self.asserNotUsesCursor(Person.objects.iterator()) | ||||||
|             next(persons)  # Should not open a server-side cursor |  | ||||||
|             cursors = self.inspect_cursors() |  | ||||||
|             self.assertEqual(len(cursors), 0) |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user