Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workaround for old astarte versions #191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading