|
15 | 15 | [metabase.models
|
16 | 16 | [field :refer [Field]]
|
17 | 17 | [table :as table :refer [Table]]]
|
18 |
| - [metabase.test.data :as data] |
19 | 18 | [metabase.test.data.interface :as tx]
|
20 | 19 | [taoensso.nippy :as nippy]
|
21 |
| - [toucan.db :as db] |
22 |
| - [toucan.util.test :as tt]) |
| 20 | + [toucan.db :as db]) |
23 | 21 | (:import org.bson.types.ObjectId))
|
24 | 22 |
|
25 | 23 | ;; ## Constants + Helper Fns/Macros
|
|
83 | 81 | (-> (qp/process-query {:native {:query native-query
|
84 | 82 | :collection "venues"}
|
85 | 83 | :type :native
|
86 |
| - :database (data/id)}) |
| 84 | + :database (mt/id)}) |
87 | 85 | (m/dissoc-in [:data :results_metadata] [:data :insights]))))))
|
88 | 86 |
|
89 | 87 | ;; ## Tests for individual syncing functions
|
|
94 | 92 | {:schema nil, :name "categories"}
|
95 | 93 | {:schema nil, :name "users"}
|
96 | 94 | {:schema nil, :name "venues"}}}
|
97 |
| - (driver/describe-database :mongo (data/db)))))) |
| 95 | + (driver/describe-database :mongo (mt/db)))))) |
98 | 96 |
|
99 | 97 | (deftest describe-table-test
|
100 | 98 | (mt/test-driver :mongo
|
|
119 | 117 | :database-type "java.lang.Long"
|
120 | 118 | :base-type :type/Integer
|
121 | 119 | :pk? true}}}
|
122 |
| - (driver/describe-table :mongo (data/db) (Table (data/id :venues))))))) |
| 120 | + (driver/describe-table :mongo (mt/db) (Table (mt/id :venues))))))) |
123 | 121 |
|
124 | 122 | (deftest nested-columns-test
|
125 | 123 | (mt/test-driver :mongo
|
|
141 | 139 |
|
142 | 140 | (deftest all-num-columns-test
|
143 | 141 | (mt/test-driver :mongo
|
144 |
| - (data/dataset all-null-columns |
| 142 | + (mt/dataset all-null-columns |
145 | 143 | (is (= [{:name "_id", :database_type "java.lang.Long", :base_type :type/Integer, :special_type :type/PK}
|
146 | 144 | {:name "favorite_snack", :database_type "NULL", :base_type :type/*, :special_type nil}
|
147 | 145 | {:name "name", :database_type "java.lang.String", :base_type :type/Text, :special_type :type/Name}]
|
148 | 146 | (map
|
149 | 147 | (partial into {})
|
150 | 148 | (db/select [Field :name :database_type :base_type :special_type]
|
151 |
| - :table_id (data/id :bird_species) |
| 149 | + :table_id (mt/id :bird_species) |
152 | 150 | {:order-by [:name]})))))))
|
153 | 151 |
|
154 | 152 | (deftest table-rows-sample-test
|
155 | 153 | (mt/test-driver :mongo
|
156 |
| - (driver/sync-in-context :mongo (data/db) |
| 154 | + (driver/sync-in-context :mongo (mt/db) |
157 | 155 | (fn []
|
158 | 156 | (is (= [[1 "Red Medicine"]
|
159 | 157 | [2 "Stout Burgers & Beers"]
|
160 | 158 | [3 "The Apple Pan"]
|
161 | 159 | [4 "Wurstküche"]
|
162 | 160 | [5 "Brite Spot Family Restaurant"]]
|
163 |
| - (vec (take 5 (metadata-queries/table-rows-sample (Table (data/id :venues)) |
164 |
| - [(Field (data/id :venues :id)) |
165 |
| - (Field (data/id :venues :name))]))))))))) |
| 161 | + (vec (take 5 (metadata-queries/table-rows-sample (Table (mt/id :venues)) |
| 162 | + [(Field (mt/id :venues :id)) |
| 163 | + (Field (mt/id :venues :name))]))))))))) |
166 | 164 |
|
167 | 165 |
|
168 | 166 | ;; ## Big-picture tests for the way data should look post-sync
|
|
173 | 171 | {:active true, :name "users"}
|
174 | 172 | {:active true, :name "venues"}]
|
175 | 173 | (for [field (db/select [Table :name :active]
|
176 |
| - :db_id (data/id) |
| 174 | + :db_id (mt/id) |
177 | 175 | {:order-by [:name]})]
|
178 | 176 | (into {} field)))
|
179 | 177 | "Test that Tables got synced correctly")))
|
|
200 | 198 | (vec (for [table-name table-names]
|
201 | 199 | (vec (for [field (db/select [Field :name :base_type :special_type]
|
202 | 200 | :active true
|
203 |
| - :table_id (data/id table-name) |
| 201 | + :table_id (mt/id table-name) |
204 | 202 | {:order-by [:name]})]
|
205 | 203 | (into {} field))))))))))
|
206 | 204 |
|
|
215 | 213 | (deftest bson-ids-test
|
216 | 214 | (mt/test-driver :mongo
|
217 | 215 | (is (= [[2 "Lucky Pigeon" (ObjectId. "abcdefabcdefabcdefabcdef")]]
|
218 |
| - (rows (data/dataset with-bson-ids |
219 |
| - (data/run-mbql-query birds |
| 216 | + (rows (mt/dataset with-bson-ids |
| 217 | + (mt/run-mbql-query birds |
220 | 218 | {:filter [:= $bird_id "abcdefabcdefabcdefabcdef"]}))))
|
221 | 219 | "Check that we support Mongo BSON ID and can filter by it (#1367)")))
|
222 | 220 |
|
|
226 | 224 | (letfn [(rows-count [query]
|
227 | 225 | (count (rows (qp/process-query {:native query
|
228 | 226 | :type :native
|
229 |
| - :database (data/id)}))))] |
230 |
| - (data/dataset with-bson-ids |
| 227 | + :database (mt/id)}))))] |
| 228 | + (mt/dataset with-bson-ids |
231 | 229 | (is (= 1
|
232 | 230 | (rows-count {:query "[{\"$match\": {\"bird_id\": ObjectId(\"abcdefabcdefabcdefabcdef\")}}]"
|
233 | 231 | :collection "birds"}))))
|
|
251 | 249 | (mt/test-driver :mongo
|
252 | 250 | (testing "make sure x-rays don't use features that the driver doesn't support"
|
253 | 251 | (is (= true
|
254 |
| - (->> (magic/automagic-analysis (Field (data/id :venues :price)) {}) |
| 252 | + (->> (magic/automagic-analysis (Field (mt/id :venues :price)) {}) |
255 | 253 | :ordered_cards
|
256 | 254 | (mapcat (comp :breakout :query :dataset_query :card))
|
257 |
| - (not-any? #{[:binning-strategy [:field-id (data/id :venues :price)] "default"]}))))))) |
| 255 | + (not-any? #{[:binning-strategy [:field-id (mt/id :venues :price)] "default"]}))))))) |
258 | 256 |
|
259 | 257 | (deftest no-values-test
|
260 | 258 | (mt/test-driver :mongo
|
261 | 259 | (testing (str "if we query a something an there are no values for the Field, the query should still return "
|
262 | 260 | "successfully! (#8929 and #8894)")
|
263 | 261 | ;; add a temporary Field that doesn't actually exist to test data categories
|
264 |
| - (tt/with-temp Field [_ {:name "parent_id", :table_id (data/id :categories)}] |
| 262 | + (mt/with-temp Field [_ {:name "parent_id", :table_id (mt/id :categories)}] |
265 | 263 | ;; ok, now run a basic MBQL query against categories Table. When implicit Field IDs get added the `parent_id`
|
266 | 264 | ;; Field will be included
|
267 | 265 | (testing (str "if the column does not come back in the results for a given document we should fill in the "
|
|
270 | 268 | [2 "American" nil]
|
271 | 269 | [3 "Artisan" nil]]}
|
272 | 270 | (->
|
273 |
| - (data/run-mbql-query categories |
| 271 | + (mt/run-mbql-query categories |
274 | 272 | {:order-by [[:asc [:field-id $id]]]
|
275 | 273 | :limit 3})
|
276 | 274 | qp.t/data
|
|
287 | 285 | (is (= [[22]]
|
288 | 286 | (mt/rows
|
289 | 287 | (qp/process-query
|
290 |
| - {:database (data/id) |
291 |
| - :type :native |
292 |
| - :native {:projections [:count] |
293 |
| - :query [{"$project" {"price" "$price"}} |
294 |
| - {"$match" {"price" {"$eq" 1}}} |
295 |
| - {"$group" {"_id" nil, "count" {"$sum" 1}}} |
296 |
| - {"$sort" {"_id" 1}} |
297 |
| - {"$project" {"_id" false, "count" true}}] |
298 |
| - :collection "venues"}}))))))) |
| 288 | + {:database (mt/id) |
| 289 | + :type :native |
| 290 | + :native {:projections [:count] |
| 291 | + :query [{"$project" {"price" "$price"}} |
| 292 | + {"$match" {"price" {"$eq" 1}}} |
| 293 | + {"$group" {"_id" nil, "count" {"$sum" 1}}} |
| 294 | + {"$sort" {"_id" 1}} |
| 295 | + {"$project" {"_id" false, "count" true}}] |
| 296 | + :collection "venues"}}))))))) |
0 commit comments