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
32060350
Commit
32060350
authored
7 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Test cleanup
parent
02ce7ff4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/metabase/sync_database/analyze_test.clj
+50
-48
50 additions, 48 deletions
test/metabase/sync_database/analyze_test.clj
test/metabase/test/data.clj
+2
-0
2 additions, 0 deletions
test/metabase/test/data.clj
with
52 additions
and
48 deletions
test/metabase/sync_database/analyze_test.clj
+
50
−
48
View file @
32060350
(
ns
metabase.sync-database.analyze-test
(
:require
[
clojure.string
:as
str
]
[
expectations
:refer
:all
]
[
metabase
[
driver
:as
driver
]
[
util
:as
u
]]
[
metabase.db.metadata-queries
:as
metadata-queries
]
[
metabase.models
[
field
:refer
[
Field
]]
[
table
:as
table
:refer
[
Table
]]]
[
metabase.sync-database.analyze
:refer
:all
]
[
metabase.test
[
data
:as
data
]
[
util
:as
tu
]]
[
metabase.test.data.users
:refer
:all
]
[
metabase.test.util
:as
tu
]
[
toucan.db
:as
db
]
[
toucan.util.test
:as
tt
]
[
metabase.driver
:as
driver
]
[
metabase.models.field
:as
field
]))
[
toucan.util.test
:as
tt
]))
;; test:cardinality-and-extract-field-values
;; (#2332) check that if field values are long we skip over them
...
...
@@ -29,8 +32,8 @@
;;; ## mark-json-field!
(
tu/resolve-private-vars
metabase.sync-database.analyze
values-are-valid-json?
)
(
tu/resolve-private-vars
metabase.sync-database.analyze
values-are-valid-emails?
)
(
tu/resolve-private-vars
metabase.sync-database.analyze
values-are-valid-json?
values-are-valid-emails?
)
(
def
^
:const
^
:private
fake-values-seq-json
"A sequence of values that should be marked is valid JSON."
)
...
...
@@ -81,28 +84,28 @@
(
expect
false
(
values-are-valid-emails?
[
"false"
]))
;; Tests to avoid analyzing hidden tables
(
defn
count-unanalyzed-fields
[
db_id
table-name
]
(
let
[
table-id
(
db/select-one-id
Table,
:db_id
db_id,
:active
true
:name
table-name
)]
(
assert
(
pos?
;; don't let ourselves be fooled if the test passes because the table is
;; totally broken or has no fields. Make sure we actually test something
(
db/count
Field
:table_id
table-id
)))
(
db/count
Field
:last_analyzed
nil
:table_id
table-id
)))
(
defn
latest-sync-time
[
table
]
(
let
[
table-id
(
db/select-one-id
Table
:db_id
(
:db_id
table
)
:active
true
:name
(
:name
table
))]
(
db/select-field
:last_analyzed
Field
:table_id
table-id
)))
(
defn
set-table-visibility-type!
[
table
visibility-type
]
(
defn-
unanalyzed-fields-count
[
table
]
(
assert
(
pos?
;; don't let ourselves be fooled if the test passes because the table is
;; totally broken or has no fields. Make sure we actually test something
(
db/count
Field
:table_id
(
u/get-id
table
))))
(
db/count
Field
:last_analyzed
nil,
:table_id
(
u/get-id
table
)))
(
defn-
latest-sync-time
[
table
]
(
db/select-one-field
:last_analyzed
Field
:last_analyzed
[
:not=
nil
]
:table_id
(
u/get-id
table
)
{
:order-by
[[
:last_analyzed
:desc
]]}))
(
defn-
set-table-visibility-type!
[
table
visibility-type
]
((
user->client
:crowberto
)
:put
200
(
format
"table/%d"
(
:id
table
))
{
:display_name
"hiddentable"
:entity_type
"person"
:visibility_type
visibility-type
:description
"What a nice table!"
}))
(
defn
api-sync
-call
[
table
]
((
user->client
:crowberto
)
:post
200
(
format
"database/%d/sync"
(
:db_id
table
))
{}
))
(
defn
-
api-sync
!
[
table
]
((
user->client
:crowberto
)
:post
200
(
format
"database/%d/sync"
(
:db_id
table
))))
(
defn
sync-call
[
table
]
(
defn
-
analyze!
[
table
]
(
let
[
db-id
(
:db_id
table
)]
(
analyze-data-shape-for-tables!
(
driver/database-id->driver
db-id
)
{
:id
db-id
})))
...
...
@@ -111,44 +114,43 @@
1
(
tt/with-temp*
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
(
do
(
set-table-visibility-type!
table
"hidden"
)
(
api-sync-call
table
)
(
set-table-visibility-type!
table
"cruft"
)
(
set-table-visibility-type!
table
"cruft"
)
(
api-sync-call
table
)
(
set-table-visibility-type!
table
"technical"
)
(
api-sync-call
table
)
(
set-table-visibility-type!
table
"technical"
)
(
api-sync-call
table
)
(
api-sync-call
table
)
(
count-unanalyzed-fields
(
:db_id
table
)
(
:name
table
)))))
(
set-table-visibility-type!
table
"hidden"
)
(
api-sync!
table
)
(
set-table-visibility-type!
table
"cruft"
)
(
set-table-visibility-type!
table
"cruft"
)
(
api-sync!
table
)
(
set-table-visibility-type!
table
"technical"
)
(
api-sync!
table
)
(
set-table-visibility-type!
table
"technical"
)
(
api-sync!
table
)
(
api-sync!
table
)
(
unanalyzed-fields-count
table
)))
;; same test not coming through the api
(
expect
1
(
tt/with-temp*
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
(
do
(
set-table-visibility-type!
table
"hidden"
)
(
sync-call
table
)
(
set-table-visibility-type!
table
"cruft"
)
(
set-table-visibility-type!
table
"cruft"
)
(
sync-call
table
)
(
set-table-visibility-type!
table
"technical"
)
(
sync-call
table
)
(
set-table-visibility-type!
table
"technical"
)
(
sync-call
table
)
(
sync-call
table
)
(
count-
unanalyzed-fields
(
:db_id
table
)
(
:name
table
)))
))
(
set-table-visibility-type!
table
"hidden"
)
(
analyze!
table
)
(
set-table-visibility-type!
table
"cruft"
)
(
set-table-visibility-type!
table
"cruft"
)
(
analyze!
table
)
(
set-table-visibility-type!
table
"technical"
)
(
analyze!
table
)
(
set-table-visibility-type!
table
"technical"
)
(
analyze!
table
)
(
analyze!
table
)
(
unanalyzed-fields
-count
table
)))
;; un-hiding a table should cause it to be analyzed
(
expect
0
(
tt/with-temp*
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
(
do
(
set-table-visibility-type!
table
"hidden"
)
(
set-table-visibility-type!
table
nil
)
(
count-
unanalyzed-fields
(
:db_id
table
)
(
:name
table
)))
))
(
set-table-visibility-type!
table
"hidden"
)
(
set-table-visibility-type!
table
nil
)
(
unanalyzed-fields
-count
table
)))
;; re-hiding a table should not cause it to be analyzed
(
expect
...
...
This diff is collapsed.
Click to expand it.
test/metabase/test/data.clj
+
2
−
0
View file @
32060350
...
...
@@ -9,6 +9,7 @@
[
query-processor
:as
qp
]
[
sync-database
:as
sync-database
]
[
util
:as
u
]]
metabase.driver.h2
[
metabase.models
[
database
:refer
[
Database
]]
[
field
:as
field
:refer
[
Field
]]
...
...
@@ -19,6 +20,7 @@
[
metabase.test.data
[
dataset-definitions
:as
defs
]
[
datasets
:refer
[
*driver*
]]
h2
[
interface
:as
i
]]
[
schema.core
:as
s
]
[
toucan.db
:as
db
])
...
...
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