You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/02 16:24:52 UTC

[GitHub] [incubator-superset] dpgaspar commented on a change in pull request #11131: test: removed unicode_test example from unit tests

dpgaspar commented on a change in pull request #11131:
URL: https://github.com/apache/incubator-superset/pull/11131#discussion_r498921390



##########
File path: tests/dashboard_utils.py
##########
@@ -0,0 +1,78 @@
+# 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.
+# isort:skip_file
+"""Utils to provide dashboards for tests"""
+
+import json
+
+from pandas import DataFrame
+from typing import Dict, Any
+
+from superset import db, ConnectorRegistry
+from superset.models.dashboard import Dashboard
+from superset.models.slice import Slice
+
+
+def create_table_for_dashboard(
+    df: DataFrame, tbl_name: str, database, schema: Dict[str, Any]
+):
+    df.to_sql(
+        tbl_name,
+        database.get_sqla_engine(),
+        if_exists="replace",
+        chunksize=500,
+        dtype=schema,
+        index=False,
+        method="multi",
+    )
+
+    tbl_source = ConnectorRegistry.sources["table"]
+    obj = db.session.query(tbl_source).filter_by(table_name=tbl_name).first()
+    if not obj:
+        obj = tbl_source(table_name=tbl_name)
+    obj.database = database
+    db.session.merge(obj)
+    db.session.commit()
+
+    return obj
+
+
+def create_slice(title, viz_type, tbl, slices_dict: Dict[str, str]):
+    return Slice(
+        slice_name=title,
+        viz_type=viz_type,
+        datasource_type="table",
+        datasource_id=tbl.id,
+        params=json.dumps(slices_dict, indent=4, sort_keys=True),
+    )
+
+
+def create_dashboard(slug: str, title: str, position: str, slc: Slice):

Review comment:
       nit: missing return type

##########
File path: tests/dashboard_utils.py
##########
@@ -0,0 +1,78 @@
+# 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.
+# isort:skip_file
+"""Utils to provide dashboards for tests"""
+
+import json
+
+from pandas import DataFrame
+from typing import Dict, Any
+
+from superset import db, ConnectorRegistry
+from superset.models.dashboard import Dashboard
+from superset.models.slice import Slice
+
+
+def create_table_for_dashboard(
+    df: DataFrame, tbl_name: str, database, schema: Dict[str, Any]
+):

Review comment:
       nit: missing return type

##########
File path: tests/dashboard_utils.py
##########
@@ -0,0 +1,78 @@
+# 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.
+# isort:skip_file
+"""Utils to provide dashboards for tests"""
+
+import json
+
+from pandas import DataFrame
+from typing import Dict, Any
+
+from superset import db, ConnectorRegistry
+from superset.models.dashboard import Dashboard
+from superset.models.slice import Slice
+
+
+def create_table_for_dashboard(
+    df: DataFrame, tbl_name: str, database, schema: Dict[str, Any]
+):
+    df.to_sql(
+        tbl_name,
+        database.get_sqla_engine(),
+        if_exists="replace",
+        chunksize=500,
+        dtype=schema,
+        index=False,
+        method="multi",
+    )
+
+    tbl_source = ConnectorRegistry.sources["table"]
+    obj = db.session.query(tbl_source).filter_by(table_name=tbl_name).first()
+    if not obj:
+        obj = tbl_source(table_name=tbl_name)
+    obj.database = database
+    db.session.merge(obj)
+    db.session.commit()
+
+    return obj
+
+
+def create_slice(title, viz_type, tbl, slices_dict: Dict[str, str]):

Review comment:
       nit: missing return type
   
   

##########
File path: tests/security_tests.py
##########
@@ -1122,6 +1132,41 @@ def test_rls_filter_doesnt_alter_energy_query(self):
         assert tbl.get_extra_cache_keys(self.query_obj) == []
         assert "value > 1" not in sql
 
+    @pytest.fixture()
+    def load_unicode_dashboard(self):
+        data = [
+            {"phrase": "Под"},
+            {"phrase": "řšž"},
+            {"phrase": "視野無限廣"},
+            {"phrase": "微風"},
+            {"phrase": "中国智造"},
+            {"phrase": "æøå"},
+            {"phrase": "ëœéè"},
+            {"phrase": "いろはにほ"},
+        ]
+        tbl_name = "unicode_test"
+
+        # generate date/numeric data
+        df = pd.DataFrame.from_dict(data)
+
+        with self.create_app().app_context():
+            database = get_example_database()
+            schema = {
+                "phrase": String(500),
+            }
+            obj = create_table_for_dashboard(df, tbl_name, database, schema)
+            obj.fetch_metadata()
+
+            tbl = obj
+            slc = create_slice("Unicode Cloud", "word_cloud", tbl, None)
+            o = db.session.query(Slice).filter_by(slice_name=slc.slice_name).first()
+            if o:
+                db.session.delete(o)
+            db.session.add(slc)
+            db.session.commit()
+            create_dashboard("unicode-test", "Unicode Test", None, slc)

Review comment:
       Yield and cleanup?

##########
File path: tests/databases/api_tests.py
##########
@@ -758,6 +768,38 @@ def test_test_connection_unsafe_uri(self):
         }
         self.assertEqual(response, expected_response)
 
+    @pytest.fixture()
+    def load_unicode_dashboard(self):
+        data = [
+            {"phrase": "Под"},
+            {"phrase": "řšž"},
+            {"phrase": "視野無限廣"},
+            {"phrase": "微風"},
+            {"phrase": "中国智造"},
+            {"phrase": "æøå"},
+            {"phrase": "ëœéè"},
+            {"phrase": "いろはにほ"},
+        ]
+        tbl_name = "unicode_test"
+
+        # generate date/numeric data
+        df = pd.DataFrame.from_dict(data)
+
+        with self.create_app().app_context():
+            database = get_example_database()
+            schema = {
+                "phrase": String(500),
+                "dttm": Date(),
+                "value": Float(),
+            }
+            obj = create_table_for_dashboard(df, tbl_name, database, schema)
+            obj.fetch_metadata()
+
+            db.session.commit()
+            position = "{}"
+            create_dashboard("unicode-test", "Unicode Test", position, None)

Review comment:
       What's being done on other pytest fixtures is to `yield create_dashboard("unicode-test", "Unicode Test", position, None)` and then clean everything up (on this case delete the dashboard and then delete the table for dashboard)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org