1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #29501 -- Allowed dbshell to pass options to underlying tool.

This commit is contained in:
Adam Johnson
2020-04-14 08:56:40 +01:00
parent 8e8c3f964e
commit 5b884d45ac
13 changed files with 117 additions and 21 deletions

View File

@@ -9,15 +9,17 @@ from django.test import SimpleTestCase
@skipUnless(connection.vendor == 'sqlite', 'SQLite tests.')
class SqliteDbshellCommandTestCase(SimpleTestCase):
def _run_dbshell(self):
def _run_dbshell(self, parameters=None):
"""Run runshell command and capture its arguments."""
def _mock_subprocess_run(*args, **kwargs):
self.subprocess_args = list(*args)
return CompletedProcess(self.subprocess_args, 0)
if parameters is None:
parameters = []
client = DatabaseClient(connection)
with mock.patch('subprocess.run', new=_mock_subprocess_run):
client.runshell()
client.runshell(parameters)
return self.subprocess_args
def test_path_name(self):
@@ -29,3 +31,13 @@ class SqliteDbshellCommandTestCase(SimpleTestCase):
self._run_dbshell(),
['sqlite3', 'test.db.sqlite3'],
)
def test_parameters(self):
with mock.patch.dict(
connection.settings_dict,
{'NAME': Path('test.db.sqlite3')},
):
self.assertEqual(
self._run_dbshell(['-help']),
['sqlite3', 'test.db.sqlite3', '-help'],
)