feat(gateway): safe type converter (1879 BUG-1/BUG-2)

This commit is contained in:
PedroHMCosme
2026-07-13 18:31:07 -03:00
parent 3dd4f60b0e
commit 55f67216ee
2 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import pytest
from ingestor.converters import ConversionError, to_typed_value
@pytest.mark.parametrize('raw,expected', [
('false', False), ('False', False), ('0', False), ('no', False),
('off', False), ('', False), ('true', True), ('1', True), (True, True),
])
def test_bool_from_json_string(raw, expected):
assert to_typed_value(raw, 'boolean') is expected
def test_float_and_int():
assert to_typed_value('42.5', 'float') == 42.5
assert to_typed_value('7', 'int') == 7
@pytest.mark.parametrize('raw,dtype', [
(None, 'int'), ('abc', 'float'), ('123.123', 'int'), (None, 'float'),
])
def test_invalid_raises_conversion_error(raw, dtype):
with pytest.raises(ConversionError):
to_typed_value(raw, dtype)