Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Boxiang Sun
slapos.core
Commits
2f9a27f8
Commit
2f9a27f8
authored
Jul 28, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test_cli: add test for slapos request sub command
parent
a244d797
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
1 deletion
+50
-1
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+50
-1
No files found.
slapos/tests/test_cli.py
View file @
2f9a27f8
...
@@ -49,10 +49,12 @@ import slapos.cli.computer_info
...
@@ -49,10 +49,12 @@ import slapos.cli.computer_info
import
slapos.cli.computer_list
import
slapos.cli.computer_list
import
slapos.cli.computer_token
import
slapos.cli.computer_token
import
slapos.cli.supervisorctl
import
slapos.cli.supervisorctl
import
slapos.cli.request
from
slapos.cli.proxy_show
import
do_show
,
StringIO
from
slapos.cli.proxy_show
import
do_show
,
StringIO
from
slapos.cli.cache
import
do_lookup
as
cache_do_lookup
from
slapos.cli.cache
import
do_lookup
as
cache_do_lookup
from
slapos.cli.cache_source
import
do_lookup
as
cache_source_do_lookup
from
slapos.cli.cache_source
import
do_lookup
as
cache_source_do_lookup
from
slapos.client
import
ClientConfig
from
slapos.client
import
ClientConfig
from
slapos.slap
import
SoftwareProductCollection
import
slapos.grid.svcbackend
import
slapos.grid.svcbackend
import
slapos.proxy
import
slapos.proxy
import
slapos.slap
import
slapos.slap
...
@@ -65,8 +67,8 @@ def raiseNotFoundError(*args, **kwargs):
...
@@ -65,8 +67,8 @@ def raiseNotFoundError(*args, **kwargs):
class
CliMixin
(
unittest
.
TestCase
):
class
CliMixin
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
self
.
local
=
{
'slap'
:
slap
}
self
.
logger
=
create_autospec
(
logging
.
Logger
)
self
.
logger
=
create_autospec
(
logging
.
Logger
)
self
.
local
=
{
'slap'
:
slap
,
'product'
:
SoftwareProductCollection
(
self
.
logger
,
slap
)}
self
.
conf
=
create_autospec
(
ClientConfig
)
self
.
conf
=
create_autospec
(
ClientConfig
)
class
TestCliCache
(
CliMixin
):
class
TestCliCache
(
CliMixin
):
...
@@ -641,3 +643,50 @@ class TestCliComplete(CliMixin):
...
@@ -641,3 +643,50 @@ class TestCliComplete(CliMixin):
with
patch
.
object
(
sys
,
'stdout'
,
StringIO
())
as
app_stdout
:
with
patch
.
object
(
sys
,
'stdout'
,
StringIO
())
as
app_stdout
:
self
.
assertEqual
(
slapos
.
cli
.
entry
.
SlapOSApp
().
run
([
'complete'
,
'--shell=fish'
]),
0
)
self
.
assertEqual
(
slapos
.
cli
.
entry
.
SlapOSApp
().
run
([
'complete'
,
'--shell=fish'
]),
0
)
self
.
assertIn
(
'__fish_seen_subcommand_from'
,
app_stdout
.
getvalue
())
self
.
assertIn
(
'__fish_seen_subcommand_from'
,
app_stdout
.
getvalue
())
class
TestCliRequest
(
CliMixin
):
def
test_parse_option_dict
(
self
):
parse_option_dict
=
slapos
.
cli
.
request
.
parse_option_dict
self
.
assertEqual
(
parse_option_dict
([
'foo=bar'
,
'a=b'
]),
{
'foo'
:
'bar'
,
'a'
:
'b'
})
# malformed option = assignment
self
.
assertRaises
(
ValueError
,
parse_option_dict
,
[
'a'
])
# duplicated key
self
.
assertRaises
(
ValueError
,
parse_option_dict
,
[
'a=b'
,
'a=c'
])
# corner cases
self
.
assertEqual
(
parse_option_dict
([
'a=a=b'
]),
{
'a'
:
'a=b'
})
self
.
assertEqual
(
parse_option_dict
([
'a=a
\
n
b'
]),
{
'a'
:
'a
\
n
b'
})
self
.
assertEqual
(
parse_option_dict
([]),
{})
def
test_request
(
self
):
self
.
conf
.
reference
=
'instance reference'
self
.
conf
.
software_url
=
'software URL'
self
.
conf
.
parameters
=
{
'key'
:
'value'
}
self
.
conf
.
parameters_file
=
None
self
.
conf
.
node
=
{
'computer_guid'
:
'COMP-1234'
}
self
.
conf
.
type
=
None
self
.
conf
.
state
=
None
self
.
conf
.
slave
=
False
with
patch
.
object
(
slapos
.
slap
.
slap
,
'registerOpenOrder'
,
return_value
=
mock
.
create_autospec
(
slapos
.
slap
.
OpenOrder
))
as
registerOpenOrder
:
slapos
.
cli
.
request
.
do_request
(
self
.
logger
,
self
.
conf
,
self
.
local
)
registerOpenOrder
().
request
.
assert_called_once_with
(
software_release
=
'software URL'
,
partition_reference
=
'instance reference'
,
partition_parameter_kw
=
{
'key'
:
'value'
},
software_type
=
None
,
filter_kw
=
{
'computer_guid'
:
'COMP-1234'
},
state
=
None
,
shared
=
False
,
)
self
.
logger
.
info
.
assert_any_call
(
'Requesting %s as instance of %s...'
,
'instance reference'
,
'software URL'
,
)
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