Skip to content

Commit 07d2045

Browse files
bosdbosd
authored andcommitted
[IMP] Improve importer coverage
1 parent ea37f72 commit 07d2045

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_importer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,33 @@ def test_run_import_bad_context_string(
9494
filename=str(source_file),
9595
model="res.partner",
9696
context="this-is-not-a-dict",
97+
separator=",",
9798
)
9899
mock_log_error.assert_called_once()
99100
assert "Invalid context provided" in mock_log_error.call_args[0][0]
100101

101102

103+
@patch("odoo_data_flow.importer.log.error")
104+
def test_run_import_context_not_a_dict(
105+
mock_log_error: MagicMock, tmp_path: Path
106+
) -> None:
107+
"""Tests that an error is logged if the context string is not a dictionary."""
108+
# Setup: Create a dummy file to get past the file-read stage
109+
source_file = tmp_path / "data.csv"
110+
source_file.write_text("id,name\n1,test")
111+
112+
# This context is a valid Python literal, but it's a list, not a dict.
113+
run_import(
114+
config="dummy.conf",
115+
filename=str(source_file),
116+
model="res.partner",
117+
context="['not', 'a', 'dict']",
118+
separator=",",
119+
)
120+
mock_log_error.assert_called_once()
121+
assert "Context must be a dictionary" in mock_log_error.call_args[0][0]
122+
123+
102124
@patch("odoo_data_flow.importer.import_threaded.import_data")
103125
def test_run_import_for_migration(mock_import_data: MagicMock) -> None:
104126
"""Tests the in-memory import runner used for migrations."""

0 commit comments

Comments
 (0)