/test/metabase/sync/sync_metadata/tables_test.clj

https://github.com/metabase/metabase · Clojure · 41 lines · 38 code · 3 blank · 0 comment · 3 complexity · bf48380ce4d89495fc31d533514a89c3 MD5 · raw file

  1. (ns metabase.sync.sync-metadata.tables-test
  2. "Test for the logic that syncs Table models with the metadata fetched from a DB."
  3. (:require [clojure.test :refer :all]
  4. [metabase
  5. [models :refer [Database Table]]
  6. [test :as mt]
  7. [util :as u]]
  8. [metabase.sync.sync-metadata.tables :as sync-tables]
  9. [metabase.test.data.interface :as tx]
  10. [toucan.db :as db]))
  11. (tx/defdataset ^:private db-with-some-cruft
  12. [["acquired_toucans"
  13. [{:field-name "species", :base-type :type/Text}
  14. {:field-name "cam_has_acquired_one", :base-type :type/Boolean}]
  15. [["Toco" false]
  16. ["Chestnut-Mandibled" true]
  17. ["Keel-billed" false]
  18. ["Channel-billed" false]]]
  19. ["south_migrationhistory"
  20. [{:field-name "app_name", :base-type :type/Text}
  21. {:field-name "migration", :base-type :type/Text}]
  22. [["main" "0001_initial"]
  23. ["main" "0002_add_toucans"]]]])
  24. (deftest crufty-tables-test
  25. (testing "south_migrationhistory, being a CRUFTY table, should still be synced, but marked as such"
  26. (mt/dataset metabase.sync.sync-metadata.tables-test/db-with-some-cruft
  27. (is (= #{{:name "SOUTH_MIGRATIONHISTORY", :visibility_type :cruft}
  28. {:name "ACQUIRED_TOUCANS", :visibility_type nil}}
  29. (set (for [table (db/select [Table :name :visibility_type], :db_id (mt/id))]
  30. (into {} table))))))))
  31. (deftest retire-tables-test
  32. (testing "`retire-tables!` should retire the Table(s) passed to it, not all Tables in the DB -- see #9593"
  33. (mt/with-temp* [Database [db]
  34. Table [table-1 {:name "Table 1", :db_id (u/get-id db)}]
  35. Table [table-2 {:name "Table 2", :db_id (u/get-id db)}]]
  36. (#'sync-tables/retire-tables! db #{{:name "Table 1", :schema (:schema table-1)}})
  37. (is (= {"Table 1" false, "Table 2" true}
  38. (db/select-field->field :name :active Table, :db_id (u/get-id db)))))))