Skip to content

Commit

Permalink
Aggregate dupe keys into a list in datapipeline translation
Browse files Browse the repository at this point in the history
When going from API -> definition translation dupe keys should aggregate
their values into a list.
  • Loading branch information
jamesls committed Apr 9, 2014
1 parent 7242c29 commit acb850e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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'],
}]
})

0 comments on commit acb850e

Please sign in to comment.