Skip to content

Commit b1814f1

Browse files
committed
Add infrastructure for supporting multi-DB tests
1 parent 6ec4b0c commit b1814f1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tests/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import html5lib
22
from asgiref.local import Local
33
from django.http import HttpResponse
4-
from django.test import Client, RequestFactory, TestCase
4+
from django.test import Client, RequestFactory, TestCase, TransactionTestCase
55

66
from debug_toolbar.toolbar import DebugToolbar
77

@@ -29,7 +29,7 @@ def handle_toolbar_created(sender, toolbar=None, **kwargs):
2929
rf = RequestFactory()
3030

3131

32-
class BaseTestCase(TestCase):
32+
class BaseMixin:
3333
client_class = ToolbarTestClient
3434

3535
panel_id = None
@@ -67,6 +67,14 @@ def assertValidHTML(self, content):
6767
raise self.failureException("\n".join(msg_parts))
6868

6969

70+
class BaseTestCase(BaseMixin, TestCase):
71+
pass
72+
73+
74+
class BaseMultiDBTestCase(BaseMixin, TransactionTestCase):
75+
databases = {"default", "replica"}
76+
77+
7078
class IntegrationTestCase(TestCase):
7179
"""Base TestCase for tests involving clients making requests."""
7280

tests/settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@
104104
"USER": "default_test",
105105
},
106106
},
107+
"replica": {
108+
"ENGINE": "django.{}db.backends.{}".format(
109+
"contrib.gis." if USE_GIS else "", os.getenv("DB_BACKEND", "sqlite3")
110+
),
111+
"NAME": os.getenv("DB_NAME", ":memory:"),
112+
"USER": os.getenv("DB_USER"),
113+
"PASSWORD": os.getenv("DB_PASSWORD"),
114+
"HOST": os.getenv("DB_HOST", ""),
115+
"PORT": os.getenv("DB_PORT", ""),
116+
"TEST": {
117+
"USER": "default_test",
118+
"MIRROR": "default",
119+
},
120+
},
107121
}
108122

109123
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

0 commit comments

Comments
 (0)