Skip to content

Commit

Permalink
tests: Set up opensearch DBs in ClientFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen authored and chrisburr committed Jan 16, 2025
1 parent 2bf4e28 commit 4d40913
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions diracx-testing/src/diracx/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def configure(self, enabled_dependencies):
assert (
self.app.dependency_overrides == {} and self.app.lifetime_functions == []
), "configure cannot be nested"

for k, v in self.all_dependency_overrides.items():

class_name = k.__self__.__name__
Expand Down Expand Up @@ -284,17 +285,26 @@ async def create_db_schemas(self):
import sqlalchemy
from sqlalchemy.util.concurrency import greenlet_spawn

from diracx.db.os.utils import BaseOSDB
from diracx.db.sql.utils import BaseSQLDB
from diracx.testing.mock_osdb import MockOSDBMixin

for k, v in self.app.dependency_overrides.items():
# Ignore dependency overrides which aren't BaseSQLDB.transaction
if (
isinstance(v, UnavailableDependency)
or k.__func__ != BaseSQLDB.transaction.__func__
# Ignore dependency overrides which aren't BaseSQLDB.transaction or BaseOSDB.session
if isinstance(v, UnavailableDependency) or k.__func__ not in (
BaseSQLDB.transaction.__func__,
BaseOSDB.session.__func__,
):

continue

# The first argument of the overridden BaseSQLDB.transaction is the DB object
db = v.args[0]
# We expect the OS DB to be mocked with sqlite, so use the
# internal DB
if isinstance(db, MockOSDBMixin):
db = db._sql_db

assert isinstance(db, BaseSQLDB), (k, db)

# set PRAGMA foreign_keys=ON if sqlite
Expand Down

0 comments on commit 4d40913

Please sign in to comment.