Unit tests added for `get site-statuses
` cli
Change-Id: Ie000d05a34adeb98d7a52adc0839fb1eecf7e218
This commit is contained in:
parent
553acf139f
commit
839e3eb8d2
@ -23,6 +23,7 @@ from shipyard_client.cli.get.actions import GetActions
|
||||
from shipyard_client.cli.get.actions import GetConfigdocs
|
||||
from shipyard_client.cli.get.actions import GetConfigdocsStatus
|
||||
from shipyard_client.cli.get.actions import GetRenderedConfigdocs
|
||||
from shipyard_client.cli.get.actions import GetSiteStatuses
|
||||
from shipyard_client.cli.get.actions import GetWorkflows
|
||||
from tests.unit.cli import stubs
|
||||
|
||||
@ -323,3 +324,66 @@ def test_get_workflows_empty(*args):
|
||||
response = GetWorkflows(stubs.StubCliContext()).invoke_and_return_resp()
|
||||
assert 'None' in response
|
||||
assert 'State' in response
|
||||
|
||||
|
||||
GET_SITE_STATUSES_API_RESP = """
|
||||
{
|
||||
"nodes_provision_status": [
|
||||
{
|
||||
"hostname": "xyz.abc.com",
|
||||
"status": "deployed"},
|
||||
{
|
||||
"hostname": "def.abc.com",
|
||||
"status": "provisioning"}
|
||||
],
|
||||
"machines_powerstate": [
|
||||
{
|
||||
"hostname": "xyz.abc.com",
|
||||
"power_state": "on"},
|
||||
{
|
||||
"hostname": "def.abc.com",
|
||||
"power_state": "off"}
|
||||
]}
|
||||
"""
|
||||
|
||||
|
||||
@responses.activate
|
||||
@mock.patch.object(BaseClient, 'get_endpoint', lambda x: 'http://shiptest')
|
||||
@mock.patch.object(BaseClient, 'get_token', lambda x: 'abc')
|
||||
def test_get_site_statuses(*args):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'http://shiptest/site_statuses',
|
||||
body=GET_SITE_STATUSES_API_RESP,
|
||||
status=200)
|
||||
response = GetSiteStatuses(stubs.StubCliContext()).invoke_and_return_resp()
|
||||
assert 'xyz.abc.com' in response
|
||||
assert 'def.abc.com' in response
|
||||
assert 'deployed' in response
|
||||
assert 'on' in response
|
||||
assert 'off' in response
|
||||
assert 'provisioning' in response
|
||||
assert 'Nodes Provision Status:' in response
|
||||
assert 'Machines Power State:' in response
|
||||
|
||||
|
||||
@responses.activate
|
||||
@mock.patch.object(BaseClient, 'get_endpoint', lambda x: 'http://shiptest')
|
||||
@mock.patch.object(BaseClient, 'get_token', lambda x: 'abc')
|
||||
def test_get_site_statuses_with_filters(*args):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'http://shiptest/site_statuses',
|
||||
body=GET_SITE_STATUSES_API_RESP,
|
||||
status=200)
|
||||
response = GetSiteStatuses(stubs.StubCliContext(),
|
||||
fltr="nodes-provision-status,"
|
||||
"machines-power-state").invoke_and_return_resp()
|
||||
assert 'xyz.abc.com' in response
|
||||
assert 'def.abc.com' in response
|
||||
assert 'deployed' in response
|
||||
assert 'on' in response
|
||||
assert 'off' in response
|
||||
assert 'provisioning' in response
|
||||
assert 'Nodes Provision Status:' in response
|
||||
assert 'Machines Power State:' in response
|
||||
|
@ -17,7 +17,7 @@ from click.testing import CliRunner
|
||||
|
||||
from shipyard_client.cli.get.actions import (
|
||||
GetActions, GetConfigdocs, GetConfigdocsStatus, GetRenderedConfigdocs,
|
||||
GetWorkflows)
|
||||
GetWorkflows, GetSiteStatuses)
|
||||
from shipyard_client.cli.commands import shipyard
|
||||
|
||||
auth_vars = ('--os-project-domain-name=OS_PROJECT_DOMAIN_NAME_test '
|
||||
@ -127,3 +127,33 @@ def test_get_workflows_negative(*args):
|
||||
results = runner.invoke(shipyard,
|
||||
[auth_vars, 'get', 'workflows', invalid_arg])
|
||||
assert 'Error' in results.output
|
||||
|
||||
|
||||
def test_get_site_statuses(*args):
|
||||
"""test get site-statuses"""
|
||||
|
||||
runner = CliRunner()
|
||||
with patch.object(GetSiteStatuses, '__init__') as mock_method:
|
||||
runner.invoke(shipyard, [auth_vars, 'get', 'site-statuses'])
|
||||
mock_method.assert_called_once_with(ANY, '')
|
||||
|
||||
status_type_val1 = 'nodes-provision-status'
|
||||
status_type_val2 = 'machines-power-state'
|
||||
status_type_arg1 = '--status-type={}'.format(status_type_val1)
|
||||
status_type_arg2 = '--status-type={}'.format(status_type_val2)
|
||||
with patch.object(GetSiteStatuses, '__init__') as mock_method:
|
||||
runner.invoke(shipyard,
|
||||
[auth_vars, 'get', 'site-statuses',
|
||||
status_type_arg1, status_type_arg2])
|
||||
mock_method.assert_called_once_with(ANY, status_type_val1 + ',' +
|
||||
status_type_val2)
|
||||
|
||||
|
||||
def test_get_site_statuses_negative(*args):
|
||||
"""Negative unit test for get site-statuses command"""
|
||||
|
||||
invalid_arg = 'invalid_st'
|
||||
runner = CliRunner()
|
||||
results = runner.invoke(shipyard,
|
||||
[auth_vars, 'get', 'site-statuses', invalid_arg])
|
||||
assert 'Error' in results.output
|
||||
|
Loading…
x
Reference in New Issue
Block a user