Fixed #21255 -- Closed connections after management command ran

Thanks kabakov.as@gmail.com for the report, and Aymeric Augustin,
Simon Charette for the reviews.
This commit is contained in:
Claude Paroz 2014-12-28 18:10:12 +01:00
parent bae404dea3
commit 1d24f073e6
4 changed files with 27 additions and 1 deletions

View file

@ -25,7 +25,7 @@ from django.core.management import BaseCommand, CommandError, call_command, colo
from django.utils.encoding import force_text
from django.utils._os import npath, upath
from django.utils.six import StringIO
from django.test import LiveServerTestCase, TestCase, override_settings
from django.test import LiveServerTestCase, TestCase, mock, override_settings
from django.test.runner import DiscoverRunner
@ -1581,6 +1581,18 @@ class CommandTypes(AdminScriptTestCase):
with self.assertRaises(SystemExit):
command.run_from_argv(['', ''])
def test_run_from_argv_closes_connections(self):
"""
A command called from the command line should close connections after
being executed (#21255).
"""
command = BaseCommand(stderr=StringIO())
command.handle = lambda *args, **kwargs: args
with mock.patch('django.core.management.base.connections') as mock_connections:
command.run_from_argv(['', ''])
# Test connections have been closed
self.assertTrue(mock_connections.close_all.called)
def test_noargs(self):
"NoArg Commands can be executed"
args = ['noargs_command']