Skip to content
Snippets Groups Projects
Commit 8d6908ec authored by Cam Saul's avatar Cam Saul
Browse files

some test fixes

parent 25f4ab87
No related branches found
No related tags found
No related merge requests found
......@@ -176,28 +176,7 @@
;; ## SEL
(comment
:id->field `(let [[entity# field#] ~entity]
(->> (sel :many :fields [entity# field# :id] ~@forms)
(map (fn [{id# :id field-val# field#}]
{id# field-val#}))
(into {})))
:field->id `(let [[entity# field#] ~entity]
(->> (sel :many :fields [entity# field# :id] ~@forms)
(map (fn [{id# :id field-val# field#}]
{field-val# id#}))
(into {})))
:field->field `(let [[entity# field1# field2#] ~entity]
(->> (sel :many entity# ~@forms)
(map (fn [obj#]
{(field1# obj#) (field2# obj#)}))
(into {})))
:field->obj `(let [[entity# field#] ~entity]
(->> (sel :many entity# ~@forms)
(map (fn [obj#]
{(field# obj#) obj#}))
(into {})))
)
(def ^:dynamic *sel-disable-logging* false)
(defmacro sel
"Wrapper for korma `select` that calls `post-select` on results and provides a few other conveniences.
......
......@@ -82,9 +82,10 @@
;; Log if applicable
(future
(when (config/config-bool :mb-db-logging)
(log/debug "DB CALL: " (:name entity)
(or (:fields entity+fields) "*")
(s/replace log-str #"korma.core/" ""))))
(when-not @(resolve 'metabase.db/*sel-disable-logging*)
(log/debug "DB CALL: " (:name entity)
(or (:fields entity+fields) "*")
(s/replace log-str #"korma.core/" "")))))
(->> (k/exec (select-fn entity+fields))
(map (partial models/internal-post-select entity))
......
......@@ -109,7 +109,7 @@
(contains? field :special_type))
(future (create-field-values-if-needed (sel :one [this :id :table_id :base_type :special_type :field_type] :id id)))))
(post-select [_ {:keys [table_id parent_id] :as field}]
(post-select [this {:keys [table_id parent_id] :as field}]
(map->FieldInstance
(u/assoc* field
:table (delay (sel :one 'metabase.models.table/Table :id table_id))
......@@ -118,8 +118,8 @@
:human_readable_name (when (name :field)
(delay (common/name->human-readable-name (:name field))))
:parent (when parent_id
(delay (sel :one Field :id parent_id)))
:children (delay (sel :many Field :parent_id (:id field)))
(delay (this parent_id)))
:children (delay (sel :many this :parent_id (:id field)))
:qualified-name-components (delay (qualified-name-components <>))
:qualified-name (delay (apply str (interpose "." @(:qualified-name-components <>)))))))
......
......@@ -153,8 +153,9 @@
[entity id]
(when id
(when (metabase.config/config-bool :mb-db-logging)
(clojure.tools.logging/debug
"DB CALL: " (:name entity) id))
(when-not @(resolve 'metabase.db/*sel-disable-logging*)
(clojure.tools.logging/debug
"DB CALL: " (:name entity) id)))
(let [[obj] (k/select (assoc entity :fields (::default-fields entity))
(k/where {:id id})
(k/limit 1))]
......
......@@ -160,11 +160,118 @@
:base_type "TextField"
:parent_id nil
:parent nil})]
;; :field_values {}
:field_values {}
:rows 75
:updated_at $
:entity_name nil
:active true
:id (id :categories)
:db_id (db-id)
:created_at $})
((user->client :rasta) :get 200 (format "meta/table/%d/query_metadata" (id :categories))))
(def ^:private user-last-login-date-strs
"In an effort to be really annoying, the date strings returned by the API are different on Circle than they are locally.
Generate strings like '2014-01-01' at runtime so we get matching values."
(let [format-inst (fn [^java.util.Date inst]
(format "%d-%02d-%02d"
(+ (.getYear inst) 1900)
(+ (.getMonth inst) 1)
(.getDate inst)))]
(->> data/test-data
:table-definitions
first
:rows
(map second)
(map format-inst)
set
sort
vec)))
;;; GET api/meta/table/:id/query_metadata?include_sensitive_fields
;;; Make sure that getting the User table *does* include info about the password field, but not actual values themselves
(expect
(match-$ (sel :one Table :id (id :users))
{:description nil
:entity_type nil
:db (match-$ (db)
{:created_at $
:engine "h2"
:id $
:updated_at $
:name "Test Database"
:organization_id nil
:description nil})
:name "USERS"
:fields [(match-$ (sel :one Field :id (id :users :id))
{:description nil
:table_id (id :users)
:special_type "id"
:name "ID"
:updated_at $
:active true
:id $
:field_type "info"
:position 0
:target nil
:preview_display true
:created_at $
:base_type "BigIntegerField"
:parent_id nil
:parent nil})
(match-$ (sel :one Field :id (id :users :last_login))
{:description nil
:table_id (id :users)
:special_type "category"
:name "LAST_LOGIN"
:updated_at $
:active true
:id $
:field_type "info"
:position 0
:target nil
:preview_display true
:created_at $
:base_type "DateTimeField"
:parent_id nil
:parent nil})
(match-$ (sel :one Field :id (id :users :name))
{:description nil
:table_id (id :users)
:special_type "category"
:name "NAME"
:updated_at $
:active true
:id $
:field_type "info"
:position 0
:target nil
:preview_display true
:created_at $
:base_type "TextField"
:parent_id nil
:parent nil})
(match-$ (sel :one Field :table_id (id :users) :name "PASSWORD")
{:description nil
:table_id (id :users)
:special_type "category"
:name "PASSWORD"
:updated_at $
:active true
:id $
:field_type "sensitive"
:position 0
:target nil
:preview_display true
:created_at $
:base_type "TextField"
:parent_id nil
:parent nil})]
:rows 15
:updated_at $
:entity_name nil
:active true
:id (id :users)
:db_id (db-id)
:field_values {(keyword (str (id :users :last_login)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment