tests.support.mock.MagicMock

Here are the examples of the python api tests.support.mock.MagicMock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

213 Examples 7

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_virtual_crm(self, mock_which):
        mock_pkg_version = MagicMock(return_value='1.0.0')
        mock_pkg_version_cmp = MagicMock(return_value=1)

        mock_which.side_effect = [True, True]
        with patch.dict(crmshmod.__salt__, {
                'pkg.version': mock_pkg_version,
                'pkg.version_cmp': mock_pkg_version_cmp}):
            assert crmshmod.__virtual__() == 'crm'
            mock_which.assert_called_once_with(crmshmod.CRM_COMMAND)

    @mock.patch('salt.utils.path.which')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_virtual_ha(self, mock_which):
        mock_pkg_version = MagicMock(return_value='1.0.0')
        mock_pkg_version_cmp = MagicMock(return_value=-1)

        mock_which.side_effect = [True, True]
        with patch.dict(crmshmod.__salt__, {
                'pkg.version': mock_pkg_version,
                'pkg.version_cmp': mock_pkg_version_cmp}):
            assert crmshmod.__virtual__() == 'crm'
            mock_which.assert_has_calls([
                mock.call(crmshmod.CRM_COMMAND),
                mock.call(crmshmod.HA_INIT_COMMAND)
            ])

    @mock.patch('salt.utils.path.which')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_virtual_ha_error(self, mock_which):
        mock_pkg_version = MagicMock(return_value='1.0.0')
        mock_pkg_version_cmp = MagicMock(return_value=-1)

        mock_which.side_effect = [True, False]
        with patch.dict(crmshmod.__salt__, {
                'pkg.version': mock_pkg_version,
                'pkg.version_cmp': mock_pkg_version_cmp}):
            response = crmshmod.__virtual__()
            mock_which.assert_has_calls([
                mock.call(crmshmod.CRM_COMMAND),
                mock.call(crmshmod.HA_INIT_COMMAND)
            ])
            assert response == (
                False,
                'The crmsh execution module failed to load: the ha-cluster-init'
                ' package is not available.')

    def test_status(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_status(self):
        '''
        Test status method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.status()
            assert result
            mock_cmd_run.assert_called_once_with('{crm_command} status'.format(
                crm_command=crmshmod.CRM_COMMAND))

    def test_cluster_status(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_status(self):
        '''
        Test cluster_status method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_status()
            assert result
            mock_cmd_run.assert_called_once_with('{crm_command} cluster status'.format(
                crm_command=crmshmod.CRM_COMMAND))

    def test_cluster_start(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_start(self):
        '''
        Test cluster_start method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_start()
            assert result
            mock_cmd_run.assert_called_once_with('{crm_command} cluster start'.format(
                crm_command=crmshmod.CRM_COMMAND))

    def test_cluster_stop(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_stop(self):
        '''
        Test cluster_stop method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_stop()
            assert result
            mock_cmd_run.assert_called_once_with('{crm_command} cluster stop'.format(
                crm_command=crmshmod.CRM_COMMAND))

    def test_cluster_run(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_run(self):
        '''
        Test cluster_run method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_run('ls -la')
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} cluster run "{cmd}"'.format(
                    crm_command=crmshmod.CRM_COMMAND, cmd='ls -la'))

    def test_cluster_health(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_health(self):
        '''
        Test cluster_health method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_health()
            assert result
            mock_cmd_run.assert_called_once_with('{crm_command} cluster health'.format(
                crm_command=crmshmod.CRM_COMMAND))

    def test_wait_for_startup(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_wait_for_startup(self):
        '''
        Test wait_for_startup method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.wait_for_startup()
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} cluster wait_for_startup'.format(
                    crm_command=crmshmod.CRM_COMMAND))

    def test_wait_for_startup_timeout(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_wait_for_startup_timeout(self):
        '''
        Test wait_for_startup method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.wait_for_startup(5)
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} cluster wait_for_startup {timeout}'.format(
                    crm_command=crmshmod.CRM_COMMAND, timeout=5))

    def test_wait_for_startup_error(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_wait_for_startup_error(self):
        '''
        Test wait_for_startup method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            with pytest.raises(exceptions.SaltInvocationError) as err:
                crmshmod.wait_for_startup(5.0)
            assert 'timeout must be integer type' in str(err.value)

    def test_add_watchdog_sbd(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_add_watchdog_sbd(self):
        '''
        Test _add_watchdog_sbd
        '''
        mock_file_replace = MagicMock()

        with patch.dict(crmshmod.__salt__, {'file.replace': mock_file_replace}):
            crmshmod._add_watchdog_sbd('dog')
            mock_file_replace.assert_called_once_with(
                path='/etc/sysconfig/sbd',
                pattern='^SBD_WATCHDOG_DEV=.*',
                repl='SBD_WATCHDOG_DEV={}'.format('dog'),
                append_if_not_found=True
            )

    def test_add_node_corosync(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_set_corosync_value(self):
        '''
        Test _set_corosync_value
        '''
        mock_cmd_run = MagicMock()

        with patch.dict(crmshmod.__salt__, {'cmd.run': mock_cmd_run}):
            crmshmod._set_corosync_value('path', 'value')
            mock_cmd_run.assert_called_once_with(
                '{crm_command} corosync set {path} {value}'.format(
                    crm_command=crmshmod.CRM_COMMAND,
                    path='path', value='value'), raise_err=True)

    def test_create_corosync_authkey(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_create_corosync_authkey(self):
        '''
        Test _create_corosync_authkey
        '''
        mock_cmd_run = MagicMock()

        with patch.dict(crmshmod.__salt__, {'cmd.run': mock_cmd_run}):
            crmshmod._create_corosync_authkey()
            mock_cmd_run.assert_called_once_with('corosync-keygen', raise_err=True)

    @mock.patch('salt.modules.crmshmod._set_corosync_value')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_join_corosync_not_unicast(self, logger):
        '''
        Test _join_corosync_unicast
        '''
        mock_cmd_retcode = MagicMock(return_value=1)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_retcode}):
            crmshmod._join_corosync_unicast('main_node', 'eth1')
            mock_cmd_retcode.assert_called_once_with((
                    'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -t '
                    'root@{host} "grep \'transport: udpu\' {conf}"'.format(
                        host='main_node', conf='/etc/corosync/corosync.conf')))
            logger.assert_called_once_with('cluster not set as unicast')

    def test_crm_init_basic(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_crm_init_basic(self):
        '''
        Test _crm_init method
        '''
        mock_cmd_retcode = MagicMock(return_value=True)
        mock_cmd_run = MagicMock(return_value="crm cluster init help without ocfs2 mount")

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_retcode, 'cmd.run': mock_cmd_run}):
            result = crmshmod._crm_init('hacluster')
            assert result
            mock_cmd_retcode.assert_called_once_with(
                '{crm_command} cluster init -y -n {name}'.format(
                    crm_command=crmshmod.CRM_COMMAND, name='hacluster'))

    def test_crm_init_complete(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_ha_cluster_init_basic(self):
        '''
        Test _ha_cluster_init method
        '''
        mock_cmd_run = MagicMock(return_value=0)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod._ha_cluster_init()
            assert result == 0
            mock_cmd_run.assert_called_once_with(
                '{command} -y'.format(command=crmshmod.HA_INIT_COMMAND))

    @mock.patch('salt.modules.crmshmod._add_watchdog_sbd')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_crm_join_basic(self):
        '''
        Test _crm_join method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod._crm_join('192.168.1.50')
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} cluster join -y -c {host}'.format(
                    crm_command=crmshmod.CRM_COMMAND, host='192.168.1.50'))

    def test_crm_join_complete(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_crm_join_complete(self):
        '''
        Test cluster_join method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod._crm_join(
                '192.168.1.50', 'dog', 'eth1', True)
            assert result
            mock_cmd_run.assert_called_once_with(
                '{} cluster join -y -c {} -w {} -i {} -q'.format(
                    crmshmod.CRM_COMMAND, '192.168.1.50', 'dog', 'eth1'))

    @mock.patch('salt.modules.crmshmod._join_corosync_unicast')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_ha_cluster_join_basic(self, mock_corosync):
        '''
        Test _ha_cluster_join method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod._ha_cluster_join('192.168.1.50')
            assert result
            mock_corosync.assert_called_once_with('192.168.1.50', None)
            mock_cmd_run.assert_called_once_with(
                '{command} -y -c {host}'.format(
                    command=crmshmod.HA_JOIN_COMMAND, host='192.168.1.50'))

    @mock.patch('salt.modules.crmshmod._add_watchdog_sbd')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_ha_cluster_join_complete_error(self, mock_corosync, mock_watchdog):
        '''
        Test _ha_cluster_join method
        '''
        mock_cmd_run = MagicMock(side_effect=[1, 0])

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod._ha_cluster_join(
                '192.168.1.50', 'dog', 'eth1', True)
            assert result == 1
            mock_corosync.assert_called_once_with('192.168.1.50', 'eth1')
            mock_watchdog.assert_called_once_with('dog')
            mock_cmd_run.assert_called_once_with('{} -y -c {} -i {} -q'.format(
                    crmshmod.HA_JOIN_COMMAND, '192.168.1.50', 'eth1'))

    @mock.patch('salt.modules.crmshmod._crm_join')

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_remove_basic(self):
        '''
        Test cluster_remove method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_remove('192.168.1.50')
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} cluster remove -y -c {host}'.format(
                    crm_command=crmshmod.CRM_COMMAND, host='192.168.1.50'))

    def test_cluster_remove_complete(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_cluster_remove_complete(self):
        '''
        Test cluster_remove method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.cluster_remove(
                '192.168.1.50', True, True)
            assert result
            mock_cmd_run.assert_called_once_with(
                '{} cluster remove -y -c {} --force -q'.format(
                    crmshmod.CRM_COMMAND, '192.168.1.50'))

    def test_configure_load_basic(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_configure_load_basic(self):
        '''
        Test configure_load method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.configure_load('update', 'file.conf')
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} -n configure load {method} {url}'.format(
                    crm_command=crmshmod.CRM_COMMAND,
                    method='update',
                    url='file.conf'))

    def test_configure_load_complete(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_configure_load_complete(self):
        '''
        Test cluster_remove method
        '''
        mock_cmd_run = MagicMock(return_value=True)

        with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}):
            result = crmshmod.configure_load('update', 'file.conf', True, True)
            assert result
            mock_cmd_run.assert_called_once_with(
                '{crm_command} -F configure load xml {method} {url}'.format(
                    crm_command=crmshmod.CRM_COMMAND,
                    method='update',
                    url='file.conf'))

    def test_configure_get_property(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_configure_get_property(self):
        '''
        Test configure_get_property
        '''

        mock_cmd_run = MagicMock(return_value=' value ')

        with patch.dict(crmshmod.__salt__, {'cmd.run': mock_cmd_run}):
            result = crmshmod.configure_get_property('item')
            assert result == 'value'
            mock_cmd_run.assert_called_once_with(
                '{crm_command} configure get_property {property}'.format(
                    crm_command=crmshmod.CRM_COMMAND,
                    property='item'))

    def test_configure_get_property_error(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_configure_get_property_error(self):
        '''
        Test configure_get_property when it raises an error
        '''

        mock_cmd_run = MagicMock(return_value='ERROR: configure.get_property: item')

        with patch.dict(crmshmod.__salt__, {'cmd.run': mock_cmd_run}):
            with pytest.raises(exceptions.CommandExecutionError) as err:
                crmshmod.configure_get_property('item')
            mock_cmd_run.assert_called_once_with(
                '{crm_command} configure get_property {property}'.format(
                    crm_command=crmshmod.CRM_COMMAND,
                    property='item'))

        assert 'ERROR: configure.get_property: item' in str(err.value)

    def test_configure_property(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_detect_cloud_py2(self):
        '''
        Test detect_cloud
        '''
        mock_versin = '3.0.0'
        mock_cmd_run = MagicMock(return_value='my-cloud ')

        with patch.dict(crmshmod.__salt__, {
                'crm.version': mock_versin,
                'cmd.run': mock_cmd_run}):
            result = crmshmod.detect_cloud()
            assert result == 'my-cloud'

        mock_cmd_run.assert_called_once_with(
            'python -c "from crmsh import utils; print(utils.detect_cloud());"')

    def test_detect_cloud_py3(self):

3 Source : test_crmshmod.py
with Apache License 2.0
from SUSE

    def test_detect_cloud_py3(self):
        '''
        Test detect_cloud
        '''
        mock_versin = '4.0.0'
        mock_cmd_run = MagicMock(return_value='my-cloud ')

        with patch.dict(crmshmod.__salt__, {
                'crm.version': mock_versin,
                'cmd.run': mock_cmd_run}):
            result = crmshmod.detect_cloud()
            assert result == 'my-cloud'

        mock_cmd_run.assert_called_once_with(
            'python3 -c "from crmsh import utils; print(utils.detect_cloud());"')

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_createmd(self):
        '''
        Test if createmd function work well
        '''
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.createmd()
            mock_cmd.assert_called_once_with('drbdadm create-md all --force')

    def test_up(self):

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_up(self):
        '''
        Test if up function work well
        '''
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.up()
            mock_cmd.assert_called_once_with('drbdadm up all')

    def test_down(self):

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_down(self):
        '''
        Test if down function work well
        '''
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.down()
            mock_cmd.assert_called_once_with('drbdadm down all')

    def test_primary(self):

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_primary(self):
        '''
        Test if primary function work well
        '''
        # SubTest1:
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.primary()
            mock_cmd.assert_called_once_with('drbdadm primary all')

        # SubTest2:
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.primary(force=True)
            mock_cmd.assert_called_once_with('drbdadm primary all --force')

    def test_secondary(self):

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_secondary(self):
        '''
        Test if secondary function work well
        '''
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.secondary()
            mock_cmd.assert_called_once_with('drbdadm secondary all')

    def test_adjust(self):

3 Source : test_drbdmod.py
with Apache License 2.0
from SUSE

    def test_adjust(self):
        '''
        Test if adjust function work well
        '''
        mock_cmd = MagicMock(return_value=True)

        with patch.dict(drbd.__salt__, {'cmd.retcode': mock_cmd}):
            assert drbd.adjust()
            mock_cmd.assert_called_once_with('drbdadm adjust all')

    def test_setup_show(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_init_return(self, mock_hana):
        '''
        Test _init method
        '''
        mock_hana_inst = MagicMock()
        mock_hana.return_value = mock_hana_inst
        hana_inst = hanamod._init('prd', '00', 'pass')
        mock_hana.assert_called_once_with('prd', '00', 'pass')
        assert mock_hana_inst == hana_inst

    @patch('salt.modules.hanamod.hana.HanaInstance')

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_is_installed_return_true(self):
        '''
        Test is_installed method
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.is_installed.return_value = True
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            assert hanamod.is_installed('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.is_installed.assert_called_once_with()

    def test_is_installed_return_false(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_is_installed_return_false(self):
        '''
        Test is_installed method
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.is_installed.return_value = False
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            assert not hanamod.is_installed('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.is_installed.assert_called_once_with()

    @patch('salt.modules.hanamod.hana.HanaInstance')

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_uninstall_return(self):
        '''
        Test uninstall method - return
        '''
        mock_hana_inst = MagicMock()
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            hanamod.uninstall('root', 'pass', '/hana', 'prd', '00', 'pass')
            mock_hana.assert_called_once_with(
                'prd', '00', 'pass')
            mock_hana_inst.uninstall.assert_called_once_with(
                'root', 'pass', installation_folder='/hana')

    def test_uninstall_return_default(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_uninstall_return_default(self):
        '''
        Test uninstall method - return
        '''
        mock_hana_inst = MagicMock()
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            hanamod.uninstall('root', 'pass', None, 'prd', '00', 'pass')
            mock_hana.assert_called_once_with(
                'prd', '00', 'pass')
            mock_hana_inst.uninstall.assert_called_once_with('root', 'pass')

    def test_uninstall_raise(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_uninstall_raise(self):
        '''
        Test uninstall method - raise
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.uninstall.side_effect = hanamod.hana.HanaError(
            'hana error'
        )
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            with pytest.raises(exceptions.CommandExecutionError) as err:
                hanamod.uninstall('root', 'pass', None, 'prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.uninstall.assert_called_once_with('root', 'pass')
            assert 'hana error' in str(err.value)

    def test_is_running_return_true(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_is_running_return_true(self):
        '''
        Test is_running method
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.is_running.return_value = True
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            assert hanamod.is_running('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.is_running.assert_called_once_with()

    def test_is_running_return_false(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_is_running_return_false(self):
        '''
        Test is_running method
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.is_running.return_value = False
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            assert not hanamod.is_running('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.is_running.assert_called_once_with()

    def test_get_version_return(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_get_version_return(self):
        '''
        Test get_version method - return
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.get_version.return_value = '1.2.3'
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            assert u'1.2.3' == hanamod.get_version('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.get_version.assert_called_once_with()

    def test_get_version_raise(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_get_version_raise(self):
        '''
        Test get_version method - raise
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.get_version.side_effect = hanamod.hana.HanaError(
            'hana error'
        )
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            with pytest.raises(exceptions.CommandExecutionError) as err:
                hanamod.get_version('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.get_version.assert_called_once_with()
            assert 'hana error' in str(err.value)

    def test_start_return(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_start_return(self):
        '''
        Test start method - return
        '''
        mock_hana_inst = MagicMock()
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            hanamod.start('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.start.assert_called_once_with()

    def test_start_raise(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_start_raise(self):
        '''
        Test start method - raise
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.start.side_effect = hanamod.hana.HanaError(
            'hana error'
        )
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            with pytest.raises(exceptions.CommandExecutionError) as err:
                hanamod.start('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.start.assert_called_once_with()
            assert 'hana error' in str(err.value)

    def test_stop_return(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_stop_return(self):
        '''
        Test stop method - return
        '''
        mock_hana_inst = MagicMock()
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            hanamod.stop('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.stop.assert_called_once_with()

    def test_stop_raise(self):

3 Source : test_hanamod.py
with Apache License 2.0
from SUSE

    def test_stop_raise(self):
        '''
        Test stop method - raise
        '''
        mock_hana_inst = MagicMock()
        mock_hana_inst.stop.side_effect = hanamod.hana.HanaError(
            'hana error'
        )
        mock_hana = MagicMock(return_value=mock_hana_inst)
        with patch.object(hanamod, '_init', mock_hana):
            with pytest.raises(exceptions.CommandExecutionError) as err:
                hanamod.stop('prd', '00', 'pass')
            mock_hana.assert_called_once_with('prd', '00', 'pass')
            mock_hana_inst.stop.assert_called_once_with()
            assert 'hana error' in str(err.value)

    def test_get_sr_state_return(self):

See More Examples