|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +import json |
| 19 | + |
| 20 | +from superset.charts.commands.importers.v1.utils import migrate_chart |
| 21 | + |
| 22 | + |
| 23 | +def test_migrate_chart_area() -> None: |
| 24 | + """ |
| 25 | + Test the ``migrate_chart`` command when importing an area chart. |
| 26 | +
|
| 27 | + This is currently a no-op since the migration is not complete. |
| 28 | + """ |
| 29 | + chart_config = { |
| 30 | + "slice_name": "Birth names by state", |
| 31 | + "description": None, |
| 32 | + "certified_by": None, |
| 33 | + "certification_details": None, |
| 34 | + "viz_type": "area", |
| 35 | + "params": json.dumps( |
| 36 | + { |
| 37 | + "adhoc_filters": [], |
| 38 | + "annotation_layers": [], |
| 39 | + "bottom_margin": "auto", |
| 40 | + "color_scheme": "supersetColors", |
| 41 | + "comparison_type": "values", |
| 42 | + "dashboards": [], |
| 43 | + "datasource": "21__table", |
| 44 | + "extra_form_data": {}, |
| 45 | + "granularity_sqla": "ds", |
| 46 | + "groupby": ["state"], |
| 47 | + "line_interpolation": "linear", |
| 48 | + "metrics": ["count"], |
| 49 | + "order_desc": True, |
| 50 | + "rich_tooltip": True, |
| 51 | + "rolling_type": "None", |
| 52 | + "row_limit": 10000, |
| 53 | + "show_brush": "auto", |
| 54 | + "show_legend": True, |
| 55 | + "stacked_style": "stack", |
| 56 | + "time_grain_sqla": "P1D", |
| 57 | + "time_range": "No filter", |
| 58 | + "viz_type": "area", |
| 59 | + "x_axis_format": "smart_date", |
| 60 | + "x_ticks_layout": "auto", |
| 61 | + "y_axis_bounds": [None, None], |
| 62 | + "y_axis_format": "SMART_NUMBER", |
| 63 | + } |
| 64 | + ), |
| 65 | + "cache_timeout": None, |
| 66 | + "uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", |
| 67 | + "version": "1.0.0", |
| 68 | + "dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", |
| 69 | + } |
| 70 | + |
| 71 | + new_config = migrate_chart(chart_config) |
| 72 | + assert new_config == chart_config |
| 73 | + |
| 74 | + |
| 75 | +def test_migrate_pivot_table() -> None: |
| 76 | + """ |
| 77 | + Test the ``migrate_chart`` command when importing an old pivot table. |
| 78 | + """ |
| 79 | + chart_config = { |
| 80 | + "slice_name": "Pivot Table", |
| 81 | + "description": None, |
| 82 | + "certified_by": None, |
| 83 | + "certification_details": None, |
| 84 | + "viz_type": "pivot_table", |
| 85 | + "params": json.dumps( |
| 86 | + { |
| 87 | + "columns": ["state"], |
| 88 | + "compare_lag": "10", |
| 89 | + "compare_suffix": "o10Y", |
| 90 | + "granularity_sqla": "ds", |
| 91 | + "groupby": ["name"], |
| 92 | + "limit": "25", |
| 93 | + "markup_type": "markdown", |
| 94 | + "metrics": [ |
| 95 | + { |
| 96 | + "aggregate": "SUM", |
| 97 | + "column": { |
| 98 | + "column_name": "num", |
| 99 | + "type": "BIGINT", |
| 100 | + }, |
| 101 | + "expressionType": "SIMPLE", |
| 102 | + "label": "Births", |
| 103 | + "optionName": "metric_11", |
| 104 | + }, |
| 105 | + ], |
| 106 | + "row_limit": 50000, |
| 107 | + "since": "100 years ago", |
| 108 | + "time_range": "No filter", |
| 109 | + "time_range_endpoints": ["inclusive", "exclusive"], |
| 110 | + "until": "now", |
| 111 | + "viz_type": "pivot_table", |
| 112 | + }, |
| 113 | + ), |
| 114 | + "cache_timeout": None, |
| 115 | + "uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", |
| 116 | + "version": "1.0.0", |
| 117 | + "dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", |
| 118 | + } |
| 119 | + |
| 120 | + new_config = migrate_chart(chart_config) |
| 121 | + assert new_config == { |
| 122 | + "slice_name": "Pivot Table", |
| 123 | + "description": None, |
| 124 | + "certified_by": None, |
| 125 | + "certification_details": None, |
| 126 | + "viz_type": "pivot_table_v2", |
| 127 | + "params": json.dumps( |
| 128 | + { |
| 129 | + "groupbyColumns": ["state"], |
| 130 | + "compare_lag": "10", |
| 131 | + "compare_suffix": "o10Y", |
| 132 | + "groupbyRows": ["name"], |
| 133 | + "limit": "25", |
| 134 | + "markup_type": "markdown", |
| 135 | + "metrics": [ |
| 136 | + { |
| 137 | + "aggregate": "SUM", |
| 138 | + "column": {"column_name": "num", "type": "BIGINT"}, |
| 139 | + "expressionType": "SIMPLE", |
| 140 | + "label": "Births", |
| 141 | + "optionName": "metric_11", |
| 142 | + } |
| 143 | + ], |
| 144 | + "series_limit": 50000, |
| 145 | + "since": "100 years ago", |
| 146 | + "time_range_endpoints": ["inclusive", "exclusive"], |
| 147 | + "until": "now", |
| 148 | + "viz_type": "pivot_table_v2", |
| 149 | + "rowOrder": "value_z_to_a", |
| 150 | + "adhoc_filters": [ |
| 151 | + { |
| 152 | + "clause": "WHERE", |
| 153 | + "subject": "ds", |
| 154 | + "operator": "TEMPORAL_RANGE", |
| 155 | + "comparator": "No filter", |
| 156 | + "expressionType": "SIMPLE", |
| 157 | + } |
| 158 | + ], |
| 159 | + } |
| 160 | + ), |
| 161 | + "cache_timeout": None, |
| 162 | + "uuid": "ffd15af2-2188-425c-b6b4-df28aac45872", |
| 163 | + "version": "1.0.0", |
| 164 | + "dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d", |
| 165 | + } |
0 commit comments