diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 70ae863e0e2174554cb475fc27277dfb6a790f06..9e5f72fe417dbbb358c1b42adf9b701ba3d0226b 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -382,8 +382,6 @@ honeysql.util/defalias clojure.core/def metabase-enterprise.serialization.test-util/with-random-dump-dir clojure.core/let metabase.actions.test-util/with-actions clojure.core/let - metabase.actions.test-util/with-card-emitter clojure.core/let - metabase.actions.test-util/with-dashboard-emitter clojure.core/let metabase.api.common/let-404 clojure.core/let metabase.api.dashboard-test/let-url clojure.core/let metabase.api.search-test/do-test-users clojure.core/let @@ -415,6 +413,7 @@ metabase.test.data.interface/defdataset clojure.core/def metabase.test.data.interface/defdataset-edn clojure.core/def metabase.test/defdataset clojure.core/def + metabase.test/with-actions clojure.core/let metabase.test/with-open-channels clojure.core/let metabase.test/with-single-admin-user clojure.core/fn metabase.test/with-temp-dir clojure.core/let diff --git a/test/metabase/actions/test_util.clj b/test/metabase/actions/test_util.clj index 79769a33978dd5bab130b44ee523db18ee13d8e6..ea8a390d162abb15c8c1a927cdc53ff668a6cbfb 100644 --- a/test/metabase/actions/test_util.clj +++ b/test/metabase/actions/test_util.clj @@ -6,11 +6,15 @@ [metabase.http-client :as client] [metabase.models :refer [Action Card Database]] [metabase.models.action :as action] - [metabase.test :as mt] + [metabase.query-processor-test :as qp.test] + [metabase.test.data :as data] [metabase.test.data.dataset-definitions :as defs] + [metabase.test.data.datasets :as datasets] [metabase.test.data.interface :as tx] [metabase.test.initialize :as initialize] - [toucan.db :as db])) + [metabase.test.util :as tu] + [toucan.db :as db] + [toucan.util.test :as tt])) (def ^:dynamic ^:private *actions-test-data-tables* #{"categories"}) @@ -75,8 +79,8 @@ [dataset-definition thunk] (let [db (atom nil)] (try - (mt/dataset dataset-definition - (reset! db (mt/db)) + (data/dataset dataset-definition + (reset! db (data/db)) (thunk)) (finally (when-let [{driver :engine, db-id :id} @db] @@ -98,18 +102,18 @@ `(do-with-dataset-definition (tx/dataset-definition ~(str (gensym)) ~dataset-definition) (fn [] ~@body))) (deftest with-actions-test-data-test - (mt/test-drivers (mt/normal-drivers-with-feature :actions/custom) + (datasets/test-drivers (qp.test/normal-drivers-with-feature :actions/custom) (dotimes [i 2] (testing (format "Iteration %d" i) (with-actions-test-data (letfn [(row-count [] - (mt/rows (mt/run-mbql-query categories {:aggregation [[:count]]})))] + (qp.test/rows (data/run-mbql-query categories {:aggregation [[:count]]})))] (testing "before" (is (= [[75]] (row-count)))) (testing "delete row" (is (= [1] - (jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (mt/id)) + (jdbc/execute! (sql-jdbc.conn/db->pooled-connection-spec (data/id)) "DELETE FROM CATEGORIES WHERE ID = 1;")))) (testing "after" (is (= [[74]] @@ -133,8 +137,8 @@ :required false :target [:variable [:template-tag "name"]]}] :visualization_settings {:inline true} - :database_id (mt/id) - :dataset_query {:database (mt/id) + :database_id (data/id) + :dataset_query {:database (data/id) :type :native :native {:query (str "UPDATE categories\n" "SET name = concat([[{{name}}, ' ',]] 'Sh', 'op')\n" @@ -206,12 +210,12 @@ (:dataset maybe-model-def) (contains? maybe-model-def :dataset_query)) [model-part (drop 2 binding-forms-and-option-maps)] - ['[_ {:dataset true :dataset_query (mt/mbql-query categories)}] + ['[_ {:dataset true :dataset_query (metabase.test.data/mbql-query categories)}] binding-forms-and-option-maps])] `(do (initialize/initialize-if-needed! :web-server) - (mt/with-temp Card ~[model model-def] - (mt/with-model-cleanup [Action] + (tt/with-temp Card ~[model model-def] + (tu/with-model-cleanup [Action] (let [~custom-binding ~model ~@(mapcat (fn [[binding-form option-map]] [binding-form `(do-with-action (merge {:type :query} ~option-map) (:id ~model))]) @@ -222,7 +226,7 @@ (with-actions [{id :action-id} {:type :implicit :kind "row/create"} {:keys [action-id model-id]} {:type :http}] (something id action-id model-id)) - (with-actions [{model-card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} + (with-actions [{model-card-id :id} {:dataset true :dataset_query (data/mbql-query types)} {id :action-id} {:type :implicit :kind "row/create"} {:keys [action-id model-id]} {}] (something model-card-id id action-id model-id)) @@ -231,8 +235,8 @@ (defn do-with-actions-enabled "Impl for [[with-actions-enabled]]." [thunk] - (mt/with-temporary-setting-values [experimental-enable-actions true] - (mt/with-temp-vals-in-db Database (mt/id) {:settings {:database-enable-actions true}} + (tu/with-temporary-setting-values [experimental-enable-actions true] + (tu/with-temp-vals-in-db Database (data/id) {:settings {:database-enable-actions true}} (thunk)))) (defmacro with-actions-enabled diff --git a/test/metabase/actions_test.clj b/test/metabase/actions_test.clj index 546f9351ddf58424ea4d1203b3974958be31427f..ce1e3949d1d7c12f90c149c89b9d1dea07f678d6 100644 --- a/test/metabase/actions_test.clj +++ b/test/metabase/actions_test.clj @@ -2,7 +2,6 @@ (:require [clojure.test :refer :all] [metabase.actions :as actions] - [metabase.actions.test-util :as actions.test-util] [metabase.api.common :refer [*current-user-permissions-set*]] [metabase.driver :as driver] [metabase.models :refer [Database Table]] @@ -13,10 +12,10 @@ [schema.core :as s])) (defmacro with-actions-test-data-and-actions-permissively-enabled - "Combines [[actions.test-util/with-actions-test-data-and-actions-enabled]] with full permissions." + "Combines [[mt/with-actions-test-data-and-actions-enabled]] with full permissions." {:style/indent 0} [& body] - `(actions.test-util/with-actions-test-data-and-actions-enabled + `(mt/with-actions-test-data-and-actions-enabled (binding [*current-user-permissions-set* (delay #{"/"})] ~@body))) @@ -176,7 +175,7 @@ (= (namespace action) "row")) (deftest validation-test - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (doseq [{:keys [action request-body]} (mock-requests) :when (row-action? action)] (testing (str action " without :query") @@ -185,7 +184,7 @@ (deftest row-update-action-gives-400-when-matching-more-than-one (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (binding [*current-user-permissions-set* (delay #{"/"})] (let [query-that-returns-more-than-one (assoc (mt/mbql-query users {:filter [:>= $id 1]}) :update_row {(format-field-name :name) "new-name"}) @@ -198,7 +197,7 @@ (deftest row-delete-action-gives-400-when-matching-more-than-one (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (binding [*current-user-permissions-set* (delay #{"/"})] (let [query-that-returns-more-than-one (assoc (mt/mbql-query checkins {:filter [:>= $id 1]}) :update_row {(format-field-name :name) "new-name"}) @@ -229,7 +228,7 @@ (testing "row/delete" (testing "FK constraint violations errors should have nice error messages (at least for Postgres) (#24021)" (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-tables #{"venues" "categories"} + (mt/with-actions-test-data-tables #{"venues" "categories"} (with-actions-test-data-and-actions-permissively-enabled ;; attempting to delete the `Pizza` category should fail because there are several rows in `venues` that have diff --git a/test/metabase/api/action_test.clj b/test/metabase/api/action_test.clj index 3f82d4abc832694b2ddbb85ab8799c691f7cae5e..ab8573d471860400e1be1547727d25ffbe3e259e 100644 --- a/test/metabase/api/action_test.clj +++ b/test/metabase/api/action_test.clj @@ -1,7 +1,6 @@ (ns metabase.api.action-test (:require [clojure.test :refer :all] - [metabase.actions.test-util :as actions.test-util] [metabase.api.action :as api.action] [metabase.models :refer [Card]] [metabase.models.action :refer [Action]] @@ -29,7 +28,7 @@ s/Keyword s/Any}) (deftest list-actions-test - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (mt/with-non-admin-groups-no-root-collection-perms (mt/with-temp Card [{card-id :id} {:dataset true}] (mt/with-model-cleanup [Action] @@ -75,9 +74,9 @@ (deftest get-action-test (testing "GET /api/action/:id" - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (mt/with-non-admin-groups-no-root-collection-perms - (actions.test-util/with-actions [{:keys [action-id]} {}] + (mt/with-actions [{:keys [action-id]} {}] (let [action (mt/user-http-request :crowberto :get 200 (format "action/%d" action-id))] (testing "Should return a query action deserialized (#23201)" (is (schema= ExpectedGetQueryActionAPIResponse @@ -87,11 +86,11 @@ (mt/user-http-request :rasta :get 403 (format "action/%d" action-id)))))))))) (deftest unified-action-create-test - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (mt/with-non-admin-groups-no-root-collection-perms - (actions.test-util/with-actions-test-data-tables #{"users" "categories"} - (actions.test-util/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query users)} - {exiting-implicit-action-id :action-id} {:type :implicit :kind "row/update"}] + (mt/with-actions-test-data-tables #{"users" "categories"} + (mt/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query users)} + {exiting-implicit-action-id :action-id} {:type :implicit :kind "row/update"}] (doseq [initial-action [{:name "Get example" :description "A dummy HTTP action" :type "http" @@ -164,7 +163,7 @@ (is (= "Not found." (mt/user-http-request :crowberto :get 404 action-path))))))))))) (deftest action-parameters-test - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (mt/with-temp* [Card [{card-id :id} {:dataset true}]] (mt/with-model-cleanup [Action] (let [initial-action {:name "Get example" diff --git a/test/metabase/api/dashboard_test.clj b/test/metabase/api/dashboard_test.clj index 1103992fe8496277e2bd1d9a000c7d4f35df6d43..c4da4835ab5b346402657bbf74a9de35aaa6e6de 100644 --- a/test/metabase/api/dashboard_test.clj +++ b/test/metabase/api/dashboard_test.clj @@ -6,7 +6,6 @@ [clojure.test :refer :all] [clojure.walk :as walk] [medley.core :as m] - [metabase.actions.test-util :as actions.test-util] [metabase.api.card-test :as api.card-test] [metabase.api.common :as api] [metabase.api.dashboard :as api.dashboard] @@ -1344,7 +1343,7 @@ (remove-ids-and-booleanize-timestamps (dashboard-card/retrieve-dashboard-card dashcard-id-2)))))))) (deftest update-action-cards-test - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (testing "PUT /api/dashboard/:id/cards" ;; fetch a dashboard WITH a dashboard card on it (mt/with-temp* [Dashboard [{dashboard-id :id}] @@ -2257,9 +2256,9 @@ (deftest dashcard-action-create-update-test (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (doseq [action-type [:http :implicit :query]] - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type action-type :visualization_settings {:hello true}}] + (mt/with-actions [{:keys [action-id model-id]} {:type action-type :visualization_settings {:hello true}}] (testing (str "Creating dashcard with action: " action-type) (mt/with-temp* [Dashboard [{dashboard-id :id}]] (is (partial= {:visualization_settings {:label "Update"} @@ -2278,8 +2277,8 @@ (deftest dashcard-query-action-execution-test (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-and-actions-enabled - (actions.test-util/with-actions [{:keys [action-id model-id]} {}] + (mt/with-actions-test-data-and-actions-enabled + (mt/with-actions [{:keys [action-id model-id]} {}] (testing "Executing dashcard with action" (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id @@ -2323,8 +2322,8 @@ (deftest dashcard-http-action-execution-test (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-and-actions-enabled - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :http}] + (mt/with-actions-test-data-and-actions-enabled + (mt/with-actions [{:keys [action-id model-id]} {:type :http}] (testing "Executing dashcard with action" (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id @@ -2356,9 +2355,9 @@ (deftest dashcard-implicit-action-execution-test (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (testing "Executing dashcard insert" - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/create"}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/create"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :card_id model-id @@ -2381,7 +2380,7 @@ (mt/user-http-request :crowberto :post 400 execute-path {:parameters {}})))))))) (testing "Executing dashcard update" - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/update"}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/update"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :card_id model-id @@ -2404,7 +2403,7 @@ (mt/user-http-request :crowberto :post 400 execute-path {:parameters {"id" 1}})))))))) (testing "Executing dashcard delete" - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/delete"}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/delete"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :card_id model-id @@ -2449,13 +2448,13 @@ {:field-name "adatetime" :base-type :type/DateTime #_#_::good "2020-02-02 14:39:59"} ;; Difference between h2 and postgres, in and out {:field-name "adatetimetz" :base-type :type/DateTimeWithTZ #_#_::good "2020-02-02 14:39:59-0700" ::bad "not date"}]] - (actions.test-util/with-temp-test-data + (mt/with-temp-test-data ["types" (map #(dissoc % ::good ::bad) types) [["init"]]] - (actions.test-util/with-actions-enabled - (actions.test-util/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} - {:keys [action-id]} {:type :implicit :kind "row/create"}] + (mt/with-actions-enabled + (mt/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} + {:keys [action-id]} {:type :implicit :kind "row/create"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :action_id action-id @@ -2471,8 +2470,8 @@ (is (partial= {field-name value} (zipmap (map (comp str/lower-case :name) cols) (last rows)))))) - (actions.test-util/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} - {:keys [action-id]} (custom-action-for-field field-name)] + (mt/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} + {:keys [action-id]} (custom-action-for-field field-name)] (mt/with-temp DashboardCard [{custom-dashcard-id :id} {:dashboard_id dashboard-id :action_id action-id :card_id card-id}] @@ -2493,8 +2492,8 @@ (mt/user-http-request :crowberto :post 400 (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id) {:parameters {field-name value}})))) - (actions.test-util/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} - {action-id :action-id} (custom-action-for-field field-name)] + (mt/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query types)} + {action-id :action-id} (custom-action-for-field field-name)] (mt/with-temp DashboardCard [{custom-dashcard-id :id} {:dashboard_id dashboard-id :action_id action-id :card_id card-id}] @@ -2506,9 +2505,9 @@ (deftest dashcard-implicit-action-execution-auth-test (mt/with-temp-copy-of-db - (actions.test-util/with-actions-test-data + (mt/with-actions-test-data (testing "Executing dashcard with action" - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/create"}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit :kind "row/create"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :action_id action-id @@ -2521,14 +2520,14 @@ (mt/user-http-request :crowberto :post 400 execute-path {:parameters {"name" "Birds"}})))) (testing "Without execute rights on the DB" - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (is (partial= {:message "You do not have permissions to run this query."} (mt/user-http-request :rasta :post 403 execute-path {:parameters {"name" "Birds"}}))))) (testing "With execute rights on the DB" (perms/update-global-execution-permission! (:id (perms-group/all-users)) :all) (try - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (is (contains? #{{:ID 76, :NAME "Birds"} {:id 76, :name "Birds"}} (-> (mt/user-http-request :rasta :post 200 execute-path @@ -2539,8 +2538,8 @@ (deftest dashcard-custom-action-execution-auth-test (mt/with-temp-copy-of-db - (actions.test-util/with-actions-test-data - (actions.test-util/with-actions [{:keys [action-id model-id]} {}] + (mt/with-actions-test-data + (mt/with-actions [{:keys [action-id model-id]} {}] (testing "Executing dashcard with action" (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id @@ -2554,14 +2553,14 @@ (mt/user-http-request :crowberto :post 400 execute-path {:parameters {"id" 1}})))) (testing "Without execute rights on the DB" - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (is (partial= {:message "You don't have permissions to do that."} (mt/user-http-request :rasta :post 403 execute-path {:parameters {"id" 1}}))))) (testing "With execute rights on the DB" (perms/update-global-execution-permission! (:id (perms-group/all-users)) :all) (try - (actions.test-util/with-actions-enabled + (mt/with-actions-enabled (is (= {:rows-affected 1} (mt/user-http-request :rasta :post 200 execute-path {:parameters {"id" 1}})))) @@ -2570,9 +2569,9 @@ (deftest dashcard-execution-fetch-prefill-test (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (testing "Prefetching dashcard update" - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :card_id model-id @@ -2589,10 +2588,10 @@ (deftest dashcard-implicit-action-only-expose-and-allow-model-fields (mt/test-drivers (mt/normal-drivers-with-feature :actions) - (actions.test-util/with-actions-test-data-tables #{"venues" "categories"} - (actions.test-util/with-actions-test-data-and-actions-enabled - (actions.test-util/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query venues {:fields [$id $name]})} - {:keys [action-id]} {:type :implicit :kind "row/update"}] + (mt/with-actions-test-data-tables #{"venues" "categories"} + (mt/with-actions-test-data-and-actions-enabled + (mt/with-actions [{card-id :id} {:dataset true :dataset_query (mt/mbql-query venues {:fields [$id $name]})} + {:keys [action-id]} {:type :implicit :kind "row/update"}] (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id :action_id action-id @@ -2618,9 +2617,9 @@ (deftest dashcard-action-execution-granular-auth-test (when (ee-features-enabled?) (mt/with-temp-copy-of-db - (actions.test-util/with-actions-enabled - (actions.test-util/with-actions-test-data - (actions.test-util/with-actions [{:keys [action-id model-id]} {}] + (mt/with-actions-enabled + (mt/with-actions-test-data + (mt/with-actions [{:keys [action-id model-id]} {}] (testing "Executing dashcard with action" (mt/with-temp* [Dashboard [{dashboard-id :id}] DashboardCard [{dashcard-id :id} diff --git a/test/metabase/api/public_test.clj b/test/metabase/api/public_test.clj index 3665e3cbaacfaa0374281b07ef6a814f3d7423eb..1777c56e6cb11b7e8ff29a054c0feb4fadd2a364 100644 --- a/test/metabase/api/public_test.clj +++ b/test/metabase/api/public_test.clj @@ -5,7 +5,6 @@ [clojure.string :as str] [clojure.test :refer :all] [dk.ative.docjure.spreadsheet :as spreadsheet] - [metabase.actions.test-util :as actions.test-util] [metabase.api.card-test :as api.card-test] [metabase.api.dashboard-test :as api.dashboard-test] [metabase.api.pivots :as api.pivots] @@ -1220,10 +1219,10 @@ (is (= [nil nil nil 7 1015 3758] (last rows))))))))))))))) (deftest execute-public-dashcard-action-test - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (mt/with-temporary-setting-values [enable-public-sharing true] (with-temp-public-dashboard [dash {:parameters []}] - (actions.test-util/with-actions [{:keys [action-id model-id]} {}] + (mt/with-actions [{:keys [action-id model-id]} {}] (mt/with-temp* [DashboardCard [{dashcard-id :id} {:dashboard_id (:id dash) :action_id action-id :card_id model-id}]] @@ -1247,10 +1246,10 @@ (deftest execute-public-dashcard-custom-action-test (mt/with-temp-copy-of-db (perms/revoke-data-perms! (perms-group/all-users) (mt/db)) - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (mt/with-temporary-setting-values [enable-public-sharing true] (with-temp-public-dashboard [dash {:parameters []}] - (actions.test-util/with-actions [{:keys [action-id model-id]} {}] + (mt/with-actions [{:keys [action-id model-id]} {}] (mt/with-temp* [DashboardCard [{dashcard-id :id} {:dashboard_id (:id dash) :action_id action-id :card_id model-id}]] @@ -1263,10 +1262,10 @@ {:parameters {:id 1 :name "European"}})))))))))) (deftest fetch-public-dashcard-action-test - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-and-actions-enabled (mt/with-temporary-setting-values [enable-public-sharing true] (with-temp-public-dashboard [dash {:parameters []}] - (actions.test-util/with-actions [{:keys [action-id model-id]} {:type :implicit}] + (mt/with-actions [{:keys [action-id model-id]} {:type :implicit}] (mt/with-temp* [DashboardCard [{dashcard-id :id} {:dashboard_id (:id dash) :action_id action-id :card_id model-id}]] diff --git a/test/metabase/driver/sql_jdbc/actions_test.clj b/test/metabase/driver/sql_jdbc/actions_test.clj index fcb4e2955844af244c5285f67c856d02c138c4db..20fcfb8e67d311b1a927758b5a97214056c8c326 100644 --- a/test/metabase/driver/sql_jdbc/actions_test.clj +++ b/test/metabase/driver/sql_jdbc/actions_test.clj @@ -4,7 +4,6 @@ (:require [clojure.test :refer :all] [metabase.actions :as actions] - [metabase.actions.test-util :as actions.test-util] [metabase.api.common :refer [*current-user-permissions-set*]] [metabase.driver :as driver] [metabase.driver.sql-jdbc.actions :as sql-jdbc.actions] @@ -40,8 +39,8 @@ (deftest parse-sql-error-catch-exceptions-test (testing "If parse-sql-error throws an Exception, log it and return the unparsed exception instead of failing entirely (#24021)" (driver/with-driver ::parse-sql-error-exception - (actions.test-util/with-actions-test-data-tables #{"venues" "categories"} - (actions.test-util/with-actions-test-data-and-actions-enabled + (mt/with-actions-test-data-tables #{"venues" "categories"} + (mt/with-actions-test-data-and-actions-enabled (reset! parse-sql-error-called? false) ;; attempting to delete the `Pizza` category should fail because there are several rows in `venues` that have ;; this `category_id` -- it's an FK constraint violation. diff --git a/test/metabase/models/action_test.clj b/test/metabase/models/action_test.clj index a6c1cc1532dc2906ff162baa19b692bbde99e6f1..e6cb47eab32ceceb6827a5d544027b12df967dc6 100644 --- a/test/metabase/models/action_test.clj +++ b/test/metabase/models/action_test.clj @@ -1,14 +1,13 @@ (ns metabase.models.action-test (:require [clojure.test :refer :all] - [metabase.actions.test-util :as actions.test-util] [metabase.models.action :as action] [metabase.test :as mt])) (deftest hydrate-query-action-test (mt/test-drivers (mt/normal-drivers-with-feature :actions/custom) - (actions.test-util/with-actions-test-data-and-actions-enabled - (actions.test-util/with-actions [{:keys [model-id action-id] :as _context} {}] + (mt/with-actions-test-data-and-actions-enabled + (mt/with-actions [{:keys [model-id action-id] :as _context} {}] (is (partial= {:id action-id :name "Query Example" @@ -18,8 +17,8 @@ (deftest hydrate-http-action-test (mt/test-drivers (mt/normal-drivers-with-feature :actions/custom) - (actions.test-util/with-actions-test-data-and-actions-enabled - (actions.test-util/with-actions [{:keys [action-id] :as _context} {:type :http}] + (mt/with-actions-test-data-and-actions-enabled + (mt/with-actions [{:keys [action-id] :as _context} {:type :http}] (is (partial= {:id action-id :name "Echo Example" diff --git a/test/metabase/test.clj b/test/metabase/test.clj index 71fedddb7b9837bc27bf7761950789fcb2ae134a..83ba4bed0624fa919e0f226c6f5cf41c652ca2b5 100644 --- a/test/metabase/test.clj +++ b/test/metabase/test.clj @@ -11,6 +11,7 @@ [humane-are.core :as humane-are] [java-time :as t] [medley.core :as m] + [metabase.actions.test-util :as actions.test-util] [metabase.config :as config] [metabase.driver :as driver] [metabase.driver.sql-jdbc.test-util :as sql-jdbc.tu] @@ -85,6 +86,14 @@ ;; Add more stuff here as needed (p/import-vars + [actions.test-util + with-actions + with-actions-enabled + with-actions-test-data + with-actions-test-data-tables + with-actions-test-data-and-actions-enabled + with-temp-test-data] + [data $ids dataset diff --git a/test/metabase/test/data/interface.clj b/test/metabase/test/data/interface.clj index 4303750b515842ab072013bf3d7edc395264d615..5feb05ed2fcbcb3f94ab065a52e42c8e87219452 100644 --- a/test/metabase/test/data/interface.clj +++ b/test/metabase/test/data/interface.clj @@ -51,7 +51,7 @@ ;; this was added pretty recently (in the 44 cycle) so it might not be supported everywhere. It should work for ;; drivers using `:sql/test-extensions` and [[metabase.test.data.sql/field-definition-sql]] but you might need to add ;; support for it elsewhere if you want to use it. It only really matters for testing things that modify test - ;; datasets e.g. [[metabase.actions.test-util/with-actions-test-data]] + ;; datasets e.g. [[mt/with-actions-test-data]] (s/optional-key :not-null?) (s/maybe s/Bool) (s/optional-key :semantic-type) (s/maybe su/FieldSemanticOrRelationType) (s/optional-key :effective-type) (s/maybe su/FieldType)