betodealmeida commented on code in PR #21029:
URL: https://github.com/apache/superset/pull/21029#discussion_r942902080
##########
tests/unit_tests/charts/test_post_processing.py:
##########
@@ -1960,3 +1961,64 @@ def test_apply_post_process_json_format_data_is_none():
assert apply_post_process(result, form_data) == {
"queries": [{"result_format": ChartDataResultFormat.JSON, "data":
None}]
}
+
+
+def test_apply_post_process_verbose_map(session: Session):
+ from superset.connectors.sqla.models import SqlaTable, SqlMetric
+ from superset.models.core import Database
+
+ engine = session.get_bind()
+ SqlaTable.metadata.create_all(engine) # pylint: disable=no-member
+ db = Database(database_name="my_database", sqlalchemy_uri="sqlite://")
+ sqla_table = SqlaTable(
+ table_name="my_sqla_table",
+ columns=[],
+ metrics=[
+ SqlMetric(
+ metric_name="count",
+ verbose_name="COUNT(*)",
+ metric_type="count",
+ expression="COUNT(*)",
+ )
+ ],
+ database=db,
+ )
+
+ result = {
+ "queries": [
+ {
+ "result_format": ChartDataResultFormat.JSON,
+ "data": [{"count": 4725}],
+ }
+ ]
+ }
+ form_data = {
+ "datasource": "19__table",
+ "viz_type": "pivot_table_v2",
+ "slice_id": 69,
+ "url_params": {},
+ "granularity_sqla": "time_start",
+ "time_grain_sqla": "P1D",
+ "time_range": "No filter",
+ "groupbyColumns": [],
+ "groupbyRows": [],
+ "metrics": ["COUNT(*)"],
+ "metricsLayout": "COLUMNS",
+ "row_limit": 10000,
+ "order_desc": True,
+ "valueFormat": "SMART_NUMBER",
+ "date_format": "smart_date",
+ "rowOrder": "key_a_to_z",
+ "colOrder": "key_a_to_z",
+ "extra_form_data": {},
+ "force": False,
+ "result_format": "json",
+ "result_type": "results",
+ }
+
+ assert (
+ "COUNT(*)"
+ in apply_post_process(result, form_data,
datasource=sqla_table)["queries"][0][
+ "data"
+ ].keys()
+ )
Review Comment:
Nit: I would make this assertion more generic, since it might be useful to
capture future regressions in other parts of the code. Something like:
```python
assert apply_post_process(result, form_data, datasource=sqla_table) = {
"queries": [
{
"data": { "COUNT(*)": ..., ... },
},
]
)
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]