Skip to content
Snippets Groups Projects
Commit 59209257 authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #150 from metabase/search_choices_test

lots-of-tests
parents 4e406387 f9af6202
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
(defendpoint GET "/form_input" [org]
(require-params org)
(check-403 ((:perms-for-org @*current-user*) org))
(let [dbs (databases-for-org org)]
{:permissions common/permissions
......@@ -24,6 +25,7 @@
(defendpoint GET "/" [org f]
(require-params org)
(check-403 ((:perms-for-org @*current-user*) org))
(-> (case (or (keyword f) :all) ; default value for `f` is `:all`
:all (sel :many Query
......
......@@ -15,7 +15,8 @@
(defn fetch-query [uuid]
((user->client :rasta) :get (format "qs/%s" uuid)))
;; POST /api/qs
;; ## POST /api/qs
;; Test that we can create a Query
(expect-eval-actual-first
(match-$ (sel :one QueryExecution (order :id :desc))
......@@ -27,7 +28,8 @@
(-> (create-query)
(dissoc :status))) ; status is a race condition and can be either 'running' or 'completed'
;; GET /api/qs/:uuid
;; ## GET /api/qs/:uuid
;; Can we fetch the results of a Query ?
(expect-eval-actual-first
(match-$ (sel :one QueryExecution (order :id :desc))
......@@ -42,3 +44,11 @@
(let [{uuid :uuid} (create-query)]
(Thread/sleep 100) ; this query is simple as f**k. Give it 100ms to complete
(fetch-query uuid))) ; if it doesn't by then our QP might be brokesies
;; ## GET /api/qs/:uuid/csv
(expect-eval-actual-first
"count(*)\n75\n"
(let [{uuid :uuid} (create-query)]
(Thread/sleep 50)
((user->client :rasta) :get 200 (format "qs/%s/csv" uuid))))
......@@ -15,6 +15,26 @@
:sql "SELECT COUNT(*) FROM VENUES;"}
kwargs)))
;; ## GET /api/query/form_input
(expect
{:databases [(match-$ @test-db
{:id $
:name "Test Database"})]
:timezones ["GMT"
"UTC"
"US/Alaska"
"US/Arizona"
"US/Central"
"US/Eastern"
"US/Hawaii"
"US/Mountain"
"US/Pacific"
"America/Costa_Rica"]
:permissions [{:name "None", :id 0}
{:name "Read Only", :id 1}
{:name "Read & Write", :id 2}]}
((user->client :rasta) :get 200 "query/form_input" :org (:id @test-org)))
;; ## POST /api/query (create)
;; Check that we can save a Query
(expect-eval-actual-first
......@@ -158,3 +178,69 @@
;; wait 100ms for QueryExecution to complete. If it takes longer than that, it's probably brokesies
(Thread/sleep 100)
((user->client :rasta) :get 200 (format "query/%d/results" id)))]))
;; ## GET /api/query
;; Fetch Queries for the current Org
(expect-eval-actual-first
(let [[query-1 query-2] (sel :many Query :database_id (:id @test-db) (order :id :ASC))
rasta (match-$ (fetch-user :rasta)
{:common_name "Rasta Toucan"
:date_joined $
:last_name "Toucan"
:id $
:is_superuser false
:last_login $
:first_name "Rasta"
:email "rasta@metabase.com"})
db (match-$ @test-db
{:created_at $
:engine "h2"
:id $
:details $
:updated_at $
:name "Test Database"
:organization_id (:id @test-org)
:description nil})]
[(match-$ query-1
{:creator rasta
:database_id (:id @test-db)
:name $
:type "rawsql"
:creator_id (user->id :rasta)
:updated_at $
:details {:timezone nil
:sql "SELECT COUNT(*) FROM VENUES;"}
:id $
:database db
:version 1
:public_perms 0
:created_at $})
(match-$ query-2
{:creator rasta
:database_id (:id @test-db)
:name $
:type "rawsql"
:creator_id (user->id :rasta)
:updated_at $
:details {:timezone nil
:sql "SELECT COUNT(*) FROM VENUES;"}
:id $
:database db
:version 1
:public_perms 0
:created_at $})])
(do (cascade-delete Query :database_id (:id @test-db))
(create-query)
(create-query)
((user->client :rasta) :get 200 "query" :org (:id @test-org))))
;; ## POST /api/query/:id/csv
(expect-eval-actual-first
"count(*)\n100\n"
(let [{query-id :id} (create-query)]
((user->client :rasta) :post 200 (format "query/%d" query-id))
;; 50ms should be long enough for query to finish
(Thread/sleep 50)
((user->client :rasta) :get 200 (format "query/%d/csv" query-id))))
......@@ -13,7 +13,7 @@
[]
(let [{query-id :id} (create-query)
query-execution ((user->client :rasta) :post 200 (format "query/%d" query-id))]
(Thread/sleep 100) ; Give it 100ms to finish
(Thread/sleep 50) ; Give it 50ms to finish
query-execution))
;; ## GET /result/:id
......@@ -52,3 +52,10 @@
:row_count 1})
(let [{execution-id :id} (create-and-execute-query)]
((user->client :rasta) :get 200 (format "result/%d/response" execution-id))))
;; ## GET /result/:id/csv
(expect-eval-actual-first
"count(*)\n100\n"
(let [{execution-id :id} (create-and-execute-query)]
((user->client :rasta) :get 200 (format "result/%d/csv" execution-id))))
(ns metabase.api.search-test
"Tests for /api/search endpoints."
(:require [expectations :refer :all]
[korma.core :refer :all]
[metabase.db :refer :all]
[metabase.test.util :refer [match-$ expect-eval-actual-first random-name]]
[metabase.test-data :refer :all]))
;; ## GET /api/search/model_choices
(expect
{:choices {:metabase {:card "Cards"
:dashboard "Dashboards"
:database "Databases"
:field "Fields"
:table "Tables"}}}
((user->client :lucky) :get 200 "search/model_choices"))
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