2023-06-08 09:13:39 -04:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2023-11-16 12:28:09 -05:00
|
|
|
from typing import Any
|
2023-06-08 09:13:39 -04:00
|
|
|
|
|
|
|
from superset.migrations.shared.migrate_viz import MigratePivotTable
|
2023-11-16 12:28:09 -05:00
|
|
|
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
|
2023-06-08 09:13:39 -04:00
|
|
|
|
2023-11-16 12:28:09 -05:00
|
|
|
SOURCE_FORM_DATA: dict[str, Any] = {
|
2023-06-08 09:13:39 -04:00
|
|
|
"any_other_key": "untouched",
|
|
|
|
"columns": ["state"],
|
|
|
|
"combine_metric": True,
|
|
|
|
"groupby": ["name"],
|
|
|
|
"number_format": "SMART_NUMBER",
|
|
|
|
"pandas_aggfunc": "sum",
|
|
|
|
"pivot_margins": True,
|
|
|
|
"timeseries_limit_metric": "count",
|
|
|
|
"transpose_pivot": True,
|
|
|
|
"viz_type": "pivot_table",
|
|
|
|
}
|
|
|
|
|
2023-11-16 12:28:09 -05:00
|
|
|
TARGET_FORM_DATA: dict[str, Any] = {
|
2023-06-08 09:13:39 -04:00
|
|
|
"any_other_key": "untouched",
|
|
|
|
"aggregateFunction": "Sum",
|
|
|
|
"colTotals": True,
|
2023-08-14 08:20:32 -04:00
|
|
|
"colSubTotals": True,
|
2023-06-08 09:13:39 -04:00
|
|
|
"combineMetric": True,
|
|
|
|
"form_data_bak": SOURCE_FORM_DATA,
|
|
|
|
"groupbyColumns": ["state"],
|
|
|
|
"groupbyRows": ["name"],
|
2023-06-09 14:39:23 -04:00
|
|
|
"rowOrder": "value_z_to_a",
|
2023-06-08 09:13:39 -04:00
|
|
|
"series_limit_metric": "count",
|
|
|
|
"transposePivot": True,
|
|
|
|
"valueFormat": "SMART_NUMBER",
|
|
|
|
"viz_type": "pivot_table_v2",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-16 12:28:09 -05:00
|
|
|
def test_migration() -> None:
|
|
|
|
migrate_and_assert(MigratePivotTable, SOURCE_FORM_DATA, TARGET_FORM_DATA)
|