Exemple #1
0
    def test_concat_fields(self):
        node = {
            'Child1': {
                'columns': ['column_1', 'column_2'],
                'delimiter': '_',
                'destination': 'column_3',
            },
            'Child2': {
                'columns': ['column_1'],
                'destination': 'column_3',
            },
        }

        row = {
            'level': 1,
            'id': '007',
            'code': 'be',
            'Child1': [
                {'column_1': 2, 'column_2': 'aa'},
                {'column_1': 3, 'column_2': 'bb'},
            ],
            'Child2': [
                {'column_1': 2, 'column_2': 'aa'},
                {'column_1': 3, 'column_2': 'bb'},
            ],
        }
        row = _concat_fields(row, node)
        assert row == {
            'level': 1,
            'id': '007',
            'code': 'be',
            'Child1': [
                {'column_1': 2, 'column_2': 'aa', 'column_3': '2_aa'},
                {'column_1': 3, 'column_2': 'bb', 'column_3': '3_bb'},
            ],
            'Child2': [
                {'column_1': 2, 'column_2': 'aa', 'column_3': '2'},
                {'column_1': 3, 'column_2': 'bb', 'column_3': '3'},
            ]
        }
Exemple #2
0
    def test_concat_fields(self):
        nodes = {
            "Child1": {
                "columns": ["column_1", "column_2"],
                "delimiter": "_",
                "destination": "column_3",
            },
            "Child2": {
                "columns": ["column_1"],
                "destination": "column_3",
            },
        }

        row = {
            "level":
            1,
            "id":
            "007",
            "code":
            "be",
            "Child1": [
                {
                    "column_1": 2,
                    "column_2": "aa"
                },
                {
                    "column_1": 3,
                    "column_2": "bb"
                },
            ],
            "Child2": [
                {
                    "column_1": 2,
                    "column_2": "aa"
                },
                {
                    "column_1": 3,
                    "column_2": "bb"
                },
            ],
        }
        row = _concat_fields(row, nodes)
        assert row == {
            "level":
            1,
            "id":
            "007",
            "code":
            "be",
            "Child1": [
                {
                    "column_1": 2,
                    "column_2": "aa",
                    "column_3": "2_aa"
                },
                {
                    "column_1": 3,
                    "column_2": "bb",
                    "column_3": "3_bb"
                },
            ],
            "Child2": [
                {
                    "column_1": 2,
                    "column_2": "aa",
                    "column_3": "2"
                },
                {
                    "column_1": 3,
                    "column_2": "bb",
                    "column_3": "3"
                },
            ],
        }