Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
slapos
Commits
a510c252
Commit
a510c252
authored
Oct 06, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request: Fix and update test
parent
d14d41d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
17 deletions
+61
-17
slapos/recipe/request.py
slapos/recipe/request.py
+3
-3
slapos/test/recipe/test_request.py
slapos/test/recipe/test_request.py
+58
-14
No files found.
slapos/recipe/request.py
View file @
a510c252
...
...
@@ -277,10 +277,10 @@ class Recipe(object):
def
_getFilteredParameterDict
(
self
,
partition_dict
,
return_parameter_list
):
result
=
{}
parameters
=
json_loads_byteified
(
partition_dict
.
get
(
"parameters"
,
"{}"
)
)
parameters
=
partition_dict
.
get
(
"connection_parameters"
,
"{}"
)
for
key
in
return_parameter_list
:
if
key
in
parameters
:
result
[
key
]
=
parameters
[
"key"
]
result
[
key
]
=
parameters
[
key
]
return
result
def
install
(
self
):
...
...
@@ -349,7 +349,7 @@ class JSONCodec(object):
return
{}
def
_getFilteredParameterDict
(
self
,
partition_dict
,
return_parameter_list
):
parameters
=
json_loads_byteified
(
partition
.
get
(
"parameters"
,
"{}"
)
)
parameters
=
partition_dict
.
get
(
"connection_parameters"
,
"{}"
)
if
JSON_SERIALISED_MAGIC_KEY
in
parameters
:
return
json
.
loads
(
parameters
[
JSON_SERIALISED_MAGIC_KEY
])
return
{}
...
...
slapos/test/recipe/test_request.py
View file @
a510c252
...
...
@@ -202,33 +202,77 @@ class RecipejIOTestMixin:
])
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
with
LogCapture
()
as
log
:
#import pdb; pdb.set_trace()
self
.
recipe
(
self
.
buildout
,
"request"
,
self
.
options
)
log
.
check
(
(
'request'
,
'DEBUG'
,
'No parameter to return to main instance.Be careful about that...'
),
)
expected_request_body
=
{
"software_release_uri"
:
"foo.cfg"
,
"title"
:
"MyInstance"
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
"slappartx12"
,
"state"
:
"started"
,
"compute_node_id"
:
"COMP-321"
,
"software_type"
:
"RootSoftwareInstance"
}
if
self
.
called_partition_parameter_kw
:
expected_request_body
[
"parameters"
]
=
json
.
dumps
(
self
.
called_partition_parameter_kw
)
self
.
assertEqual
(
api_handler
.
request_payload_list
[
0
],
json
.
dumps
({
"software_release_uri"
:
"foo.cfg"
,
"title"
:
"MyInstance"
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
"slappartx12"
,
"state"
:
"started"
,
"compute_node_id"
:
"COMP-321"
,
"software_type"
:
"RootSoftwareInstance"
}))
api_handler
.
request_payload_list
[
0
],
json
.
dumps
(
expected_request_body
))
def
test_return_in_options_logs
(
self
):
pass
api_handler
=
APIRequestHandler
([
(
"/api/get"
,
json
.
dumps
(
self
.
instance_data
)),
])
self
.
options
[
'return'
]
=
'anything'
with
httmock
.
HTTMock
(
api_handler
.
request_handler
):
with
LogCapture
()
as
log
:
self
.
recipe
(
self
.
buildout
,
"request"
,
self
.
options
)
log
.
check
()
expected_request_body
=
{
"software_release_uri"
:
"foo.cfg"
,
"title"
:
"MyInstance"
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
"slappartx12"
,
"state"
:
"started"
,
"compute_node_id"
:
"COMP-321"
,
"software_type"
:
"RootSoftwareInstance"
}
if
self
.
called_partition_parameter_kw
:
expected_request_body
[
"parameters"
]
=
json
.
dumps
(
self
.
called_partition_parameter_kw
)
self
.
assertEqual
(
api_handler
.
request_payload_list
[
0
],
json
.
dumps
(
expected_request_body
))
self
.
assertEqual
(
self
.
options
[
"connection-anything"
],
"done"
)
def
test_return_not_ready
(
self
):
"""
def test_return_not_ready(self):
pass
def test_return_ready(self):
pass
"""
class
RequestjIOTest
(
RecipejIOTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
Recipe
connection_parameter_dict_empty
=
{}
connection_parameter_dict
=
{
"foo"
:
"bar"
}
connection_parameter_dict
=
{
"anything"
:
"done"
}
called_partition_parameter_kw
=
None
class
RequestjIOAPIOptionalTest
(
RecipejIOTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
RequestOptional
connection_parameter_dict_empty
=
{}
connection_parameter_dict
=
{
"anything"
:
"done"
}
called_partition_parameter_kw
=
None
class
RequestjIOAPIJSONEncodedTest
(
RecipejIOTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
RequestJSONEncoded
connection_parameter_dict_empty
=
{}
connection_parameter_dict
=
{
"_"
:
'{"anything": "done"}'
}
called_partition_parameter_kw
=
{
"_"
:
"{}"
}
class
RequestjIOAPIOptionalJSONEncodedTest
(
RecipejIOTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
RequestOptionalJSONEncoded
connection_parameter_dict_empty
=
{}
connection_parameter_dict
=
{
"_"
:
'{"anything": "done"}'
}
called_partition_parameter_kw
=
{
"_"
:
"{}"
}
Write
Preview
Markdown
is supported
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