Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grid5000
g5k-api
Commits
9a16a2e9
Commit
9a16a2e9
authored
Apr 27, 2020
by
Samir Noir
🧀
Browse files
Fix post rspec requests by using `body:` instead of send_payload method
parent
a2b33293
Changes
3
Hide whitespace changes
Inline
Side-by-side
spec/controllers/deployments_controller_spec.rb
View file @
9a16a2e9
...
...
@@ -108,9 +108,9 @@ describe DeploymentsController do
it
"should fail if the deployment is not valid"
do
authenticate_as
(
"crohr"
)
send_
payload
(
@valid_attributes
.
merge
(
"nodes"
=>
[])
,
:json
)
payload
=
@valid_attributes
.
merge
(
"nodes"
=>
[])
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
,
body:
payload
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
.
body
).
to
match
/The deployment you are trying to submit is not valid/
...
...
@@ -122,9 +122,8 @@ describe DeploymentsController do
expect
(
@deployment
).
to
receive
(
:launch_workflow!
).
and_raise
(
Exception
.
new
(
"some error message"
))
authenticate_as
(
"crohr"
)
send_payload
(
@valid_attributes
,
:json
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
,
body:
@valid_attributes
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
body
).
to
eq
(
"Cannot launch deployment: some error message"
)
...
...
@@ -137,9 +136,8 @@ describe DeploymentsController do
expect
(
@deployment
).
to
receive
(
:launch_workflow!
).
and_return
(
nil
)
authenticate_as
(
"crohr"
)
send_payload
(
@valid_attributes
,
:json
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
,
body:
@valid_attributes
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
body
).
to
eq
(
"Cannot launch deployment: Uid must be set"
)
...
...
@@ -159,9 +157,8 @@ describe DeploymentsController do
@deployment
.
uid
=
"kadeploy-api-provided-wid"
authenticate_as
(
"crohr"
)
send_payload
(
@valid_attributes
,
:json
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
,
body:
@valid_attributes
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
headers
[
'Location'
]).
to
eq
(
"http://api-in.local/sites/rennes/deployments/kadeploy-api-provided-wid"
)
...
...
spec/controllers/jobs_controller_spec.rb
View file @
9a16a2e9
...
...
@@ -115,7 +115,6 @@ describe JobsController do
it
"should fail if the OAR api does not return 201, 202 or 400"
do
payload
=
@valid_job_attributes
authenticate_as
(
"crohr"
)
send_payload
(
payload
,
:json
)
expected_url
=
"http://api-out.local/sites/rennes/internal/oarapi/jobs.json"
stub_request
(
:post
,
expected_url
).
...
...
@@ -133,7 +132,7 @@ describe JobsController do
:body
=>
"some error"
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
,
body:
payload
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
400
expect
(
response
.
body
).
to
eq
"Request to
#{
expected_url
}
failed with status 400: some error"
end
...
...
@@ -141,7 +140,6 @@ describe JobsController do
it
"should return a 400 error if the OAR API returns 400 error code"
do
payload
=
@valid_job_attributes
.
merge
(
"resources"
=>
"{ib30g='YES'}/nodes=2"
)
authenticate_as
(
"crohr"
)
send_payload
(
payload
,
:json
)
expected_url
=
"http://api-out.local/sites/rennes/internal/oarapi/jobs.json"
stub_request
(
:post
,
expected_url
).
...
...
@@ -159,7 +157,8 @@ describe JobsController do
:body
=>
"Bad Request"
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
},
body:
payload
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
400
expect
(
response
.
body
).
to
eq
"Request to
#{
expected_url
}
failed with status 400: Bad Request"
end
# "should return a 400 error if the OAR API returns 400 error code"
...
...
@@ -167,7 +166,6 @@ describe JobsController do
it
"should return a 401 error if the OAR API returns 401 error code"
do
payload
=
@valid_job_attributes
authenticate_as
(
"xyz"
)
send_payload
(
payload
,
:json
)
expected_url
=
"http://api-out.local/sites/rennes/internal/oarapi/jobs.json"
stub_request
(
:post
,
expected_url
).
...
...
@@ -185,14 +183,14 @@ describe JobsController do
:body
=>
"Authorization Required"
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
},
body:
payload
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
401
expect
(
response
.
body
).
to
eq
"Request to
#{
expected_url
}
failed with status 401: Authorization Required"
end
# "should return a 401 error if the OAR API returns 400 error code"
it
"should return 201, the job details, and the Location header"
do
payload
=
@valid_job_attributes
authenticate_as
(
"crohr"
)
send_payload
(
payload
,
:json
)
expected_url
=
"http://api-out.local/sites/rennes/internal/oarapi/jobs.json"
stub_request
(
:post
,
expected_url
).
...
...
@@ -215,7 +213,8 @@ describe JobsController do
}
)
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
}
post
:create
,
params:
{
:site_id
=>
"rennes"
,
:format
=>
:json
},
body:
payload
.
to_json
,
as: :json
expect
(
response
.
status
).
to
eq
201
expect
(
JSON
.
parse
(
response
.
body
)).
to
include
({
"uid"
=>
961722
})
expect
(
response
.
location
).
to
eq
"http://api-in.local/sites/rennes/jobs/961722"
...
...
spec/spec_helper.rb
View file @
9a16a2e9
...
...
@@ -73,16 +73,6 @@ module HeaderHelper
header
=
"HTTP_"
+
Rails
.
my_config
(
:header_user_cn
).
gsub
(
"-"
,
"_"
).
upcase
@request
.
env
[
header
]
=
username
end
def
send_payload
(
h
,
type
)
case
type
when
:json
@request
.
env
[
'RAW_POST_DATA'
]
=
JSON
.
dump
(
h
)
@request
.
env
[
'CONTENT_TYPE'
]
=
media_type
(
type
)
else
raise
StandardError
,
"Don't know how to send payload of type
#{
type
.
inspect
}
"
end
end
end
RSpec
.
configure
do
|
config
|
...
...
@@ -115,7 +105,7 @@ RSpec.configure do |config|
system
"mv
#{
File
.
join
(
@repository_path
,
'.git'
)
}
#{
File
.
join
(
@repository_path
,
'git.rename'
)
}
"
end
end
config
.
around
(
:each
)
do
|
example
|
Rails
.
logger
.
debug
example
.
metadata
[
:full_description
]
EM
.
synchrony
do
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment