Skip to content

Commit f53dbce

Browse files
committed
intermediate save
1 parent 36849fd commit f53dbce

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

src/odoo_data_flow/lib/preflight.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616

1717
from odoo_data_flow.enums import PreflightMode
1818

19+
__all__ = [
20+
"PREFLIGHT_CHECKS",
21+
"PreflightMode",
22+
"_get_csv_header",
23+
"_get_installed_languages",
24+
"_get_odoo_fields",
25+
"_get_required_languages",
26+
"_handle_missing_languages",
27+
"_validate_header",
28+
"connection_check",
29+
"deferral_and_strategy_check",
30+
"language_check",
31+
"register_check",
32+
"self_referencing_check",
33+
"type_correction_check",
34+
]
35+
1936
from ..logging_config import log
2037
from . import cache, conf_lib, sort
2138
from .actions import language_installer
@@ -221,6 +238,10 @@ def _handle_missing_languages(
221238
log.info("--headless mode detected. Auto-confirming language installation.")
222239
if isinstance(config, dict):
223240
log.error("Language installation from a dict config is not supported.")
241+
_show_error_panel(
242+
"Language installation from a dict config is not supported",
243+
"Please use a configuration file instead.",
244+
)
224245
return False
225246
return language_installer.run_language_installation(
226247
config, list(missing_languages)
@@ -232,6 +253,10 @@ def _handle_missing_languages(
232253

233254
if isinstance(config, dict):
234255
log.error("Language installation from a dict config is not supported.")
256+
_show_error_panel(
257+
"Language installation from a dict config is not supported",
258+
"Please use a configuration file instead.",
259+
)
235260
return False
236261
return language_installer.run_language_installation(config, list(missing_languages))
237262

tests/test_mapper.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import inspect
44
import logging
55
import os
6-
from typing import Any, Callable
6+
from typing import TYPE_CHECKING, Any, Callable
77
from unittest.mock import MagicMock, call, patch
88

99
import httpx
@@ -12,6 +12,9 @@
1212
from odoo_data_flow.lib import mapper
1313
from odoo_data_flow.lib.internal.exceptions import SkippingError
1414

15+
if TYPE_CHECKING:
16+
import pytest_mock
17+
1518
# Import MapperFunc for type hinting in this test file
1619
from odoo_data_flow.lib.mapper import MapperFunc
1720

@@ -70,7 +73,7 @@ def concat_fun(line: LineDict, state: StateDict) -> str:
7073

7174
# --- Pytest Fixtures for Patching ---
7275
@pytest.fixture(autouse=True)
73-
def mock_mapper_dependencies(mocker: MagicMock) -> None:
76+
def mock_mapper_dependencies(mocker: "pytest_mock.MockerFixture") -> None:
7477
"""Fixture to mock external dependencies in mapper.py."""
7578
mocker.patch("odoo_data_flow.lib.mapper.to_m2o", side_effect=_mock_to_m2o)
7679
mocker.patch(
@@ -105,7 +108,7 @@ def test_val_postprocess_builtin() -> None:
105108
assert mapper_func(LINE_SIMPLE, {}) == "a"
106109

107110

108-
def test_val_postprocess_fallback(mocker: MagicMock) -> None:
111+
def test_val_postprocess_fallback(mocker: "pytest_mock.MockerFixture") -> None:
109112
"""Test post process fallback.
110113
111114
Tests the val mapper's fallback from a 2-arg to a 1-arg postprocess call.
@@ -280,7 +283,7 @@ def test_binary_url_map_empty() -> None:
280283
assert mapper_func(LINE_SIMPLE, {}) == ""
281284

282285

283-
def test_binary_url_map_skip_on_not_found(mocker: MagicMock) -> None:
286+
def test_binary_url_map_skip_on_not_found(mocker: "pytest_mock.MockerFixture") -> None:
284287
"""Tests that binary_url_map raises SkippingError when request fails."""
285288
mock_httpx_get = mocker.patch("odoo_data_flow.lib.mapper.httpx.get")
286289
mock_httpx_get.side_effect = httpx.RequestError(
@@ -292,7 +295,7 @@ def test_binary_url_map_skip_on_not_found(mocker: MagicMock) -> None:
292295
mapper_func(LINE_SIMPLE, {})
293296

294297

295-
def test_binary_url_map_request_exception(mocker: MagicMock) -> None:
298+
def test_binary_url_map_request_exception(mocker: "pytest_mock.MockerFixture") -> None:
296299
"""Tests that a warning is logged when a URL request fails and skip=False."""
297300
mock_httpx_get = mocker.patch("odoo_data_flow.lib.mapper.httpx.get")
298301
mock_log_warning = mocker.patch("odoo_data_flow.lib.mapper.log.warning")
@@ -451,7 +454,7 @@ def test_map_val_m2m_with_non_string_key() -> None:
451454
assert mapper_func({}, {}) == "One"
452455

453456

454-
def test_binary_with_path_prefix(mocker: MagicMock) -> None:
457+
def test_binary_with_path_prefix(mocker: "pytest_mock.MockerFixture") -> None:
455458
"""Tests the binary mapper with a path_prefix."""
456459
mock_open = mocker.patch(
457460
"builtins.open", mocker.mock_open(read_data=b"file_content")
@@ -470,7 +473,7 @@ def test_m2o_att_name() -> None:
470473
assert result == {"att1": "prefix.att1", "att3": "prefix.att3"}
471474

472475

473-
def test_m2o_fun_state_present_but_unused(mocker: MagicMock) -> None:
476+
def test_m2o_fun_state_present_but_unused(mocker: "pytest_mock.MockerFixture") -> None:
474477
"""Confirms m2o_fun works correctly when 'state' is provided but not directly used.
475478
476479
Args:
@@ -497,7 +500,7 @@ def test_m2o_fun_state_present_but_unused(mocker: MagicMock) -> None:
497500

498501

499502
def test_m2o_fun_with_skip_and_empty_value_state_unused(
500-
mocker: MagicMock,
503+
mocker: "pytest_mock.MockerFixture",
501504
) -> None:
502505
"""Tests m2o_fun with 'skip' when value is empty, confirming state is unused.
503506
@@ -525,7 +528,9 @@ def test_m2o_fun_with_skip_and_empty_value_state_unused(
525528
assert state == {"initial": "value"}
526529

527530

528-
def test_m2o_map_fun_state_passed_to_concat_mapper(mocker: MagicMock) -> None:
531+
def test_m2o_map_fun_state_passed_to_concat_mapper(
532+
mocker: "pytest_mock.MockerFixture",
533+
) -> None:
529534
"""Test m2o_map state management.
530535
531536
Confirms m2o_map passes 'state' to the underlying concat_mapper and
@@ -556,7 +561,9 @@ def test_m2o_map_fun_state_passed_to_concat_mapper(mocker: MagicMock) -> None:
556561
mock_to_m2o.assert_called_once_with("test_prefix", "John_Doe_APP", default="")
557562

558563

559-
def test_m2o_map_fun_state_modified_by_concat_mapper(mocker: MagicMock) -> None:
564+
def test_m2o_map_fun_state_modified_by_concat_mapper(
565+
mocker: "pytest_mock.MockerFixture",
566+
) -> None:
560567
"""Confirms m2o_map's underlying concat_mapper can modify the state.
561568
562569
Args:
@@ -573,7 +580,7 @@ def test_m2o_map_fun_state_modified_by_concat_mapper(mocker: MagicMock) -> None:
573580

574581

575582
def test_m2o_map_fun_with_skip_and_empty_concat_value_state_passed(
576-
mocker: MagicMock,
583+
mocker: "pytest_mock.MockerFixture",
577584
) -> None:
578585
"""Tests m2o_map.
579586

tests/test_preflight.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_language_check_handles_get_installed_languages_failure(
359359
config="",
360360
headless=False,
361361
)
362-
362+
363363
# Should return False when _get_installed_languages fails
364364
assert result is False
365365
mock_get_langs.assert_called_once_with("")
@@ -492,11 +492,14 @@ def test_language_check_fail_mode_skips_entire_check(
492492
mock_install.assert_not_called()
493493
mock_confirm.assert_not_called()
494494

495-
496-
497495
@patch("odoo_data_flow.lib.preflight.Confirm.ask", return_value=True)
498-
def test_language_check_dict_config_installation_not_supported(
496+
@patch(
497+
"odoo_data_flow.lib.preflight._get_installed_languages",
498+
return_value={"en_US"},
499+
)
500+
def test_language_check_dict_config_installation_not_supported_v2(
499501
self,
502+
mock_get_langs: MagicMock,
500503
mock_confirm: MagicMock,
501504
mock_polars_read_csv: MagicMock,
502505
mock_conf_lib: MagicMock,
@@ -530,6 +533,7 @@ def test_language_check_dict_config_installation_not_supported(
530533
in mock_show_error_panel.call_args[0][0]
531534
)
532535

536+
533537
class TestDeferralAndStrategyCheck:
534538
"""Tests for the deferral_and_strategy_check pre-flight checker."""
535539

0 commit comments

Comments
 (0)