villebro commented on a change in pull request #8901: Add datasource.changed_on to cache_key URL: https://github.com/apache/incubator-superset/pull/8901#discussion_r365984496
########## File path: tests/core_tests.py ########## @@ -110,30 +128,40 @@ def test_cache_key(self): qobj["groupby"] = [] self.assertNotEqual(cache_key, viz.cache_key(qobj)) + def test_cache_key_changes_when_datasource_is_updated(self): + qc_dict = self._get_query_context_dict() + + # construct baseline cache_key + query_context = QueryContext(**qc_dict) + query_object = query_context.queries[0] + cache_key_original = query_context.cache_key(query_object) + + # make temporary change and revert it to refresh the changed_on property + datasource = ConnectorRegistry.get_datasource( + datasource_type=qc_dict["datasource"]["type"], + datasource_id=qc_dict["datasource"]["id"], + session=db.session, + ) + description_original = datasource.description + datasource.description = "temporary description" + db.session.commit() + datasource.description = description_original + db.session.commit() + + # create new QueryContext with unchanged attributes and extract new cache_key + query_context = QueryContext(**qc_dict) + query_object = query_context.queries[0] + cache_key_new = query_context.cache_key(query_object) + + # the new cache_key should be different due to updated datasource + self.assertNotEqual(cache_key_original, cache_key_new) + def test_api_v1_query_endpoint(self): self.login(username="admin") - slc = self.get_slice("Girl Name Cloud", db.session) - form_data = slc.form_data - data = json.dumps( - { - "datasource": {"id": slc.datasource_id, "type": slc.datasource_type}, - "queries": [ - { - "granularity": "ds", - "groupby": ["name"], - "metrics": ["sum__num"], - "filters": [], - "time_range": "{} : {}".format( - form_data.get("since"), form_data.get("until") - ), - "limit": 100, - } - ], - } - ) - # TODO: update once get_data is implemented for QueryObject - with self.assertRaises(Exception): - self.get_resp("/api/v1/query/", {"query_context": data}) + qc_dict = self._get_query_context_dict() + data = json.dumps(qc_dict) + resp = json.loads(self.get_resp("/api/v1/query/", {"query_context": data})) + self.assertEqual(resp[0]["rowcount"], 100) Review comment: The old unit test seemed to be incomplete, so fixed a few bugs in the body (`limit` -> `row_limit` and removed `time_range`) to make it work properly. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org