Skip to content

Commit

Permalink
Merge pull request #191 from sorru94/remove-workaround-for-old-Astart…
Browse files Browse the repository at this point in the history
…e-versions

Remove workaround for old astarte versions
  • Loading branch information
harlem88 authored Sep 9, 2024
2 parents b46ec43 + 67495a7 commit 32be4ae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
14 changes: 1 addition & 13 deletions astarte/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ def __init__(self):
self._on_data_received: Callable[[Device, str, str, object], None] | None = None
self._on_disconnected: Callable[[Device, int], None] | None = None
self._loop = None
self._disable_receive_validation = False

def disable_receive_validation(self):
"""
Disable validation for the message reception.
N.B. This is a temporary workaround specifically designed to bypass bugs in Astarte core.
It should not be used carelessly.
See: https://github.com/astarte-platform/astarte-device-sdk-python/issues/136
"""
self._disable_receive_validation = True

@abstractmethod
def add_interface_from_json(self, interface_json: dict):
Expand Down Expand Up @@ -442,7 +430,7 @@ def _on_message_generic(self, interface_name, path, payload):
return

# Check the payload matches with the interface
if payload and not self._disable_receive_validation:
if payload:
try:
interface.validate_payload(path, payload)
except ValidationError as val_err:
Expand Down
27 changes: 0 additions & 27 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,33 +640,6 @@ def test_device_on_message_generic(self, mock_get_interface, _store_property):
device, interface_name, interface_path, mock_message
)

@mock.patch.multiple(Device, __abstractmethods__=set(), _store_property=mock.DEFAULT)
@mock.patch.object(Introspection, "get_interface")
def test_device_on_message_generic_no_validation(self, mock_get_interface, _store_property):
device = Device()
device.disable_receive_validation()

on_data_received_mock = mock.MagicMock()
device.set_events_callbacks(on_data_received=on_data_received_mock)
interface_name = "interface name"
interface_path = "interface path"
mock_message = mock.MagicMock()
device._on_message_generic(interface_name, interface_path, mock_message)

mock_get_interface.assert_called_once_with(interface_name)
mock_get_interface.return_value.is_server_owned.assert_called_once()
mock_get_interface.return_value.is_property_endpoint_resettable.assert_not_called()
mock_get_interface.return_value.validate_path.assert_called_once_with(
interface_path, mock_message
)
mock_get_interface.return_value.validate_payload.assert_not_called()
_store_property.assert_called_once_with(
mock_get_interface.return_value, interface_path, mock_message
)
on_data_received_mock.assert_called_once_with(
device, interface_name, interface_path, mock_message
)

@mock.patch.multiple(Device, __abstractmethods__=set(), _store_property=mock.DEFAULT)
@mock.patch.object(Introspection, "get_interface")
def test_device_on_message_generic_with_threading(self, mock_get_interface, _store_property):
Expand Down

0 comments on commit 32be4ae

Please sign in to comment.