hughhhh commented on code in PR #43870: URL: https://github.com/apache/superset/pull/43870#discussion_r4319678672
########## tests/unit_tests/datasets/partition_mapping_preview_test.py: ########## @@ -0,0 +1,1071 @@ +# 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. +""" +The partition mapping preview endpoint. + +This route fires a real warehouse query from a text input in the dataset +editor, so the order of its guards is the point: parse and denylist checks run +*before* anything reaches the engine, which is what keeps a half-typed +expression from costing a query at all. +""" + +from __future__ import annotations + +from typing import Any +from unittest.mock import MagicMock, patch + +import pytest +from flask import Flask +from sqlalchemy.orm.session import Session + +from superset import db + +PROBE = "superset.connectors.sqla.partition_mapping.evaluate_transform" + + [email protected](autouse=True) +def enable_partition_filter_mapping(app: Flask) -> Any: + app.config["DEFAULT_FEATURE_FLAGS"]["PARTITION_FILTER_MAPPING"] = True + yield + del app.config["DEFAULT_FEATURE_FLAGS"]["PARTITION_FILTER_MAPPING"] + + [email protected](autouse=True) +def real_cache(app: Flask) -> Any: + """ + The test app runs a null cache, which would make the rate limiter a no-op. + """ + from flask_caching import Cache + + from superset.extensions import cache_manager + + cache = Cache(config={"CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 300}) + cache.init_app(app) + original = cache_manager._cache # noqa: SLF001 + cache_manager._cache = cache # noqa: SLF001 + yield + cache_manager._cache = original # noqa: SLF001 + + [email protected](autouse=True) +def allow_editorship(mocker: Any) -> Any: Review Comment: Fixed. `test_preview_refuses_a_caller_who_cannot_edit_the_dataset` uses the real `SupersetSecurityManager.raise_for_editorship` rather than the autouse mock, asserts a 403, and booby-traps the probe so a 403 that still reached the engine would fail. -- 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]
