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
351fb57f
Unverified
Commit
351fb57f
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Better-organized HTTP client used for tests and add full-response option.
parent
c97e4c2a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/http_client.clj
+22
-11
22 additions, 11 deletions
test/metabase/http_client.clj
with
22 additions
and
11 deletions
test/metabase/http_client.clj
+
22
−
11
View file @
351fb57f
...
...
@@ -120,14 +120,28 @@
url
(
build-url
url
url-param-kwargs
)
method-name
(
s/upper-case
(
name
method
))
;; Now perform the HTTP request
{
:keys
[
status
body
]}
(
try
(
request-fn
url
request-map
)
(
catch
clojure.lang.ExceptionInfo
e
(
log/debug
method-name
url
)
(
:object
(
ex-data
e
))))]
{
:keys
[
status
body
]
:as
resp
}
(
try
(
request-fn
url
request-map
)
(
catch
clojure.lang.ExceptionInfo
e
(
log/debug
method-name
url
)
(
:object
(
ex-data
e
))))]
(
log/debug
method-name
url
status
)
(
check-status-code
method-name
url
body
expected-status
status
)
(
parse-response
body
)))
(
update
resp
:body
parse-response
)))
(
defn-
parse-http-client-args
"Parse the list of required and optional `args` into the various separated params that `-client` requires"
[
args
]
(
let
[[
credentials
[
method
&
args
]]
(
u/optional
#
(
or
(
map?
%
)
(
string?
%
))
args
)
[
expected-status
[
url
&
args
]]
(
u/optional
integer?
args
)
[{
:keys
[
request-options
]}
args
]
(
u/optional
(
every-pred
map?
:request-options
)
args
{
:request-options
{}})
[
body
[
&
{
:as
url-param-kwargs
}]]
(
u/optional
map?
args
)]
[
credentials
method
expected-status
url
body
url-param-kwargs
request-options
]))
(
defn
client-full-response
"Identical to `client` except returns the full HTTP response map, not just the body of the response"
{
:arglists
'
([
credentials?
method
expected-status-code?
url
request-options?
http-body-map?
&
url-kwargs
])}
[
&
args
]
(
apply
-client
(
parse-http-client-args
args
)))
(
defn
client
"Perform an API call and return the response (for test purposes).
...
...
@@ -142,7 +156,8 @@
Args:
* CREDENTIALS Optional map of `:username` and `:password` or `X-METABASE-SESSION` token of a User who we should perform the request as
* CREDENTIALS Optional map of `:username` and `:password` or `X-METABASE-SESSION` token of a User who we
should perform the request as
* METHOD `:get`, `:post`, `:delete`, or `:put`
* EXPECTED-STATUS-CODE When passed, throw an exception if the response has a different status code.
* URL Base URL of the request, which will be appended to `*url-prefix*`. e.g. `card/1/favorite`
...
...
@@ -150,8 +165,4 @@
* URL-KWARGS key-value pairs that will be encoded and added to the URL as GET params"
{
:arglists
'
([
credentials?
method
expected-status-code?
url
request-options?
http-body-map?
&
url-kwargs
])}
[
&
args
]
(
let
[[
credentials
[
method
&
args
]]
(
u/optional
#
(
or
(
map?
%
)
(
string?
%
))
args
)
[
expected-status
[
url
&
args
]]
(
u/optional
integer?
args
)
[{
:keys
[
request-options
]}
args
]
(
u/optional
(
every-pred
map?
:request-options
)
args
{
:request-options
{}})
[
body
[
&
{
:as
url-param-kwargs
}]]
(
u/optional
map?
args
)]
(
-client
credentials
method
expected-status
url
body
url-param-kwargs
request-options
)))
(
:body
(
apply
client-full-response
args
)))
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