Skip to content

Commit 4d40913

Browse files
chaenchrisburr
authored andcommitted
tests: Set up opensearch DBs in ClientFactory
1 parent 2bf4e28 commit 4d40913

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • diracx-testing/src/diracx/testing

diracx-testing/src/diracx/testing/utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def configure(self, enabled_dependencies):
252252
assert (
253253
self.app.dependency_overrides == {} and self.app.lifetime_functions == []
254254
), "configure cannot be nested"
255+
255256
for k, v in self.all_dependency_overrides.items():
256257

257258
class_name = k.__self__.__name__
@@ -284,17 +285,26 @@ async def create_db_schemas(self):
284285
import sqlalchemy
285286
from sqlalchemy.util.concurrency import greenlet_spawn
286287

288+
from diracx.db.os.utils import BaseOSDB
287289
from diracx.db.sql.utils import BaseSQLDB
290+
from diracx.testing.mock_osdb import MockOSDBMixin
288291

289292
for k, v in self.app.dependency_overrides.items():
290-
# Ignore dependency overrides which aren't BaseSQLDB.transaction
291-
if (
292-
isinstance(v, UnavailableDependency)
293-
or k.__func__ != BaseSQLDB.transaction.__func__
293+
# Ignore dependency overrides which aren't BaseSQLDB.transaction or BaseOSDB.session
294+
if isinstance(v, UnavailableDependency) or k.__func__ not in (
295+
BaseSQLDB.transaction.__func__,
296+
BaseOSDB.session.__func__,
294297
):
298+
295299
continue
300+
296301
# The first argument of the overridden BaseSQLDB.transaction is the DB object
297302
db = v.args[0]
303+
# We expect the OS DB to be mocked with sqlite, so use the
304+
# internal DB
305+
if isinstance(db, MockOSDBMixin):
306+
db = db._sql_db
307+
298308
assert isinstance(db, BaseSQLDB), (k, db)
299309

300310
# set PRAGMA foreign_keys=ON if sqlite

0 commit comments

Comments
 (0)