| 1 |
import copy |
| 2 |
import multiprocessing |
| 3 |
import unittest |
| 4 |
from unittest import mock |
| 5 |
|
| 6 |
from django.db import DEFAULT_DB_ALIAS, NotSupportedError, connection, connections |
| 7 |
from django.test import SimpleTestCase |
| 8 |
|
| 9 |
|
| 10 |
@unittest.skipUnless(connection.vendor == "sqlite", "SQLite tests") |
| 11 |
class TestDbSignatureTests(SimpleTestCase): |
| 12 |
def test_custom_test_name(self): |
| 13 |
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS]) |
| 14 |
test_connection.settings_dict = copy.deepcopy( |
| 15 |
connections[DEFAULT_DB_ALIAS].settings_dict |
| 16 |
) |
| 17 |
test_connection.settings_dict["NAME"] = None |
| 18 |
test_connection.settings_dict["TEST"]["NAME"] = "custom.sqlite.db" |
| 19 |
signature = test_connection.creation_class(test_connection).test_db_signature() |
| 20 |
self.assertEqual(signature, (None, "custom.sqlite.db")) |
| 21 |
|
| 22 |
def test_get_test_db_clone_settings_name(self): |
| 23 |
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS]) |
| 24 |
test_connection.settings_dict = copy.deepcopy( |
| 25 |
connections[DEFAULT_DB_ALIAS].settings_dict, |
| 26 |
) |
| 27 |
tests = [ |
| 28 |
("test.sqlite3", "test_1.sqlite3"), |
| 29 |
("test", "test_1"), |
| 30 |
] |
| 31 |
for test_db_name, expected_clone_name in tests: |
| 32 |
with self.subTest(test_db_name=test_db_name): |
| 33 |
test_connection.settings_dict["NAME"] = test_db_name |
| 34 |
test_connection.settings_dict["TEST"]["NAME"] = test_db_name |
| 35 |
creation_class = test_connection.creation_class(test_connection) |
| 36 |
clone_settings_dict = creation_class.get_test_db_clone_settings("1") |
| 37 |
self.assertEqual(clone_settings_dict["NAME"], expected_clone_name) |
| 38 |
|
| 39 |
@mock.patch.object(multiprocessing, "get_start_method", return_value="forkserver") |
| 40 |
def test_get_test_db_clone_settings_not_supported(self, *mocked_objects): |
| 41 |
msg = "Cloning with start method 'forkserver' is not supported." |
| 42 |
with self.assertRaisesMessage(NotSupportedError, msg): |
| 43 |
connection.creation.get_test_db_clone_settings(1) |