mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #31117 -- Made various tests properly handle unexpected databases aliases.
- Used selected "databases" instead of django.db.connections. - Made routers in tests.migrations skip migrations on unexpected databases. - Added DiscoverRunnerGetDatabasesTests.assertSkippedDatabases() hook which properly asserts messages about skipped databases.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							26be703fe6
						
					
				
				
					commit
					2a2ea4ee18
				
			| @@ -2,7 +2,6 @@ from unittest import mock | ||||
|  | ||||
| from django.contrib import admin | ||||
| from django.contrib.auth.models import User | ||||
| from django.db import connections | ||||
| from django.test import TestCase, override_settings | ||||
| from django.urls import path, reverse | ||||
|  | ||||
| @@ -34,7 +33,7 @@ class MultiDatabaseTests(TestCase): | ||||
|     def setUpTestData(cls): | ||||
|         cls.superusers = {} | ||||
|         cls.test_book_ids = {} | ||||
|         for db in connections: | ||||
|         for db in cls.databases: | ||||
|             Router.target_db = db | ||||
|             cls.superusers[db] = User.objects.create_superuser( | ||||
|                 username='admin', password='something', email='test@test.org', | ||||
| @@ -45,7 +44,7 @@ class MultiDatabaseTests(TestCase): | ||||
|  | ||||
|     @mock.patch('django.contrib.admin.options.transaction') | ||||
|     def test_add_view(self, mock): | ||||
|         for db in connections: | ||||
|         for db in self.databases: | ||||
|             with self.subTest(db=db): | ||||
|                 Router.target_db = db | ||||
|                 self.client.force_login(self.superusers[db]) | ||||
| @@ -57,7 +56,7 @@ class MultiDatabaseTests(TestCase): | ||||
|  | ||||
|     @mock.patch('django.contrib.admin.options.transaction') | ||||
|     def test_change_view(self, mock): | ||||
|         for db in connections: | ||||
|         for db in self.databases: | ||||
|             with self.subTest(db=db): | ||||
|                 Router.target_db = db | ||||
|                 self.client.force_login(self.superusers[db]) | ||||
| @@ -69,7 +68,7 @@ class MultiDatabaseTests(TestCase): | ||||
|  | ||||
|     @mock.patch('django.contrib.admin.options.transaction') | ||||
|     def test_delete_view(self, mock): | ||||
|         for db in connections: | ||||
|         for db in self.databases: | ||||
|             with self.subTest(db=db): | ||||
|                 Router.target_db = db | ||||
|                 self.client.force_login(self.superusers[db]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user