salt/tests/unit/cli/batch_test.py
Colton Myers 000de95974 Merge remote-tracking branch 'upstream/2015.2' into merge-forward-develop
Conflicts:
    .pylintrc
    doc/ref/runners/all/salt.runners.nacl.rst
    doc/topics/cloud/config.rst
    salt/cli/salt.py
    salt/client/mixins.py
    salt/client/ssh/__init__.py
    salt/loader.py
    salt/minion.py
    salt/modules/cassandra_cql.py
    salt/modules/gpg.py
    salt/modules/grains.py
    salt/modules/iptables.py
    salt/modules/yumpkg.py
    salt/netapi/rest_cherrypy/app.py
    salt/renderers/pyobjects.py
    salt/returners/mysql.py
    salt/runners/jobs.py
    salt/state.py
    salt/states/file.py
    salt/states/service.py
    salt/utils/minions.py
    tests/integration/__init__.py
    tests/integration/netapi/rest_tornado/test_app.py
    tests/integration/states/cmd.py
2015-04-16 12:15:44 -06:00

70 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
'''
# Import python libs
from __future__ import absolute_import
# Import Salt Libs
from salt.cli.batch import Batch
# Import Salt Testing Libs
from salttesting import skipIf, TestCase
from salttesting.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
@skipIf(NO_MOCK, NO_MOCK_REASON)
class BatchTestCase(TestCase):
'''
Unit Tests for the salt.cli.batch module
'''
def setUp(self):
opts = {'batch': '', 'conf_file': {}, 'tgt': '', 'transport': '', 'timeout': 5}
mock_client = MagicMock()
with patch('salt.client.get_local_client', MagicMock(return_value=mock_client)):
with patch('salt.client.LocalClient.cmd_iter', MagicMock(return_value=[])):
self.batch = Batch(opts, quiet='quiet')
# get_bnum tests
def test_get_bnum(self):
'''
Tests passing batch value as a number
'''
self.batch.opts = {'batch': '2', 'timeout': 5}
self.batch.minions = ['foo', 'bar']
self.assertEqual(Batch.get_bnum(self.batch), 2)
def test_get_bnum_percentage(self):
'''
Tests passing batch value as percentage
'''
self.batch.opts = {'batch': '50%', 'timeout': 5}
self.batch.minions = ['foo']
self.assertEqual(Batch.get_bnum(self.batch), 1)
def test_get_bnum_high_percentage(self):
'''
Tests passing batch value as percentage over 100%
'''
self.batch.opts = {'batch': '160%', 'timeout': 5}
self.batch.minions = ['foo', 'bar', 'baz']
self.assertEqual(Batch.get_bnum(self.batch), 4)
def test_get_bnum_invalid_batch_data(self):
'''
Tests when an invalid batch value is passed
'''
ret = Batch.get_bnum(self.batch)
self.assertEqual(ret, None)
if __name__ == '__main__':
from integration import run_tests
run_tests(BatchTestCase, needs_daemon=False)