2019-11-20 17:37:10 +00:00
|
|
|
import copy
|
2022-02-12 20:40:12 +00:00
|
|
|
import multiprocessing
|
2019-11-20 17:37:10 +00:00
|
|
|
import unittest
|
2022-02-12 20:40:12 +00:00
|
|
|
from unittest import mock
|
2019-11-20 17:37:10 +00:00
|
|
|
|
2022-02-12 20:40:12 +00:00
|
|
|
from django.db import DEFAULT_DB_ALIAS, NotSupportedError, connection, connections
|
2019-11-20 17:37:10 +00:00
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@unittest.skipUnless(connection.vendor == "sqlite", "SQLite tests")
|
2019-11-20 17:37:10 +00:00
|
|
|
class TestDbSignatureTests(SimpleTestCase):
|
|
|
|
def test_custom_test_name(self):
|
2019-12-31 11:09:50 +00:00
|
|
|
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS])
|
2022-02-03 19:24:19 +00:00
|
|
|
test_connection.settings_dict = copy.deepcopy(
|
|
|
|
connections[DEFAULT_DB_ALIAS].settings_dict
|
|
|
|
)
|
|
|
|
test_connection.settings_dict["NAME"] = None
|
|
|
|
test_connection.settings_dict["TEST"]["NAME"] = "custom.sqlite.db"
|
2019-12-31 11:09:50 +00:00
|
|
|
signature = test_connection.creation_class(test_connection).test_db_signature()
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(signature, (None, "custom.sqlite.db"))
|
2021-03-25 05:37:01 +00:00
|
|
|
|
|
|
|
def test_get_test_db_clone_settings_name(self):
|
|
|
|
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS])
|
|
|
|
test_connection.settings_dict = copy.deepcopy(
|
|
|
|
connections[DEFAULT_DB_ALIAS].settings_dict,
|
|
|
|
)
|
|
|
|
tests = [
|
2022-02-03 19:24:19 +00:00
|
|
|
("test.sqlite3", "test_1.sqlite3"),
|
|
|
|
("test", "test_1"),
|
2021-03-25 05:37:01 +00:00
|
|
|
]
|
|
|
|
for test_db_name, expected_clone_name in tests:
|
|
|
|
with self.subTest(test_db_name=test_db_name):
|
2022-02-03 19:24:19 +00:00
|
|
|
test_connection.settings_dict["NAME"] = test_db_name
|
|
|
|
test_connection.settings_dict["TEST"]["NAME"] = test_db_name
|
2021-03-25 05:37:01 +00:00
|
|
|
creation_class = test_connection.creation_class(test_connection)
|
2022-02-03 19:24:19 +00:00
|
|
|
clone_settings_dict = creation_class.get_test_db_clone_settings("1")
|
|
|
|
self.assertEqual(clone_settings_dict["NAME"], expected_clone_name)
|
2022-02-12 20:40:12 +00:00
|
|
|
|
|
|
|
@mock.patch.object(multiprocessing, "get_start_method", return_value="forkserver")
|
|
|
|
def test_get_test_db_clone_settings_not_supported(self, *mocked_objects):
|
|
|
|
msg = "Cloning with start method 'forkserver' is not supported."
|
|
|
|
with self.assertRaisesMessage(NotSupportedError, msg):
|
|
|
|
connection.creation.get_test_db_clone_settings(1)
|