1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Replaced django.test.utils.patch_logger() with assertLogs().

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz
2018-04-28 15:20:27 +02:00
committed by Tim Graham
parent 7d3fe36c62
commit 607970f31c
13 changed files with 97 additions and 157 deletions

View File

@@ -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):