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
Labels
Merge Requests
17
Merge Requests
17
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
0fe48bb0
Commit
0fe48bb0
authored
Mar 09, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: Adapt slapos service info tests
Adapt the tests to take news and 'status' field into consideration.
parent
1b5415cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
29 deletions
+67
-29
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+65
-29
slapos/tests/test_slapproxy.py
slapos/tests/test_slapproxy.py
+2
-0
No files found.
slapos/tests/test_cli.py
View file @
0fe48bb0
##############################################################################
#
#
# Copyright (c) 2013 Vifib SARL and Contributors. All Rights Reserved.
# Copyright (c) 2013 Vifib SARL and Contributors. All Rights Reserved.
#
#
...
@@ -40,7 +40,7 @@ import pkg_resources
...
@@ -40,7 +40,7 @@ import pkg_resources
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
mock
import
patch
,
create_autospec
from
mock
import
patch
,
create_autospec
import
mock
import
mock
from
slapos.util
import
sqlite_connect
,
bytes2str
,
UndefinedSerializationError
from
slapos.util
import
sqlite_connect
,
bytes2str
,
UndefinedSerializationError
,
dict2xml
from
slapos.slap.slap
import
DEFAULT_SOFTWARE_TYPE
from
slapos.slap.slap
import
DEFAULT_SOFTWARE_TYPE
import
slapos.cli.console
import
slapos.cli.console
...
@@ -617,45 +617,81 @@ class TestCliList(CliMixin):
...
@@ -617,45 +617,81 @@ class TestCliList(CliMixin):
class
TestCliInfo
(
CliMixin
):
class
TestCliInfo
(
CliMixin
):
def
test_info_xml_serialisation
(
self
,
_
):
def
test_info_xml_serialisation
(
self
,
_
):
self
.
_test_info_output
(
self
.
_test_info_output
(
self
.
_make_fake_instance
())
slapos
.
slap
.
SoftwareInstance
(
_software_release_url
=
'SR1'
,
_requested_state
=
'mystate'
,
_connection_dict
=
'<?xml version=
\
'
1.0
\
'
encoding=
\
'
utf-8
\
'
?>
\
n
<instance>
\
n
<parameter id="myconnectionparameter">value1</parameter>
\
n
</instance>
\
n
'
,
_parameter_dict
=
{
'myinstanceparameter'
:
'value2'
}))
def
test_info_json_in_serialisation
(
self
,
_
):
def
test_info_json_in_serialisation
(
self
,
_
):
self
.
_test_info_output
(
self
.
_make_fake_instance
(
xml
=
False
))
def
test_info_status_none
(
self
,
_
):
self
.
_test_info_output
(
self
.
_make_fake_instance
(
news
=
[{
'text'
:
'toto'
}]),
status
=
'none'
)
def
test_info_status_green
(
self
,
_
):
self
.
_test_info_output
(
self
.
_make_fake_instance
(
news
=
[{
'text'
:
'#access'
},
{
'text'
:
'toto'
}]),
status
=
'green'
)
def
test_info_status_red
(
self
,
_
):
self
.
_test_info_output
(
self
.
_make_fake_instance
(
news
=
[{
'text'
:
'#error'
},
{
'text'
:
'toto'
}]),
status
=
'red'
)
def
test_info_status_orange
(
self
,
_
):
self
.
_test_info_output
(
self
.
_make_fake_instance
(
news
=
[{
'text'
:
'#error'
},
{
'text'
:
'#access'
},
{
'text'
:
'toto'
}]),
status
=
'orange'
)
def
test_info_news
(
self
,
_
):
news
=
[{
'text'
:
'toto'
}]
self
.
_test_info_output
(
self
.
_test_info_output
(
slapos
.
slap
.
SoftwareInstance
(
self
.
_make_fake_instance
(
_software_release_url
=
'SR1'
,
news
=
news
),
_requested_state
=
'mystate'
,
status
=
'none'
,
_connection_dict
=
news
=
news
)
'<?xml version=
\
'
1.0
\
'
encoding=
\
'
utf-8
\
'
?>
\
n
<instance>
\
n
<parameter id="_">{"myconnectionparameter": "value1"}</parameter>
\
n
</instance>
\
n
'
,
_parameter_dict
=
{
'myinstanceparameter'
:
'value2'
}))
def
_make_fake_instance
(
self
,
xml
=
True
,
news
=
None
):
conn
=
{
'myconnectionparameter'
:
'value1'
}
def
_test_info_output
(
self
,
instance
):
if
xml
:
conn_params
=
dict2xml
(
conn
)
else
:
conn_params
=
'<instance>
\
n
<parameter id="_">%s</parameter>
\
n
</instance>'
%
json
.
dumps
(
conn
)
instance
=
slapos
.
slap
.
SoftwareInstance
(
_software_release_url
=
'SR1'
,
_requested_state
=
'mystate'
,
_connection_dict
=
conn_params
,
_parameter_dict
=
{
'myinstanceparameter'
:
'value2'
})
if
news
:
instance
.
_news
=
{
'instance'
:
news
}
return
instance
def
_test_info_output
(
self
,
instance
,
status
=
"unsupported"
,
news
=
None
):
"""
"""
Test "slapos service info" command output.
Test "slapos service info" command output.
"""
"""
setattr
(
self
.
conf
,
'reference'
,
'instance1'
)
setattr
(
self
.
conf
,
'reference'
,
'instance1'
)
setattr
(
self
.
conf
,
'news'
,
bool
(
news
))
with
patch
.
object
(
slapos
.
slap
.
OpenOrder
,
'getInformation'
,
with
patch
.
object
(
slapos
.
slap
.
OpenOrder
,
'getInformation'
,
return_value
=
instance
):
return_value
=
instance
):
slapos
.
cli
.
info
.
do_info
(
self
.
logger
,
self
.
conf
,
self
.
local
)
slapos
.
cli
.
info
.
do_info
(
self
.
logger
,
self
.
conf
,
self
.
local
)
if
six
.
PY3
:
if
six
.
PY3
:
self
.
logger
.
info
.
assert_called_once_with
(
expected
=
{
textwrap
.
dedent
(
'''
\
"software-url"
:
instance
.
_software_release_url
,
{
"instance-state"
:
instance
.
_requested_state
,
"software-url": "SR1"
,
"instance-parameters"
:
instance
.
_parameter_dict
,
"instance-state": "mystate",
"connection-parameters"
:
{
"
instance-parameters": {
"
myconnectionparameter"
:
"value1"
"myinstanceparameter": "value2"
},
},
"status"
:
status
"connection-parameters": {
}
"myconnectionparameter": "value1"
if
news
:
}
expected
[
'news'
]
=
news
}'''
))
self
.
logger
.
info
.
assert_called_once_with
(
json
.
dumps
(
expected
,
indent
=
2
))
def
test_unknownReference
(
self
,
_
):
def
test_unknownReference
(
self
,
_
):
"""
"""
...
...
slapos/tests/test_slapproxy.py
View file @
0fe48bb0
...
@@ -1301,6 +1301,7 @@ class TestCliInformation(CliMasterMixin):
...
@@ -1301,6 +1301,7 @@ class TestCliInformation(CliMasterMixin):
"instance-state"
:
"busy"
,
"instance-state"
:
"busy"
,
"instance-parameters"
:
{},
"instance-parameters"
:
{},
"connection-parameters"
:
{},
"connection-parameters"
:
{},
"status"
:
"unsupported"
,
},
},
)
)
output1
=
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance1'
),
stderr
=
subprocess
.
DEVNULL
)
output1
=
self
.
cliDoSlapos
((
'service'
,
'info'
,
'MyInstance1'
),
stderr
=
subprocess
.
DEVNULL
)
...
@@ -1311,6 +1312,7 @@ class TestCliInformation(CliMasterMixin):
...
@@ -1311,6 +1312,7 @@ class TestCliInformation(CliMasterMixin):
"instance-state"
:
"busy"
,
"instance-state"
:
"busy"
,
"instance-parameters"
:
{
"couscous"
:
"hello"
},
"instance-parameters"
:
{
"couscous"
:
"hello"
},
"connection-parameters"
:
{},
"connection-parameters"
:
{},
"status"
:
"unsupported"
,
},
},
)
)
try
:
try
:
...
...
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