diff options
| author | Simon Charette <charette.s@gmail.com> | 2020-10-04 18:25:29 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-29 22:22:58 +0100 |
| commit | bbe6fbb8768e8fb1aecb96d51c049d7ceaf802d3 (patch) | |
| tree | 7c0e7ac6defc405cd5320066f75ade21bf9943ac /tests/dbshell/test_sqlite.py | |
| parent | 4ac2d4fa42e1659f328c35b6b8d4761b3419c11a (diff) | |
| download | django-bbe6fbb8768e8fb1aecb96d51c049d7ceaf802d3.tar.gz | |
Refs #32061 -- Unified DatabaseClient.runshell() in db backends.
Diffstat (limited to 'tests/dbshell/test_sqlite.py')
| -rw-r--r-- | tests/dbshell/test_sqlite.py | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/tests/dbshell/test_sqlite.py b/tests/dbshell/test_sqlite.py index c3b2b1e28d..570230f62d 100644 --- a/tests/dbshell/test_sqlite.py +++ b/tests/dbshell/test_sqlite.py @@ -1,43 +1,23 @@ from pathlib import Path -from subprocess import CompletedProcess -from unittest import mock, skipUnless -from django.db import connection from django.db.backends.sqlite3.client import DatabaseClient from django.test import SimpleTestCase -@skipUnless(connection.vendor == 'sqlite', 'SQLite tests.') class SqliteDbshellCommandTestCase(SimpleTestCase): - 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) - + def settings_to_cmd_args_env(self, settings_dict, parameters=None): if parameters is None: parameters = [] - client = DatabaseClient(connection) - with mock.patch('subprocess.run', new=_mock_subprocess_run): - client.runshell(parameters) - return self.subprocess_args + return DatabaseClient.settings_to_cmd_args_env(settings_dict, parameters) def test_path_name(self): - with mock.patch.dict( - connection.settings_dict, - {'NAME': Path('test.db.sqlite3')}, - ): - self.assertEqual( - self._run_dbshell(), - ['sqlite3', 'test.db.sqlite3'], - ) + self.assertEqual( + self.settings_to_cmd_args_env({'NAME': Path('test.db.sqlite3')}), + (['sqlite3', 'test.db.sqlite3'], None), + ) 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'], - ) + self.assertEqual( + self.settings_to_cmd_args_env({'NAME': 'test.db.sqlite3'}, ['-help']), + (['sqlite3', 'test.db.sqlite3', '-help'], None), + ) |
