Skip to content

Commit 16fd5b7

Browse files
feat: add get_default_engine method for the database (#197)
Co-authored-by: Eric Ford <[email protected]>
1 parent ae1d7c7 commit 16fd5b7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/firebolt/model/database.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,16 @@ class _DatabaseUpdateRequest(FireboltBaseModel):
164164
return Database.parse_obj_with_service(
165165
response.json()["database"], self._service
166166
)
167+
168+
def get_default_engine(self) -> Optional[Engine]:
169+
"""
170+
Returns: default engine of the database, or None if default engine is missing
171+
"""
172+
rm = self._service.resource_manager
173+
default_engines = [
174+
rm.engines.get(binding.engine_id)
175+
for binding in rm.bindings.get_many(database_id=self.database_id)
176+
if binding.is_default_engine
177+
]
178+
179+
return None if len(default_engines) == 0 else default_engines[0]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from firebolt.common import Settings
2+
from firebolt.service.manager import ResourceManager
3+
4+
5+
def test_database_get_default_engine(
6+
rm_settings: Settings,
7+
database_name: str,
8+
stopped_engine_name: str,
9+
engine_name: str,
10+
):
11+
"""
12+
Checks that the default engine is either running or stopped engine
13+
"""
14+
rm = ResourceManager(rm_settings)
15+
16+
db = rm.databases.get_by_name(database_name)
17+
18+
engine = db.get_default_engine()
19+
assert engine is not None, "default engine is None, but shouldn't"
20+
assert engine.name in [
21+
stopped_engine_name,
22+
engine_name,
23+
], "Returned default engine name is neither of known engines"

0 commit comments

Comments
 (0)