diracx-testing 0.0.1a24__py3-none-any.whl → 0.0.1a25__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- diracx/testing/mock_osdb.py +10 -5
- diracx/testing/utils.py +14 -4
- {diracx_testing-0.0.1a24.dist-info → diracx_testing-0.0.1a25.dist-info}/METADATA +1 -1
- {diracx_testing-0.0.1a24.dist-info → diracx_testing-0.0.1a25.dist-info}/RECORD +6 -6
- {diracx_testing-0.0.1a24.dist-info → diracx_testing-0.0.1a25.dist-info}/WHEEL +0 -0
- {diracx_testing-0.0.1a24.dist-info → diracx_testing-0.0.1a25.dist-info}/top_level.txt +0 -0
diracx/testing/mock_osdb.py
CHANGED
@@ -72,18 +72,22 @@ class MockOSDBMixin:
|
|
72
72
|
yield
|
73
73
|
|
74
74
|
async def __aenter__(self):
|
75
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
293
|
-
|
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,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=
|
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=
|
8
|
-
diracx_testing-0.0.
|
9
|
-
diracx_testing-0.0.
|
10
|
-
diracx_testing-0.0.
|
11
|
-
diracx_testing-0.0.
|
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,,
|
File without changes
|
File without changes
|