diff options
| author | Claude Paroz <claude@2xlibre.net> | 2018-04-28 15:20:27 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-05-07 09:34:00 -0400 |
| commit | 607970f31cc07c317f2ebb684c8f3ccc36a95b3e (patch) | |
| tree | b11c0976fb161d3339025400b048a27ce5e2f19f /tests/schema | |
| parent | 7d3fe36c626a3268413eb86d37920f132eb4a54f (diff) | |
Replaced django.test.utils.patch_logger() with assertLogs().
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/schema')
| -rw-r--r-- | tests/schema/test_logging.py | 12 | ||||
| -rw-r--r-- | tests/schema/tests.py | 14 |
2 files changed, 12 insertions, 14 deletions
diff --git a/tests/schema/test_logging.py b/tests/schema/test_logging.py index 21e3c9e4a6..453bdd798e 100644 --- a/tests/schema/test_logging.py +++ b/tests/schema/test_logging.py @@ -1,6 +1,5 @@ from django.db import connection from django.test import TestCase -from django.test.utils import patch_logger class SchemaLoggerTests(TestCase): @@ -9,12 +8,11 @@ class SchemaLoggerTests(TestCase): editor = connection.schema_editor(collect_sql=True) sql = 'SELECT * FROM foo WHERE id in (%s, %s)' params = [42, 1337] - with patch_logger('django.db.backends.schema', 'debug', log_kwargs=True) as logger: + with self.assertLogs('django.db.backends.schema', 'DEBUG') as cm: editor.execute(sql, params) + self.assertEqual(cm.records[0].sql, sql) + self.assertEqual(cm.records[0].params, params) self.assertEqual( - logger, - [( - 'SELECT * FROM foo WHERE id in (%s, %s); (params [42, 1337])', - {'extra': {'sql': sql, 'params': params}}, - )] + cm.records[0].getMessage(), + 'SELECT * FROM foo WHERE id in (%s, %s); (params [42, 1337])', ) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index fd818392b0..e1bf438ca3 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -22,7 +22,7 @@ from django.db.transaction import TransactionManagementError, atomic from django.test import ( TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature, ) -from django.test.utils import CaptureQueriesContext, isolate_apps, patch_logger +from django.test.utils import CaptureQueriesContext, isolate_apps from django.utils import timezone from .fields import ( @@ -1573,11 +1573,11 @@ class SchemaTests(TransactionTestCase): new_field = CharField(max_length=255, unique=True) new_field.model = Author new_field.set_attributes_from_name('name') - with patch_logger('django.db.backends.schema', 'debug') as logger_calls: + with self.assertLogs('django.db.backends.schema', 'DEBUG') as cm: with connection.schema_editor() as editor: editor.alter_field(Author, Author._meta.get_field('name'), new_field) - # One SQL statement is executed to alter the field. - self.assertEqual(len(logger_calls), 1) + # One SQL statement is executed to alter the field. + self.assertEqual(len(cm.records), 1) @isolate_apps('schema') @unittest.skipIf(connection.vendor == 'sqlite', 'SQLite remakes the table on field alteration.') @@ -1606,11 +1606,11 @@ class SchemaTests(TransactionTestCase): new_field = SlugField(max_length=75, unique=True) new_field.model = Tag new_field.set_attributes_from_name('slug') - with patch_logger('django.db.backends.schema', 'debug') as logger_calls: + with self.assertLogs('django.db.backends.schema', 'DEBUG') as cm: with connection.schema_editor() as editor: editor.alter_field(Tag, Tag._meta.get_field('slug'), new_field) - # One SQL statement is executed to alter the field. - self.assertEqual(len(logger_calls), 1) + # One SQL statement is executed to alter the field. + self.assertEqual(len(cm.records), 1) # Ensure that the field is still unique. Tag.objects.create(title='foo', slug='foo') with self.assertRaises(IntegrityError): |
