Skip to content

Commit a112c1e

Browse files
author
bosd
committed
[IMP]: Coverage of conf_lib
1 parent c041e05 commit a112c1e

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

tests/test_conf_lib.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
"""Test the converter.
2-
3-
This test script generates data for the image converter functions
4-
to be used in the main test suite.
5-
"""
1+
"""Test the configuration file handling."""
62

73
from pathlib import Path
84
from unittest.mock import MagicMock, patch
@@ -91,3 +87,27 @@ def test_get_connection_malformed_value(tmp_path: Path) -> None:
9187

9288
with pytest.raises(ValueError):
9389
get_connection_from_config(str(config_file))
90+
91+
92+
@patch("odoo_data_flow.lib.conf_lib.odoolib.get_connection")
93+
def test_get_connection_generic_exception(
94+
mock_get_connection: MagicMock, tmp_path: Path
95+
) -> None:
96+
"""Tests that a generic Exception during connection is caught and re-raised."""
97+
# 1. Setup: Create a valid config file
98+
config_file = tmp_path / "connection.conf"
99+
config_content = """
100+
[Connection]
101+
hostname = test-server
102+
database = test-db
103+
login = test-user
104+
password = test-pass
105+
"""
106+
config_file.write_text(config_content)
107+
108+
# Configure the mock to raise a generic exception
109+
mock_get_connection.side_effect = Exception("A generic connection error occurred")
110+
111+
# 2. Action & Assertions
112+
with pytest.raises(Exception, match="A generic connection error occurred"):
113+
get_connection_from_config(str(config_file))

0 commit comments

Comments
 (0)