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

Aggregate dupe keys into a list in datapipeline translation #750

Merged
merged 1 commit into from
Apr 10, 2014
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
10 changes: 9 additions & 1 deletion awscli/customizations/datapipeline/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def api_to_definition(api_response):
value = field['stringValue']
else:
value = {'ref': field['refValue']}
current[key] = value
if key not in current:
current[key] = value
elif isinstance(current[key], list):
# Dupe keys result in values aggregating
# into a list.
current[key].append(value)
else:
converted_list = [current[key], value]
current[key] = converted_list
pipeline_objs.append(current)
return {'objects': pipeline_objs}
19 changes: 19 additions & 0 deletions tests/unit/customizations/datapipeline/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,22 @@ def test_api_to_df(self):
'output': {'ref': 'OutputData'}
}]
})

def test_api_to_df_with_dupe_keys(self):
# Duplicate keys should be aggregated into a list.
api = [{"name": "S3ToS3Copy", "id": "S3ToS3Copy",
"fields": [{"key": "type", "stringValue": "CopyActivity" },
{"key": "schedule", "refValue": "CopyPeriod" },
{"key": "script", "stringValue": "value1"},
{"key": "script", "stringValue": "value2"}]}]
definition = translator.api_to_definition(api)
self.assertEqual(definition, {
'objects': [{
'id': 'S3ToS3Copy',
'name': 'S3ToS3Copy',
'type': 'CopyActivity',
'schedule': {'ref': 'CopyPeriod'},
'script': ['value1', 'value2'],
}]
})