diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-07-02 14:36:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-02 15:36:53 +0200 |
| commit | fa35c8bdbc6aca65d94d6280fa463d5bc7baa5c0 (patch) | |
| tree | fd32615a8397e8c5068eb45a0c7e43ed1eb44795 /tests | |
| parent | 313c3d1aa14d80922003f841c257ec4e153f8653 (diff) | |
Fixed #30934 -- Included database alias in django.db.backends log messages.
This is useful when working with database routing as you want to know
where each query is being executed.
Co-authored-by: David Winterbottom <david.winterbottom@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index d335aaefbc..1536e93065 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -3,6 +3,7 @@ import datetime import threading import unittest import warnings +from unittest import mock from django.core.management.color import no_style from django.db import ( @@ -491,6 +492,23 @@ class BackendTestCase(TransactionTestCase): BaseDatabaseWrapper.queries_limit = old_queries_limit new_connection.close() + @mock.patch('django.db.backends.utils.logger') + @override_settings(DEBUG=True) + def test_queries_logger(self, mocked_logger): + sql = 'SELECT 1' + connection.features.bare_select_suffix + with connection.cursor() as cursor: + cursor.execute(sql) + params, kwargs = mocked_logger.debug.call_args + self.assertIn('; alias=%s', params[0]) + self.assertEqual(params[2], sql) + self.assertEqual(params[3], None) + self.assertEqual(params[4], connection.alias) + self.assertEqual( + list(kwargs['extra']), + ['duration', 'sql', 'params', 'alias'], + ) + self.assertEqual(tuple(kwargs['extra'].values()), params[1:]) + def test_timezone_none_use_tz_false(self): connection.ensure_connection() with self.settings(TIME_ZONE=None, USE_TZ=False): |
