def test_order_export_inherits_global_safety_flags_when_order_flags_are_unset(monkeypatch): from app.modules.orders.backend import economic_export settings = economic_export.settings monkeypatch.setattr(settings, "ECONOMIC_READ_ONLY", False) monkeypatch.setattr(settings, "ECONOMIC_DRY_RUN", False) monkeypatch.setattr(settings, "ORDRE_ECONOMIC_READ_ONLY", True) monkeypatch.setattr(settings, "ORDRE_ECONOMIC_DRY_RUN", True) fields_set = set(settings.model_fields_set) fields_set.discard("ORDRE_ECONOMIC_READ_ONLY") fields_set.discard("ORDRE_ECONOMIC_DRY_RUN") monkeypatch.setattr(settings, "__pydantic_fields_set__", fields_set) service = economic_export.OrdreEconomicExportService() assert service.read_only is False assert service.dry_run is False def test_order_export_respects_explicit_order_safety_flags(monkeypatch): from app.modules.orders.backend import economic_export settings = economic_export.settings monkeypatch.setattr(settings, "ECONOMIC_READ_ONLY", False) monkeypatch.setattr(settings, "ECONOMIC_DRY_RUN", False) monkeypatch.setattr(settings, "ORDRE_ECONOMIC_READ_ONLY", True) monkeypatch.setattr(settings, "ORDRE_ECONOMIC_DRY_RUN", True) fields_set = set(settings.model_fields_set) fields_set.update({"ORDRE_ECONOMIC_READ_ONLY", "ORDRE_ECONOMIC_DRY_RUN"}) monkeypatch.setattr(settings, "__pydantic_fields_set__", fields_set) service = economic_export.OrdreEconomicExportService() assert service.read_only is True assert service.dry_run is True def test_economic_validation_error_is_exposed_without_developer_metadata(): from app.modules.orders.backend.economic_export import _economic_error_message message = _economic_error_message( 400, '{"message":"Validation failed","errors":{"paymentTerms":"Required"},"developerHint":"internal"}', ) assert "Validation failed" in message assert "paymentTerms" in message assert "Required" in message assert "internal" not in message def test_order_export_blocks_priced_line_when_product_does_not_exist(): from fastapi import HTTPException from app.modules.orders.backend.economic_export import _require_valid_product_numbers try: _require_valid_product_numbers({"1000", "UKENDT"}, {"1000"}) assert False, "missing product must block the export before POST" except HTTPException as exc: assert exc.status_code == 409 assert "UKENDT" in exc.detail assert "Ordren blev ikke sendt" in exc.detail def test_order_export_accepts_only_verified_products(): from app.modules.orders.backend.economic_export import _require_valid_product_numbers assert _require_valid_product_numbers({"1000"}, {"1000"}) == []