diracx-testing 0.0.1a24__py3-none-any.whl → 0.0.1a25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,18 +72,22 @@ class MockOSDBMixin:
72
72
  yield
73
73
 
74
74
  async def __aenter__(self):
75
- await self._sql_db.__aenter__()
75
+ """Enter the request context.
76
+
77
+ This is a no-op as the real OpenSearch class doesn't use transactions.
78
+ Instead we enter a transaction in each method that needs it.
79
+ """
76
80
  return self
77
81
 
78
82
  async def __aexit__(self, exc_type, exc_value, traceback):
79
- await self._sql_db.__aexit__(exc_type, exc_value, traceback)
83
+ pass
80
84
 
81
85
  async def create_index_template(self) -> None:
82
86
  async with self._sql_db.engine.begin() as conn:
83
87
  await conn.run_sync(self._sql_db.metadata.create_all)
84
88
 
85
89
  async def upsert(self, doc_id, document) -> None:
86
- async with self:
90
+ async with self._sql_db:
87
91
  values = {}
88
92
  for key, value in document.items():
89
93
  if key in self.fields:
@@ -106,7 +110,7 @@ class MockOSDBMixin:
106
110
  per_page: int = 100,
107
111
  page: int | None = None,
108
112
  ) -> tuple[int, list[dict[Any, Any]]]:
109
- async with self:
113
+ async with self._sql_db:
110
114
  # Apply selection
111
115
  if parameters:
112
116
  columns = []
@@ -150,7 +154,8 @@ class MockOSDBMixin:
150
154
  return results
151
155
 
152
156
  async def ping(self):
153
- return await self._sql_db.ping()
157
+ async with self._sql_db:
158
+ return await self._sql_db.ping()
154
159
 
155
160
 
156
161
  def fake_available_osdb_implementations(name, *, real_available_implementations):
diracx/testing/utils.py CHANGED
@@ -252,6 +252,7 @@ class ClientFactory:
252
252
  assert (
253
253
  self.app.dependency_overrides == {} and self.app.lifetime_functions == []
254
254
  ), "configure cannot be nested"
255
+
255
256
  for k, v in self.all_dependency_overrides.items():
256
257
 
257
258
  class_name = k.__self__.__name__
@@ -284,17 +285,26 @@ class ClientFactory:
284
285
  import sqlalchemy
285
286
  from sqlalchemy.util.concurrency import greenlet_spawn
286
287
 
288
+ from diracx.db.os.utils import BaseOSDB
287
289
  from diracx.db.sql.utils import BaseSQLDB
290
+ from diracx.testing.mock_osdb import MockOSDBMixin
288
291
 
289
292
  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__,
294
297
  ):
298
+
295
299
  continue
300
+
296
301
  # The first argument of the overridden BaseSQLDB.transaction is the DB object
297
302
  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
+
298
308
  assert isinstance(db, BaseSQLDB), (k, db)
299
309
 
300
310
  # set PRAGMA foreign_keys=ON if sqlite
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: diracx-testing
3
- Version: 0.0.1a24
3
+ Version: 0.0.1a25
4
4
  Summary: TODO
5
5
  License: GPL-3.0-only
6
6
  Classifier: Intended Audience :: Science/Research
@@ -1,11 +1,11 @@
1
1
  diracx/testing/__init__.py,sha256=nGbnGP8m53N9rqHR-hyqDa5vetcsmnQp806HadV6_dE,984
2
2
  diracx/testing/dummy_osdb.py,sha256=bNk3LF8KgMuQx3RVFNYuw4hMmpG2A80sZ58rEZqHo7M,907
3
3
  diracx/testing/entrypoints.py,sha256=MbH0VLUQz96XPdHzb7XWFwYtWEitAqPrrGM1H1FzDLo,2231
4
- diracx/testing/mock_osdb.py,sha256=SCpiC0HnsBL2UZMrmybG060A2jvlhDXNcLQ4KgdCSQ4,5873
4
+ diracx/testing/mock_osdb.py,sha256=hHuvmQZ3212SaSGX11dQv4ki3ZWsmqJZFYwdn6kg2MA,6029
5
5
  diracx/testing/osdb.py,sha256=m6mUBLnGOoQLTCIBie9P2GhmLMybrgzIrlIYfhF1_Ss,3230
6
6
  diracx/testing/routers.py,sha256=UW-TnikMQgcNxF5sUZD5DWoucGiCpP6s8mYmuahDiSc,979
7
- diracx/testing/utils.py,sha256=5NRQhWre34dIhhTccBI1IICz2lPdxvEpbpq4jb_wKZw,23694
8
- diracx_testing-0.0.1a24.dist-info/METADATA,sha256=MYbR38ttL5UcXNqhmh0Q-8fWlnhqWDVXH1k9ImIfpTI,613
9
- diracx_testing-0.0.1a24.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- diracx_testing-0.0.1a24.dist-info/top_level.txt,sha256=vJx10tdRlBX3rF2Psgk5jlwVGZNcL3m_7iQWwgPXt-U,7
11
- diracx_testing-0.0.1a24.dist-info/RECORD,,
7
+ diracx/testing/utils.py,sha256=Ak0lzWKXgB4Q9oIqr4a3x1IZ6KO9vX8TSeeld8rid7c,24032
8
+ diracx_testing-0.0.1a25.dist-info/METADATA,sha256=5Jottro46jEDYowuLkmLS8P5FvEobp6iS46c45NjJ_I,613
9
+ diracx_testing-0.0.1a25.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ diracx_testing-0.0.1a25.dist-info/top_level.txt,sha256=vJx10tdRlBX3rF2Psgk5jlwVGZNcL3m_7iQWwgPXt-U,7
11
+ diracx_testing-0.0.1a25.dist-info/RECORD,,