File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,19 @@ def run_iib_command(**kwargs):
1919 command = iib_command .format (broker )
2020 else :
2121 command = iib_command
22+ output = execute_command (command = command )
23+ return output
24+
25+
26+ def execute_command (command ):
27+ """Executes in shell."""
2228 proc = subprocess .Popen (command ,
2329 shell = True ,
2430 stdout = subprocess .PIPE ,
2531 stderr = subprocess .STDOUT ,
2632 universal_newlines = True )
27- output = proc .communicate ()[0 ]
28- return output
33+ result = proc .communicate ()[0 ]
34+ return result
2935
3036
3137def get_status (status ):
Original file line number Diff line number Diff line change 33import os
44import sys
55import unittest
6- from modules .iib_api import get_status
6+ try :
7+ from unittest .mock import patch
8+ except ImportError :
9+ from mock import patch
10+ from modules .iib_api import (
11+ run_iib_command ,
12+ get_status )
713sys .path .append (os .getcwd ())
814
915
16+ def mock_execute_command (command ):
17+ """Mock for `execute_command` function."""
18+ return command
19+
20+
21+ class TestRunMqCommand (unittest .TestCase ):
22+ @patch ('modules.iib_api.execute_command' , side_effect = mock_execute_command )
23+ def test_run_iib_command (self , execute_command ):
24+ """Tests for `run_iib_command` function."""
25+ self .assertEqual (
26+ run_iib_command (task = 'get_brokers_status' ),
27+ 'mqsilist | grep Broker' )
28+ self .assertEqual (
29+ run_iib_command (task = 'get_broker_objects' , broker_name = 'TEST' ),
30+ 'mqsilist TEST -r' )
31+
32+
1033class TestGetStatus (unittest .TestCase ):
1134 def test_get_status (self ):
1235 """Test for `get_status` function."""
You can’t perform that action at this time.
0 commit comments