Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
05859d21
Commit
05859d21
authored
8 years ago
by
Cam Saül
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2909 from metabase/even-more-test-cleanup
Even more test cleanup
parents
e6c042e1
d468bf24
Loading
Loading
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/database.clj
+5
-4
5 additions, 4 deletions
src/metabase/api/database.clj
test/metabase/api/activity_test.clj
+40
-39
40 additions, 39 deletions
test/metabase/api/activity_test.clj
test/metabase/api/database_test.clj
+209
-206
209 additions, 206 deletions
test/metabase/api/database_test.clj
with
254 additions
and
249 deletions
src/metabase/api/database.clj
+
5
−
4
View file @
05859d21
...
...
@@ -63,9 +63,9 @@
(
defendpoint
POST
"/"
"Add a new `Database`."
[
:as
{{
:keys
[
name
engine
details
is_full_sync
]}
:body
}]
{
name
[
Required
NonEmptyString
]
engine
[
Required
DBEngine
]
details
[
Required
Dict
]}
{
name
[
Required
NonEmptyString
]
engine
[
Required
DBEngine
]
details
[
Required
Dict
]}
(
check-superuser
)
;; this function tries connecting over ssl and non-ssl to establish a connection
;; if it succeeds it returns the `details` that worked, otherwise it returns an error
...
...
@@ -85,7 +85,8 @@
(
if-not
(
false?
(
:valid
details-or-error
))
;; no error, proceed with creation
(
let-500
[
new-db
(
db/insert!
Database,
:name
name,
:engine
engine,
:details
details-or-error,
:is_full_sync
is_full_sync
)]
(
events/publish-event
:database-create
new-db
))
(
events/publish-event
:database-create
new-db
)
new-db
)
;; failed to connect, return error
{
:status
400
:body
details-or-error
})))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/activity_test.clj
+
40
−
39
View file @
05859d21
...
...
@@ -9,7 +9,7 @@
[
view-log
:refer
[
ViewLog
]])
[
metabase.test.data
:refer
:all
]
[
metabase.test.data.users
:refer
:all
]
[
metabase.test.util
:refer
[
match-$
random-name
expect-with-temp
resolve-private-fns
]]
[
metabase.test.util
:refer
[
match-$
expect-with-temp
resolve-private-fns
]]
[
metabase.util
:as
u
]))
;; GET /
...
...
@@ -99,17 +99,28 @@
:table
nil
:custom_id
nil
:details
$
})]
(
->>
((
user->client
:crowberto
)
:get
200
"activity"
)
(
map
#
(
dissoc
%
:timestamp
)))
)
(
for
[
activity
((
user->client
:crowberto
)
:get
200
"activity"
)
]
(
dissoc
activity
:timestamp
)))
;; GET /recent_views
;;
;
GET /recent_views
; Things we are testing for:
; 1. ordering is sorted by most recent
; 2. results are filtered to current user
; 3. `:model_object` is hydrated in each result
; 4. we filter out entries where `:model_object` is nil (object doesn't exist)
;; Things we are testing for:
;; 1. ordering is sorted by most recent
;; 2. results are filtered to current user
;; 3. `:model_object` is hydrated in each result
;; 4. we filter out entries where `:model_object` is nil (object doesn't exist)
(
defn-
create-view!
[
user
model
model-id
]
(
db/insert!
ViewLog
:user_id
user
:model
model
:model_id
model-id
:timestamp
(
u/new-sql-timestamp
))
;; we sleep a bit to ensure no events have the same timestamp
;; sadly, MySQL doesn't support milliseconds so we have to wait a second
;; otherwise our records are out of order and this test fails :(
(
Thread/sleep
1000
))
(
expect-with-temp
[
Card
[
card1
{
:name
"rand-name"
:creator_id
(
user->id
:crowberto
)
...
...
@@ -127,47 +138,37 @@
:display
"table"
:dataset_query
{}
:visualization_settings
{}}]]
[{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"card"
:model_id
(
:id
card1
)
[{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"card"
:model_id
(
:id
card1
)
:model_object
{
:id
(
:id
card1
)
:name
(
:name
card1
)
:description
(
:description
card1
)
:display
(
name
(
:display
card1
))}}
{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"dashboard"
:model_id
(
:id
dash1
)
{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"dashboard"
:model_id
(
:id
dash1
)
:model_object
{
:id
(
:id
dash1
)
:name
(
:name
dash1
)
:description
(
:description
dash1
)}}
{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"card"
:model_id
(
:id
card2
)
{
:cnt
1
:user_id
(
user->id
:crowberto
)
:model
"card"
:model_id
(
:id
card2
)
:model_object
{
:id
(
:id
card2
)
:name
(
:name
card2
)
:description
(
:description
card2
)
:display
(
name
(
:display
card2
))}}]
(
let
[
create-view
(
fn
[
user
model
model-id
]
(
db/insert!
ViewLog
:user_id
user
:model
model
:model_id
model-id
:timestamp
(
u/new-sql-timestamp
))
;; we sleep a bit to ensure no events have the same timestamp
;; sadly, MySQL doesn't support milliseconds so we have to wait a second
;; otherwise our records are out of order and this test fails :(
(
Thread/sleep
1000
))]
(
do
(
create-view
(
user->id
:crowberto
)
"card"
(
:id
card2
))
(
create-view
(
user->id
:crowberto
)
"dashboard"
(
:id
dash1
))
(
create-view
(
user->id
:crowberto
)
"card"
(
:id
card1
))
(
create-view
(
user->id
:crowberto
)
"card"
36478
)
(
create-view
(
user->id
:rasta
)
"card"
(
:id
card1
))
(
->>
((
user->client
:crowberto
)
:get
200
"activity/recent_views"
)
(
map
#
(
dissoc
%
:max_ts
))))))
(
do
(
create-view!
(
user->id
:crowberto
)
"card"
(
:id
card2
))
(
create-view!
(
user->id
:crowberto
)
"dashboard"
(
:id
dash1
))
(
create-view!
(
user->id
:crowberto
)
"card"
(
:id
card1
))
(
create-view!
(
user->id
:crowberto
)
"card"
36478
)
(
create-view!
(
user->id
:rasta
)
"card"
(
:id
card1
))
(
for
[
recent-view
((
user->client
:crowberto
)
:get
200
"activity/recent_views"
)]
(
dissoc
recent-view
:max_ts
))))
;;; activities->referenced-objects, referenced-objects->existing-objects, add-model-exists-info
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/database_test.clj
+
209
−
206
View file @
05859d21
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment