| 1 |
from unittest import mock |
| 2 |
|
| 3 |
from django.db import connection |
| 4 |
from django.db.backends.base.client import BaseDatabaseClient |
| 5 |
from django.test import SimpleTestCase |
| 6 |
|
| 7 |
|
| 8 |
class SimpleDatabaseClientTests(SimpleTestCase): |
| 9 |
def setUp(self): |
| 10 |
self.client = BaseDatabaseClient(connection=connection) |
| 11 |
|
| 12 |
def test_settings_to_cmd_args_env(self): |
| 13 |
msg = ( |
| 14 |
"subclasses of BaseDatabaseClient must provide a " |
| 15 |
"settings_to_cmd_args_env() method or override a runshell()." |
| 16 |
) |
| 17 |
with self.assertRaisesMessage(NotImplementedError, msg): |
| 18 |
self.client.settings_to_cmd_args_env(None, None) |
| 19 |
|
| 20 |
def test_runshell_use_environ(self): |
| 21 |
for env in [None, {}]: |
| 22 |
with self.subTest(env=env): |
| 23 |
with mock.patch("subprocess.run") as run: |
| 24 |
with mock.patch.object( |
| 25 |
BaseDatabaseClient, |
| 26 |
"settings_to_cmd_args_env", |
| 27 |
return_value=([], env), |
| 28 |
): |
| 29 |
self.client.runshell(None) |
| 30 |
run.assert_called_once_with([], env=None, check=True) |