Skip to content

Commit 47a0aae

Browse files
author
Sergio García Prado
committed
ISSUE #98
* Raise a `MinosConfigException` when requested database does not exist.
1 parent 405f31f commit 47a0aae

File tree

3 files changed

+8
-31
lines changed

3 files changed

+8
-31
lines changed

packages/core/minos-microservice-common/minos/common/config/abc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,21 @@ def get_default_database(self):
145145
146146
:return: A ``dict`` containing the database's config values.
147147
"""
148-
return self.get_database_by_name("default")
148+
return self.get_database_by_name(None)
149149

150-
def get_database_by_name(self, name: str) -> dict[str, Any]:
150+
def get_database_by_name(self, name: Optional[str]) -> dict[str, Any]:
151151
"""Get the database value by name.
152152
153153
:param name: The name of the database. If ``None`` is provided then the default database will be used.
154154
:return: A ``dict`` containing the database's config values.
155155
"""
156+
if name is None:
157+
name = "default"
158+
156159
databases = self.get_databases()
157160

158161
if name not in databases:
159-
name = "default"
162+
raise MinosConfigException(f"{name!r} database is not configured")
160163

161164
return databases[name]
162165

packages/core/minos-microservice-common/tests/test_common/test_config/test_abc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def test_get_database_unknown(self):
147147
mock = MagicMock(return_value={"default": "foo"})
148148
self.config._get_databases = mock
149149

150-
self.assertEqual("foo", self.config.get_database_by_name("unknown"))
150+
with self.assertRaises(MinosConfigException):
151+
self.config.get_database_by_name("unknown")
151152

152153
self.assertEqual([call()], mock.call_args_list)
153154

packages/core/minos-microservice-common/tests/test_common/test_config/test_v2/test_base.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ def test_database_default(self):
191191
self.assertEqual("localhost", database_config["host"])
192192
self.assertEqual(5432, database_config["port"])
193193

194-
def test_database_event(self):
195-
config = ConfigV2(self.file_path, with_environment=False)
196-
database_config = config.get_database_by_name("event")
197-
self.assertEqual("order_db", database_config["database"])
198-
self.assertEqual("minos", database_config["user"])
199-
self.assertEqual("min0s", database_config["password"])
200-
self.assertEqual("localhost", database_config["host"])
201-
self.assertEqual(5432, database_config["port"])
202-
203194
def test_database_query(self):
204195
config = ConfigV2(self.file_path, with_environment=False)
205196
query_database = config.get_database_by_name("query")
@@ -209,24 +200,6 @@ def test_database_query(self):
209200
self.assertEqual("localhost", query_database["host"])
210201
self.assertEqual(5432, query_database["port"])
211202

212-
def test_database_snapshot(self):
213-
config = ConfigV2(self.file_path, with_environment=False)
214-
snapshot = config.get_database_by_name("snapshot")
215-
self.assertEqual("order_db", snapshot["database"])
216-
self.assertEqual("minos", snapshot["user"])
217-
self.assertEqual("min0s", snapshot["password"])
218-
self.assertEqual("localhost", snapshot["host"])
219-
self.assertEqual(5432, snapshot["port"])
220-
221-
def test_database_broker(self):
222-
config = ConfigV2(self.file_path, with_environment=False)
223-
snapshot = config.get_database_by_name("broker")
224-
self.assertEqual("order_db", snapshot["database"])
225-
self.assertEqual("minos", snapshot["user"])
226-
self.assertEqual("min0s", snapshot["password"])
227-
self.assertEqual("localhost", snapshot["host"])
228-
self.assertEqual(5432, snapshot["port"])
229-
230203
def test_database_saga(self):
231204
config = ConfigV2(self.file_path, with_environment=False)
232205
saga = config.get_database_by_name("saga")

0 commit comments

Comments
 (0)