Skip to content

Commit 159e10c

Browse files
committed
Add test for iib_api
1 parent e9a2cce commit 159e10c

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

modules/iib_api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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

3137
def get_status(status):

tests/test_iib_api.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,33 @@
33
import os
44
import sys
55
import 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)
713
sys.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+
1033
class TestGetStatus(unittest.TestCase):
1134
def test_get_status(self):
1235
"""Test for `get_status` function."""

0 commit comments

Comments
 (0)