-
Notifications
You must be signed in to change notification settings - Fork 18.1k
test: removed unicode_test example from unit tests #11131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bbd1239
Removed depemdency to unicode example in tests config.
kkucharc 37ecef0
Added common methods for creating dashboards for tests.
kkucharc 173ea9a
Added fixtures to all tests which were using unicode example.
kkucharc 5ac088f
Added cleanup for unicode_test table
kkucharc 8002941
Removed unnecessary fixture parts of unicode dashboard tests
kkucharc 773898b
Parametrized creating slice for tests
kkucharc 21e5fe5
Moved fixtures for unicode test to separate file and refactored to se…
kkucharc 2f9e21a
Cleandup after fix
kkucharc c04ce35
Changed variable names to more readable
kkucharc 7c07907
Added cleanup for dashboards and slices
kkucharc 8f5ec97
Applied unicode fixture to charts api tests
kkucharc c4537ff
Update schema variable to dtype in dashboard utils
kkucharc 7c78f7a
Changed variable schema to dtype in dashboards. Replaced accessing fi…
kkucharc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # 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. | ||
| """Utils to provide dashboards for tests""" | ||
|
|
||
| import json | ||
| from typing import Any, Dict | ||
|
|
||
| from pandas import DataFrame | ||
|
|
||
| from superset import ConnectorRegistry, db | ||
| from superset.connectors.sqla.models import SqlaTable | ||
| from superset.models.core import Database | ||
| from superset.models.dashboard import Dashboard | ||
| from superset.models.slice import Slice | ||
|
|
||
|
|
||
| def create_table_for_dashboard( | ||
| df: DataFrame, table_name: str, database: Database, dtype: Dict[str, Any] | ||
| ) -> SqlaTable: | ||
| df.to_sql( | ||
| table_name, | ||
| database.get_sqla_engine(), | ||
| if_exists="replace", | ||
| chunksize=500, | ||
| dtype=schema, | ||
| index=False, | ||
| method="multi", | ||
| ) | ||
|
|
||
| table_source = ConnectorRegistry.sources["table"] | ||
| table = db.session.query(table_source).filter_by(table_name=table_name).first() | ||
| if not table: | ||
| table = table_source(table_name=table_name) | ||
| table.database = database | ||
| db.session.merge(table) | ||
| db.session.commit() | ||
|
|
||
| return table | ||
|
|
||
|
|
||
| def create_slice( | ||
| title: str, viz_type: str, table: SqlaTable, slices_dict: Dict[str, str] | ||
| ) -> Slice: | ||
| return Slice( | ||
| slice_name=title, | ||
| viz_type=viz_type, | ||
| datasource_type="table", | ||
| datasource_id=table.id, | ||
| params=json.dumps(slices_dict, indent=4, sort_keys=True), | ||
| ) | ||
|
|
||
|
|
||
| def create_dashboard(slug: str, title: str, position: str, slice: Slice) -> Dashboard: | ||
| dash = db.session.query(Dashboard).filter_by(slug=slug).first() | ||
|
|
||
| if not dash: | ||
| dash = Dashboard() | ||
| dash.dashboard_title = title | ||
| if position is not None: | ||
| js = position | ||
| pos = json.loads(js) | ||
| dash.position_json = json.dumps(pos, indent=4) | ||
| dash.slug = slug | ||
| if slice is not None: | ||
| dash.slices = [slice] | ||
| db.session.merge(dash) | ||
| db.session.commit() | ||
|
|
||
| return dash | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # 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. | ||
| import pandas as pd | ||
| import pytest | ||
| from pandas import DataFrame | ||
| from sqlalchemy import String | ||
|
|
||
| from superset import db | ||
| from superset.connectors.sqla.models import SqlaTable | ||
| from superset.models.dashboard import Dashboard | ||
| from superset.models.slice import Slice | ||
| from superset.utils.core import get_example_database | ||
| from tests.dashboard_utils import ( | ||
| create_dashboard, | ||
| create_slice, | ||
| create_table_for_dashboard, | ||
| ) | ||
| from tests.test_app import app | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def load_unicode_dashboard_with_slice(): | ||
| table_name = "unicode_test" | ||
| slice_name = "Unicode Cloud" | ||
| df = _get_dataframe() | ||
| with app.app_context(): | ||
| dash = _create_unicode_dashboard(df, table_name, slice_name, None) | ||
| yield | ||
|
|
||
| _cleanup(dash, slice_name) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def load_unicode_dashboard_with_position(): | ||
| table_name = "unicode_test" | ||
| slice_name = "Unicode Cloud" | ||
| df = _get_dataframe() | ||
| position = "{}" | ||
| with app.app_context(): | ||
| dash = _create_unicode_dashboard(df, table_name, slice_name, position) | ||
| yield | ||
| _cleanup(dash, slice_name) | ||
|
|
||
|
|
||
| def _get_dataframe(): | ||
| data = _get_unicode_data() | ||
| return pd.DataFrame.from_dict(data) | ||
|
|
||
|
|
||
| def _get_unicode_data(): | ||
| return [ | ||
| {"phrase": "Под"}, | ||
| {"phrase": "řšž"}, | ||
| {"phrase": "視野無限廣"}, | ||
| {"phrase": "微風"}, | ||
| {"phrase": "中国智造"}, | ||
| {"phrase": "æøå"}, | ||
| {"phrase": "ëœéè"}, | ||
| {"phrase": "いろはにほ"}, | ||
| ] | ||
|
|
||
|
|
||
| def _create_unicode_dashboard( | ||
| df: DataFrame, table_name: str, slice_title: str, position: str | ||
| ) -> Dashboard: | ||
| database = get_example_database() | ||
| schema = { | ||
| "phrase": String(500), | ||
| } | ||
| table = create_table_for_dashboard(df, table_name, database, schema) | ||
| table.fetch_metadata() | ||
|
|
||
| if slice_title: | ||
| slice = _create_and_commit_unicode_slice(table, slice_title) | ||
|
|
||
| return create_dashboard("unicode-test", "Unicode Test", position, slice) | ||
|
|
||
|
|
||
| def _create_and_commit_unicode_slice(table: SqlaTable, title: str): | ||
| slice = create_slice(title, "word_cloud", table, {}) | ||
| o = db.session.query(Slice).filter_by(slice_name=slice.slice_name).first() | ||
| if o: | ||
| db.session.delete(o) | ||
| db.session.add(slice) | ||
| db.session.commit() | ||
| return slice | ||
|
|
||
|
|
||
| def _cleanup(dash: Dashboard, slice_name: str) -> None: | ||
| engine = get_example_database().get_sqla_engine() | ||
| engine.execute("DROP TABLE IF EXISTS unicode_test") | ||
| db.session.delete(dash) | ||
| if slice_name: | ||
| slice = db.session.query(Slice).filter_by(slice_name=slice_name).first() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| db.session.delete(slice) | ||
| db.session.commit() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.