zhaoyongjie commented on code in PR #20683:
URL: https://github.com/apache/superset/pull/20683#discussion_r926445422
##########
tests/integration_tests/datasource_tests.py:
##########
@@ -414,3 +416,157 @@ def test_get_datasource_invalid_datasource_failed(self):
self.login(username="admin")
resp = self.get_json_resp("/datasource/get/druid/500000/",
raise_on_error=False)
self.assertEqual(resp.get("error"), "'druid' is not a valid
DatasourceType")
+
+ def test_get_dataset_samples(self):
+ """
+ Dataset API: Test get dataset samples
+ """
+ if backend() == "sqlite":
+ return
+
+ dataset = SqlaTable(
+ table_name="virtual_dataset",
+ sql=("SELECT 'foo' as foo, 'bar' as bar"),
+ database=get_example_database(),
+ )
+ TableColumn(column_name="foo", type="VARCHAR(255)", table=dataset)
+ TableColumn(column_name="bar", type="VARCHAR(255)", table=dataset)
+ SqlMetric(metric_name="count", expression="count(*)", table=dataset)
+
+ self.login(username="admin")
+ uri =
f"datasource/samples?datasource_id={dataset.id}&datasource_type=table"
+
+ # 1. should cache data
+ # feeds data
+ self.client.post(uri)
+ # get from cache
+ rv = self.client.post(uri)
+ rv_data = json.loads(rv.data)
+ assert rv.status_code == 200
+ assert "result" in rv_data
+ assert rv_data["result"]["cached_dttm"] is not None
+ cache_key1 = rv_data["result"]["cache_key"]
+ assert QueryCacheManager.has(cache_key1, region=CacheRegion.DATA)
+
+ # 2. should through cache
Review Comment:
done
--
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]