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

Set data_converter for activity types #4

Merged
merged 1 commit into from
Oct 28, 2016
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
5 changes: 3 additions & 2 deletions botoflow/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ def _activities(cls):
if hasattr(_func, 'swf_options'): # decorated
_set_swf_options(_func, 'activity_name_prefix',
activity_name_prefix)
_set_swf_options(_func, 'data_converter',
data_converter)

activity_type = _func.swf_options['activity_type']

if data_converter is not None:
activity_type.data_converter = data_converter

activity_type._set_activities_value(
'task_list', task_list)
activity_type._set_activities_value(
Expand Down
25 changes: 25 additions & 0 deletions test/unit/test_decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from botoflow import activities, activity
from botoflow.data_converter.json_data_converter import JSONDataConverter


def test_activities_decorator_adds_data_converter():
class MyDataConverter(object):
pass

@activities(data_converter=MyDataConverter())
class ActivitiesWithCustomDataConverter(object):
@activity(None)
def foobar(self):
pass

assert isinstance(ActivitiesWithCustomDataConverter().foobar.swf_options['activity_type'].data_converter, MyDataConverter)


def test_activities_decorator_uses_default_data_converter():
@activities()
class ActivitiesWithDefaultDataConverter(object):
@activity(None)
def foobar(self):
pass

assert isinstance(ActivitiesWithDefaultDataConverter().foobar.swf_options['activity_type'].data_converter, JSONDataConverter)