From 48f9c7c9acdc4b15876b08c44e3c457c9e7138a6 Mon Sep 17 00:00:00 2001 From: Josef Kudera <46950237+kudj@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:52:43 +0400 Subject: [PATCH] infering from list of lists added test --- python-sync-actions/src/actions/mapping.py | 4 ++ python-sync-actions/tests/test_mapping.py | 67 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) 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)