Skip to content

Commit

Permalink
Testcase fix
Browse files Browse the repository at this point in the history
tendrl-bug-id: Tendrl#1080
bugzilla: 1688630

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
  • Loading branch information
GowthamShanmugam committed Apr 21, 2019
1 parent 5e05f56 commit 48cd65c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tendrl/commons/tests/manager/test_manager_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def job_consume():
return "Thread Consuming Job"
monkeypatch.setattr(jobs, 'JobConsumerThread', job_consume)
manager = Manager("test")
assert manager._sds_sync_thread is "test"
assert manager._sds_sync_thread == "test"
assert manager._message_handler_thread is None
assert manager._job_consumer_thread == "Thread Consuming Job"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import maps
import mock
from mock import patch
import pytest

from tendrl.commons.flows.exceptions import FlowExecutionFailedError
from tendrl.commons.objects.node.flows.stop_services import \
StopServices
import tendrl.commons.objects.node_context as node
Expand All @@ -27,11 +29,18 @@ def service_success(param):


def service_failed(param):
return 'error', '', 0
return '', 'error', 0


def service_info(*args, **kwargs):
return {"exists": True, "running": True}
return {"exists": True, "running": True, "error": []}


def service_error(*args, **kwargs):
return {"exists": True,
"running": False,
"error": ["/tmp permission"]
}


def mock_log(*args, **kwargs):
Expand Down Expand Up @@ -106,6 +115,6 @@ def test_run():
assert ret_val is True
with patch.object(logger, 'log', mock_log):
with patch.object(cmd_utils.Command, 'run', service_failed):
with patch.object(Service, 'get_service_info', service_info):
ret_val = obj.run()
assert ret_val is False
with patch.object(Service, 'get_service_info', service_error):
with pytest.raises(FlowExecutionFailedError):
obj.run()
2 changes: 1 addition & 1 deletion tendrl/commons/tests/objects/test_objects_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_save():
with patch.object(Client, "write", return_value=True):
with patch.object(Client, "read",
return_value=maps.NamedDict(value="")):
obj.save(True)
obj.save(True)
with patch.object(Client, "write", return_value=True):
with patch.object(objects.BaseObject, "_hash",
return_value=None):
Expand Down
8 changes: 4 additions & 4 deletions tendrl/commons/tests/utils/test_ansible_module_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def test_AnsibleExecutableGenerationFailed_constructor():
ansible_obj = AnsibleExecutableGenerationFailed()
assert ansible_obj.message == "Executabe could not be generated for " \
"module None . Error: None"
ansible_obj = AnsibleExecutableGenerationFailed(module_path="Test\path",
ansible_obj = AnsibleExecutableGenerationFailed(module_path="Test\\path",
arguments="temp_args",
err="No Error")
assert ansible_obj.message == "Executabe could not be generated for " \
"module Test\path . Error: No Error"
"module Test\\path . Error: No Error"


def test_AnsibleModuleNotFound_constructor():
ansible_obj = AnsibleModuleNotFound()
assert ansible_obj.message == "Ansible module None not found"
ansible_obj = AnsibleModuleNotFound(module_path="Test\path")
assert ansible_obj.message == "Ansible module Test\path not found"
ansible_obj = AnsibleModuleNotFound(module_path="Test\\path")
assert ansible_obj.message == "Ansible module Test\\path not found"


@mock.patch('tendrl.commons.event.Event.__init__',
Expand Down
8 changes: 4 additions & 4 deletions tendrl/commons/tests/utils/test_service_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def test_constructor():

def test_status():
service_status = ServiceStatus("service_status")
ret = service_status.status()
ret, _ = service_status.status()
assert ret is False
with patch.object(cmd_utils.Command, 'run') as mock_run:
mock_run.return_value = run(True)
ret = service_status.status()
ret, _ = service_status.status()
assert ret is False
with patch.object(cmd_utils.Command, 'run') as mock_run:
mock_run.return_value = run(False)
ret = service_status.status()
ret, _ = service_status.status()
assert ret is True


def test_exists():
service_status = ServiceStatus("service_status")
ret = service_status.exists()
ret, _ = service_status.exists()
assert ret is False

0 comments on commit 48cd65c

Please sign in to comment.