diff options
| author | Morgan Aubert <morgan.aubert@impakfinance.com> | 2018-04-27 17:18:15 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-05-09 11:40:28 -0400 |
| commit | 704443acacf0dfbcb1c52df4b260585055754ce7 (patch) | |
| tree | 600147bf6114d7b490fcd253ff9797b7e7531c09 /tests/backends/postgresql | |
| parent | 7ba040de7703fd06b9b35ddd31da40103d911c30 (diff) | |
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
Diffstat (limited to 'tests/backends/postgresql')
| -rw-r--r-- | tests/backends/postgresql/tests.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index 33047df83b..e64e097fd1 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -1,5 +1,4 @@ import unittest -import warnings from unittest import mock from django.core.exceptions import ImproperlyConfigured @@ -24,7 +23,14 @@ class Tests(TestCase): self.assertIsNone(nodb_conn.settings_dict['NAME']) # Now assume the 'postgres' db isn't available - with warnings.catch_warnings(record=True) as w: + msg = ( + "Normally Django will use a connection to the 'postgres' database " + "to avoid running initialization queries against the production " + "database when it's not needed (for example, when running tests). " + "Django was unable to create a connection to the 'postgres' " + "database and will use the first PostgreSQL database instead." + ) + with self.assertWarnsMessage(RuntimeWarning, msg): with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.connect', side_effect=mocked_connect, autospec=True): with mock.patch.object( @@ -32,13 +38,9 @@ class Tests(TestCase): 'settings_dict', {**connection.settings_dict, 'NAME': 'postgres'}, ): - warnings.simplefilter('always', RuntimeWarning) nodb_conn = connection._nodb_connection self.assertIsNotNone(nodb_conn.settings_dict['NAME']) self.assertEqual(nodb_conn.settings_dict['NAME'], connections['other'].settings_dict['NAME']) - # Check a RuntimeWarning has been emitted - self.assertEqual(len(w), 1) - self.assertEqual(w[0].message.__class__, RuntimeWarning) def test_database_name_too_long(self): from django.db.backends.postgresql.base import DatabaseWrapper |
