Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Tervala authored and Justin Tervala committed Mar 12, 2018
2 parents 2fda318 + 4d4ccaa commit a9ab60c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<!-- Use the tags Added, Changed, Deprecated, Removed, Fixed, Security, and
Contributor to describe changes -->

## [0.7.2]
###### 2018-03-12

### Fixed
* An unintentional backward-breaking change was made to the format of the
dictionary used in the interface dispatcher which sometimes resulted in
a dict with a "data" field inside a "data" field. This has been fixed.


## [0.7.1]
###### 2018-03-08

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.7.1.{build}
version: 0.7.2.{build}

branches:
only:
Expand Down
45 changes: 26 additions & 19 deletions interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,37 @@ def _make_dispatch_method(cls, event):

def dispatch_method(sender, **kwargs):
if event.event_type != EventType.controller:
if not isinstance(sender, dict) and isinstance(sender, ExecutionElement):
data = dump_element(sender)
else:
data = deepcopy(sender)
additional_data = deepcopy(kwargs)
additional_data.pop('cls', None)
if 'data' in additional_data and 'workflow' in additional_data['data']:
additional_data['workflow'] = additional_data['data'].pop('workflow')
if not additional_data['data']:
additional_data.pop('data')
data.update(additional_data)
if 'id' in data:
data['sender_id'] = data.pop('id')
if 'name' in data:
data['sender_name'] = data.pop('name')

sender_data = InterfaceEventDispatcher._format_data(sender, kwargs)
else:
data = None
cls.event_dispatcher.dispatch(event, data)
sender_data = None
cls.event_dispatcher.dispatch(event, sender_data)
if event.event_type == EventType.action:
cls.app_action_dispatcher.dispatch(event, data)
cls.app_action_dispatcher.dispatch(event, sender_data)

return dispatch_method

@staticmethod
def _format_data(sender, kwargs):
if not isinstance(sender, dict) and isinstance(sender, ExecutionElement):
sender_data = dump_element(sender)
else:
sender_data = deepcopy(sender)
additional_data = deepcopy(kwargs)
additional_data.pop('cls', None)
if 'data' in additional_data:
if 'workflow' in additional_data['data']:
additional_data['workflow'] = additional_data['data'].pop('workflow')
if 'data' in additional_data['data']:
additional_data['data'] = additional_data['data'].pop('data')
if not additional_data['data']:
additional_data.pop('data')
sender_data.update(additional_data)
if 'id' in sender_data:
sender_data['sender_id'] = sender_data.pop('id')
if 'name' in sender_data:
sender_data['sender_name'] = sender_data.pop('name')
return sender_data

@classmethod
def _make_register_method(cls, event):
"""Constructs a method used by interface event handlers to connect to the dispatcher and register their callbacks
Expand Down
11 changes: 6 additions & 5 deletions tests/test_interface_event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def tearDownClass(cls):
walkoff.config.config.app_apis = {}
walkoff.executiondb.schemas._schema_lookup.pop(MockWorkflow, None)
execution_db_help.tear_down_device_db()

def test_singleton(self):
self.assertEqual(id(dispatcher), id(InterfaceEventDispatcher()))

Expand Down Expand Up @@ -443,11 +443,12 @@ def x(data):
workflow = MockWorkflow()
WalkoffEvent.WorkflowExecutionPending.send(MockWorkflowSchema().dump(workflow).data)

data = {'id': self.id, 'name': 'b', 'device_id': 2, 'app_name': 'App1', 'action_name': 'action1',
'execution_id': uuid.uuid4()}
sender_data = {'id': self.id, 'name': 'b', 'device_id': 2, 'app_name': 'App1', 'action_name': 'action1',
'execution_id': str(uuid.uuid4())}
kwargs = self.get_kwargs(workflow)
WalkoffEvent.ActionStarted.send(data, data=kwargs)
expected = data
kwargs.update({'data': {'a': 42}})
WalkoffEvent.ActionStarted.send(sender_data, data=kwargs)
expected = sender_data
expected.update(kwargs)
expected['sender_id'] = expected.pop('id')
expected['sender_name'] = expected.pop('name')
Expand Down
2 changes: 1 addition & 1 deletion walkoff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.7.1'
__version__ = '0.7.2'


def initialize_databases():
Expand Down

0 comments on commit a9ab60c

Please sign in to comment.