diff --git a/python-sync-actions/src/actions/mapping.py b/python-sync-actions/src/actions/mapping.py index fc65c3c..4c6c3b6 100644 --- a/python-sync-actions/src/actions/mapping.py +++ b/python-sync-actions/src/actions/mapping.py @@ -27,6 +27,10 @@ def __init__(self): def parse_row(self, row: dict[str, Any]): current_path = [] + + if isinstance(row, list): + row = row[0] + for name, value in row.items(): self.analyzer.analyze_object(current_path, name, value) diff --git a/python-sync-actions/tests/test_mapping.py b/python-sync-actions/tests/test_mapping.py index 1eae81c..517b672 100644 --- a/python-sync-actions/tests/test_mapping.py +++ b/python-sync-actions/tests/test_mapping.py @@ -131,3 +131,70 @@ def test_infer_mapping_userdata_child(self): expected_output = {'id': 'id', 'status': 'status'} self.assertEqual(output, expected_output) + + def test_types(self): + data = [[ + { + 'id': 'asdf', + 'firstWorkingDay': '2024-07-16', + 'workingDays': [ + { + 'day': 'monday' + }, + { + 'day': 'tuesday' + }, + { + 'day': 'wednesday' + }, + { + 'day': 'thursday' + }, + { + 'day': 'friday' + } + ], + 'teams': [ + { + 'name': 'Dream Team', + } + ] + }, + { + 'id': 'asdf2', + 'firstWorkingDay': '2024-07-16', + 'workingDays': [ + { + 'day': 'monday' + }, + { + 'day': 'tuesday' + }, + { + 'day': 'wednesday' + }, + { + 'day': 'thursday' + }, + { + 'day': 'friday' + } + ], + 'teams': [ + { + 'name': 'Dream Team', + } + ] + }]] + + expected = {'firstWorkingDay': 'firstWorkingDay', + 'id': 'id', + 'teams': {'forceType': True, + 'mapping': {'destination': 'teams'}, + 'type': 'column'}, + 'workingDays': {'forceType': True, + 'mapping': {'destination': 'workingDays'}, + 'type': 'column'}} + res = infer_mapping(data, max_level_nest_level=1) + + self.assertEqual(res, expected)