desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test - Create an IIS virtual directory.'
def test_create_vdir(self):
kwargs = {'name': 'TestVdir', 'site': 'MyTestSite', 'sourcepath': 'C:\\inetpub\\vdirs\\TestVdir'} with patch.dict(win_iis.__salt__): with patch('os.path.isdir', MagicMock(return_value=True)): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): ...
'Test - Get configured IIS virtual directories.'
def test_list_vdirs(self):
vdirs = {'TestVdir': {'sourcepath': 'C:\\inetpub\\vdirs\\TestVdir'}} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value=LIST_VDIRS_SRVMGR)): self.assertEqual(win_iis.list_vdirs('MyTestSite'), vdirs)
'Test - Remove an IIS virtual directory.'
def test_remove_vdir(self):
kwargs = {'name': 'TestOtherVdir', 'site': 'MyTestSite'} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_vdirs', MagicMock(return_value=VDIR_LIST)): self.assertTrue(wi...
'Test - Assign a certificate to an IIS binding.'
def test_create_cert_binding(self):
kwargs = {'name': '9988776655443322111000AAABBBCCCDDDEEEFFF', 'site': 'MyTestSite', 'hostheader': 'mytestsite.local', 'ipaddress': '*', 'port': 443} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._list_certs', MagicMock(return_value={'9988776655443322111000AAABBBCCCDDDEEEFFF': None}...
'Test - List certificate bindings for an IIS site.'
def test_list_cert_bindings(self):
key = '*:443:mytestsite.local' with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis.list_sites', MagicMock(return_value=SITE_LIST)): self.assertEqual(win_iis.list_cert_bindings('MyTestSite'), {key: BINDING_LIST[key]})
'Test - Remove a certificate from an IIS binding.'
def test_remove_cert_binding(self):
kwargs = {'name': 'FFFEEEDDDCCCBBBAAA0001112233445566778899', 'site': 'MyOtherTestSite', 'hostheader': 'myothertestsite.local', 'ipaddress': '*', 'port': 443} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('sa...
'Test - Get the value of the setting for the IIS container.'
def test_get_container_setting(self):
kwargs = {'name': 'MyTestSite', 'container': 'AppPools', 'settings': ['managedPipelineMode']} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value=CONTAINER_SETTING)): self.assertEqual(win_iis.get_container_setting(**kwargs), {'managedPipelineM...
'Test - Set the value of the setting for an IIS container.'
def test_set_container_setting(self):
kwargs = {'name': 'MyTestSite', 'container': 'AppPools', 'settings': {'managedPipelineMode': 'Integrated'}} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.get_container_setting', MagicMoc...
'List package upgrades :return:'
def test_list_upgrades(self):
ref_out = {'stdout': get_test_data('zypper-updates.xml'), 'stderr': None, 'retcode': 0} with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}): upgrades = zypper.list_upgrades(refresh=False) self.assertEqual(len(upgrades), 3) for (pkg, version) in {'SUSEConnec...
'Test Zypper caller. :return:'
def test_zypper_caller(self):
class RunSniffer(object, ): def __init__(self, stdout=None, stderr=None, retcode=None): self.calls = list() self._stdout = (stdout or '') self._stderr = (stderr or '') self._retcode = (retcode or 0) def __call__(self, *args, **kwargs): self...
'Test error handling in the list package upgrades. :return:'
def test_list_upgrades_error_handling(self):
ref_out = {'stdout': '<?xml version=\'1.0\'?>\n<stream>\n <message type="info">Refreshing service &apos;container-suseconnect&apos;.</message>\n <message type="error">Some handled zypper internal error</message>\n <message type="error">Another zypper internal error</m...
'List products test.'
def test_list_products(self):
for (filename, test_data) in {'zypper-products-sle12sp1.xml': {'name': ['SLES', 'SLES', 'SUSE-Manager-Proxy', 'SUSE-Manager-Server', 'sle-manager-tools-beta', 'sle-manager-tools-beta-broken-eol', 'sle-manager-tools-beta-no-eol'], 'vendor': 'SUSE LLC <https://www.suse.com/>', 'release': ['0', '0', '0', '0', '0...
'Test if refresh DB handled correctly'
def test_refresh_db(self):
ref_out = ["Repository 'openSUSE-Leap-42.1-LATEST' is up to date.", "Repository 'openSUSE-Leap-42.1-Update' is up to date.", "Retrieving repository 'openSUSE-Leap-42.1-Update-Non-Oss' metadata", 'Forcing building of repository cache', "Building repository 'op...
'Test the return information of the named package(s), installed on the system. :return:'
def test_info_installed(self):
run_out = {'virgo-dummy': {'build_date': '2015-07-09T10:55:19Z', 'vendor': 'openSUSE Build Service', 'description': 'This is the Virgo dummy package used for testing SUSE Manager', 'license': 'GPL-2.0', 'build_host': 'sheep05', 'url': 'http://www.suse.com', 'build_date_time_t': 1...
'Test the return information of the named package(s), installed on the system whith non-ascii chars :return:'
def test_info_installed_with_non_ascii_char(self):
run_out = {'v\xc4\xabrg\xc3\xb4': {'description': 'v\xc4\xabrg\xc3\xb4 d\xe2\x82\xac\xc5\xa1\xc3\xa7rip\xc5\xa3i\xc7\xab\xc3\xb1'}} with patch.dict(zypper.__salt__, {'lowpkg.info': MagicMock(return_value=run_out)}): installed = zypper.info_installed() self.assertEqual(installed['v\xc4\xabrg\x...
'Test return the information of the named package available for the system. :return:'
def test_info_available(self):
test_pkgs = ['vim', 'emacs', 'python'] with patch('salt.modules.zypper.__zypper__', ZyppCallMock(return_value=get_test_data('zypper-available.txt'))): available = zypper.info_available(refresh=False, *test_pkgs) self.assertEqual(len(available), 3) for (pkg_name, pkg_info) in available.it...
'Test the latest version of the named package available for upgrade or installation. :return:'
def test_latest_version(self):
with patch('salt.modules.zypper.__zypper__', ZyppCallMock(return_value=get_test_data('zypper-available.txt'))): with patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True)): self.assertEqual(zypper.latest_version('vim'), '7.4.326-2.62')
'Test system upgrade and dist-upgrade success. :return:'
def test_upgrade_success(self):
with patch.dict(zypper.__grains__, {'osrelease_info': [12, 1]}): with patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True)): with patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)): with patch('salt.modules.zypper.__zypper__.noraise.call', ...
'Test kernel package upgrade success. :return:'
def test_upgrade_kernel(self):
with patch.dict(zypper.__grains__, {'osrelease_info': [12, 1]}): with patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True)): with patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)): with patch.dict(zypper.__salt__, {'pkg_resource.parse_targ...
'Test system upgrade failure. :return:'
def test_upgrade_failure(self):
zypper_out = "\nLoading repository data...\nReading installed packages...\nComputing distribution upgrade...\nUse 'zypper repos' to get the list of defined repositories.\nRepository 'DUMMY' not found by its alias, number, or URI.\n" class F...
'Test whether or not an upgrade is available for a given package. :return:'
def test_upgrade_available(self):
ref_out = get_test_data('zypper-available.txt') with patch('salt.modules.zypper.__zypper__', ZyppCallMock(return_value=get_test_data('zypper-available.txt'))): with patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True)): for pkg_name in ['emacs', 'python']: sel...
'Test packages listing. :return:'
def test_list_pkgs(self):
def _add_data(data, key, value): data.setdefault(key, []).append(value) rpm_out = ['protobuf-java_|-2.6.1_|-3.1.develHead_|-noarch_|-_|-1499257756', 'yast2-ftp-server_|-3.1.8_|-8.1_|-x86_64_|-_|-1499257798', 'jose4j_|-0.4.4_|-2.1.develHead_|-noarch_|-_|-1499257756', 'apache-commons-cli_|-1.2_|-1.233_|-n...
'Test packages listing with the attr parameter :return:'
def test_list_pkgs_with_attr(self):
def _add_data(data, key, value): data.setdefault(key, []).append(value) rpm_out = ['protobuf-java_|-2.6.1_|-3.1.develHead_|-noarch_|-_|-1499257756', 'yast2-ftp-server_|-3.1.8_|-8.1_|-x86_64_|-_|-1499257798', 'jose4j_|-0.4.4_|-2.1.develHead_|-noarch_|-_|-1499257756', 'apache-commons-cli_|-1.2_|-1.233_|-n...
'Test advisory patches listing. :return:'
def test_list_patches(self):
ref_out = {'stdout': get_test_data('zypper-patches.xml'), 'stderr': None, 'retcode': 0} PATCHES_RET = {'SUSE-SLE-SERVER-12-SP2-2017-97': {'installed': False, 'summary': 'Recommended update for ovmf'}, 'SUSE-SLE-SERVER-12-SP2-2017-98': {'installed': True, 'summary': 'Recommended update for kmod...
'Test downloaded packages listing. :return:'
@patch('os.walk', MagicMock(return_value=[('test', 'test', 'test')])) @patch('os.path.getsize', MagicMock(return_value=123456)) @patch('os.path.getctime', MagicMock(return_value=1234567890.123456)) @patch('fnmatch.filter', MagicMock(return_value=['/var/cache/zypper/packages/foo/bar/test_package.rpm'])) def test_list_do...
DOWNLOADED_RET = {'test-package': {'1.0': {'path': '/var/cache/zypper/packages/foo/bar/test_package.rpm', 'size': 123456, 'creation_date_time_t': 1234567890, 'creation_date_time': '2009-02-13T23:31:30'}}} with patch.dict(zypper.__salt__, {'lowpkg.bin_pkg_info': MagicMock(return_value={'name': 'test-package', 'v...
'Test package download :return:'
def test_download(self):
download_out = {'stdout': get_test_data('zypper-download.xml'), 'stderr': None, 'retcode': 0} test_out = {'nmap': {'path': u'/var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm', 'repository-alias': u'SLE-12-x86_64-Pool', 'repository-name': u'SLE-12-x86_64-Pool'}} with patch.dict(zy...
'Test a package installation with downloadonly=True. :return:'
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)) @patch('salt.modules.zypper.list_downloaded', MagicMock(side_effect=[{}, {'vim': {'1.1': {'path': '/foo/bar/test.rpm', 'size': 1234, 'creation_date_time_t': 1234567890, 'creation_date_time': '2009-02-13T23:31:30'}}}])) def test_install_with_dow...
with patch.dict(zypper.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'vim': None}, 'repository'))}): with patch('salt.modules.zypper.__zypper__.noraise.call', MagicMock()) as zypper_mock: ret = zypper.install(pkgs=['vim'], downloadonly=True) zypper_mock.assert_cal...
'Test a package installation with downloadonly=True when package is already downloaded. :return:'
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)) @patch('salt.modules.zypper.list_downloaded', MagicMock(return_value={'vim': {'1.1': {'path': '/foo/bar/test.rpm', 'size': 1234, 'creation_date_time_t': 1234567890, 'creation_date_time': '2017-01-01T11:00:00'}}})) def test_install_with_download...
with patch.dict(zypper.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'vim': None}, 'repository'))}): with patch('salt.modules.zypper.__zypper__.noraise.call', MagicMock()) as zypper_mock: ret = zypper.install(pkgs=['vim'], downloadonly=True) zypper_mock.assert_cal...
'Test successfully advisory patch installation. :return:'
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)) @patch('salt.modules.zypper._get_patches', MagicMock(return_value={'SUSE-PATCH-1234': {'installed': False, 'summary': 'test'}})) @patch('salt.modules.zypper.list_pkgs', MagicMock(side_effect=[{'vim': '1.1'}, {'vim': '1.2'}])) def test_install_a...
with patch.dict(zypper.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'SUSE-PATCH-1234': None}, 'advisory'))}): with patch('salt.modules.zypper.__zypper__.noraise.call', MagicMock()) as zypper_mock: ret = zypper.install(advisory_ids=['SUSE-PATCH-1234']) zypper_mock...
'Test failing advisory patch installation because patch does not exist. :return:'
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False)) @patch('salt.modules.zypper._get_patches', MagicMock(return_value={'SUSE-PATCH-1234': {'installed': False, 'summary': 'test'}})) @patch('salt.modules.zypper.list_pkgs', MagicMock(return_value={'vim': '1.1'})) def test_install_advisory_patch_fai...
with patch.dict(zypper.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'SUSE-PATCH-XXX': None}, 'advisory'))}): with patch('salt.modules.zypper.__zypper__.noraise.call', MagicMock()) as zypper_mock: with self.assertRaisesRegex(CommandExecutionError, '^Advisory id "SUSE-PA...
'Test package removal :return:'
def test_remove_purge(self):
class ListPackages(object, ): def __init__(self): self._packages = ['vim', 'pico'] self._pkgs = {'vim': '0.18.0', 'emacs': '24.0.1', 'pico': '0.1.1'} def __call__(self): pkgs = self._pkgs.copy() for target in self._packages: if self._pk...
'Tests if repo info is properly parsed. :return:'
def test_repo_value_info(self):
repos_cfg = configparser.ConfigParser() for cfg in ['zypper-repo-1.cfg', 'zypper-repo-2.cfg']: repos_cfg.readfp(six.moves.StringIO(get_test_data(cfg))) for alias in repos_cfg.sections(): r_info = zypper._get_repo_info(alias, repos_cfg=repos_cfg) self.assertEqual(type(r_info['type']),...
'Test mod_repo adds the new repo and nothing else :return:'
def test_repo_add_nomod_noref(self):
zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) url = self.new_repo_config['url'] name = self.new_repo_config['name'] with zypper_patcher: zypper.mod_repo(name, **{'url': url}) self.assertEqual(zypper.__zypper__.xml.call.call_args_list, [call('ar', ur...
'Test mod_repo detects the repo already exists, no modification was requested and no refresh requested either :return:'
def test_repo_noadd_nomod_noref(self):
url = self.new_repo_config['url'] name = self.new_repo_config['name'] self.zypper_patcher_config['_get_configured_repos'] = Mock(**{'return_value.sections.return_value': [name]}) zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) with zypper_patcher: out = z...
'Test mod_repo detects the repo already exists, no modification was requested and no refresh requested either :return:'
def test_repo_noadd_modbaseurl_ref(self):
url = self.new_repo_config['url'] name = self.new_repo_config['name'] self.zypper_patcher_config['_get_configured_repos'] = Mock(**{'return_value.sections.side_effect': [[name], [], [], [name]]}) zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) with zypper_patcher...
'Test mod_repo adds the new repo and call modify to update autorefresh :return:'
def test_repo_add_mod_noref(self):
zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) url = self.new_repo_config['url'] name = self.new_repo_config['name'] with zypper_patcher: zypper.mod_repo(name, **{'url': url, 'refresh': True}) self.assertEqual(zypper.__zypper__.xml.call.call_args_lis...
'Test mod_repo detects the repository exists, calls modify to update \'autorefresh\' but does not call refresh :return:'
def test_repo_noadd_mod_noref(self):
url = self.new_repo_config['url'] name = self.new_repo_config['name'] self.zypper_patcher_config['_get_configured_repos'] = Mock(**{'return_value.sections.return_value': [name]}) zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) with zypper_patcher: zypper....
'Test mod_repo adds the new repo and refreshes the repo with `zypper --gpg-auto-import-keys refresh <repo-name>` :return:'
def test_repo_add_nomod_ref(self):
zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) url = self.new_repo_config['url'] name = self.new_repo_config['name'] with zypper_patcher: zypper.mod_repo(name, **{'url': url, 'gpgautoimport': True}) self.assertEqual(zypper.__zypper__.xml.call.call_ar...
'Test mod_repo detects the repo already exists, has nothing to modify and refreshes the repo with `zypper --gpg-auto-import-keys refresh <repo-name>` :return:'
def test_repo_noadd_nomod_ref(self):
url = self.new_repo_config['url'] name = self.new_repo_config['name'] self.zypper_patcher_config['_get_configured_repos'] = Mock(**{'return_value.sections.return_value': [name]}) zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) with zypper_patcher: zypper....
'Test mod_repo adds the new repo, calls modify to update \'autorefresh\' and refreshes the repo with `zypper --gpg-auto-import-keys refresh <repo-name>` :return:'
def test_repo_add_mod_ref(self):
zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) url = self.new_repo_config['url'] name = self.new_repo_config['name'] with zypper_patcher: zypper.mod_repo(name, **{'url': url, 'refresh': True, 'gpgautoimport': True}) self.assertEqual(zypper.__zypper__...
'Test mod_repo detects the repo already exists, calls modify to update \'autorefresh\' and refreshes the repo with `zypper --gpg-auto-import-keys refresh <repo-name>` :return:'
def test_repo_noadd_mod_ref(self):
url = self.new_repo_config['url'] name = self.new_repo_config['name'] self.zypper_patcher_config['_get_configured_repos'] = Mock(**{'return_value.sections.return_value': [name]}) zypper_patcher = patch.multiple('salt.modules.zypper', **self.zypper_patcher_config) with zypper_patcher: zypper....
'Test wildcard to query match all pattern :return:'
def test_wildcard_to_query_match_all(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="SLE-12-SP2-x86_64-Pool"/>\n ...
'Test wildcard to query match multiple asterisk :return:'
def test_wildcard_to_query_multiple_asterisk(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query match exact pattern at the end :return:'
def test_wildcard_to_query_exact_match_at_end(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query match exact pattern at the beginning :return:'
def test_wildcard_to_query_exact_match_at_beginning(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query usage. :return:'
def test_wildcard_to_query_usage(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query when no version has been passed on. :return:'
def test_wildcard_to_query_noversion(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query typecheck. :return:'
def test_wildcard_to_query_typecheck(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query Zypper condition preservation. :return:'
def test_wildcard_to_query_condition_preservation(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test wildcard to query unsupported operators. :return:'
def test_wildcard_to_query_unsupported_operators(self):
xmldoc = '<?xml version=\'1.0\'?><stream>\n <search-result version="0.0"><solvable-list>\n <solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="foo"/>\n ...
'Test - Get the sysServices types that can be configured.'
def test_get_agent_service_types(self):
with patch.dict(win_snmp.__salt__): self.assertIsInstance(win_snmp.get_agent_service_types(), list)
'Test - Get the permission types that can be configured for communities.'
def test_get_permission_types(self):
with patch.dict(win_snmp.__salt__): self.assertIsInstance(win_snmp.get_permission_types(), list)
'Test - Determine whether the host is configured to send authentication traps.'
def test_get_auth_traps_enabled(self):
mock_value = MagicMock(return_value={'vdata': 1}) with patch.dict(win_snmp.__salt__, {'reg.read_value': mock_value}): self.assertTrue(win_snmp.get_auth_traps_enabled())
'Test - Manage the sending of authentication traps.'
def test_set_auth_traps_enabled(self):
mock_value = MagicMock(return_value=True) kwargs = {'status': True} with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_value}): with patch('salt.modules.win_snmp.get_auth_traps_enabled', MagicMock(return_value=True)): self.assertTrue(win_snmp.set_auth_traps_enabled(**kwargs))
'Test - Get the current accepted SNMP community names and their permissions.'
def test_get_community_names(self):
mock_value = MagicMock(return_value=[{'vdata': 16, 'vname': 'TestCommunity'}]) with patch.dict(win_snmp.__salt__, {'reg.list_values': mock_value}): self.assertEqual(win_snmp.get_community_names(), COMMUNITY_NAMES)
'Test - Manage the SNMP accepted community names and their permissions.'
def test_set_community_names(self):
mock_value = MagicMock(return_value=True) kwargs = {'communities': COMMUNITY_NAMES} with patch.dict(win_snmp.__salt__, {'reg.set_value': mock_value}): with patch('salt.modules.win_snmp.get_community_names', MagicMock(return_value=COMMUNITY_NAMES)): self.assertTrue(win_snmp.set_community_...
'Test for Starts service via daemontools'
def test_start(self):
mock = MagicMock(return_value=None) with patch.dict(daemontools.__salt__, {'file.remove': mock}): mock = MagicMock(return_value='') with patch.object(daemontools, '_service_path', mock): mock = MagicMock(return_value=False) with patch.dict(daemontools.__salt__, {'cmd.retc...
'Test for Stops service via daemontools'
def test_stop(self):
mock = MagicMock(return_value=None) with patch.dict(daemontools.__salt__, {'file.touch': mock}): mock = MagicMock(return_value='') with patch.object(daemontools, '_service_path', mock): mock = MagicMock(return_value=False) with patch.dict(daemontools.__salt__, {'cmd.retco...
'Test for Send a TERM to service via daemontools'
def test_term(self):
mock = MagicMock(return_value='') with patch.object(daemontools, '_service_path', mock): mock = MagicMock(return_value=False) with patch.dict(daemontools.__salt__, {'cmd.retcode': mock}): self.assertTrue(daemontools.term('name'))
'Test for Wrapper for term()'
def test_reload_(self):
mock = MagicMock(return_value=None) with patch.object(daemontools, 'term', mock): self.assertEqual(daemontools.reload_('name'), None)
'Test for Restart service via daemontools. This will stop/start service'
def test_restart(self):
mock = MagicMock(return_value=False) with patch.object(daemontools, 'stop', mock): self.assertEqual(daemontools.restart('name'), 'restart False')
'Test for Calls daemontools.restart() function'
def test_full_restart(self):
mock = MagicMock(return_value=None) with patch.object(daemontools, 'restart', mock): self.assertEqual(daemontools.restart('name'), None)
'Test for Return the status for a service via daemontools, return pid if running'
def test_status(self):
with patch('re.search', MagicMock(return_value=1)): mock = MagicMock(return_value='') with patch.object(daemontools, '_service_path', mock): mock = MagicMock(return_value='name') with patch.dict(daemontools.__salt__, {'cmd.run_stdout': mock}): self.assertEqual...
'Test for Returns ``True`` if the specified service is available, otherwise returns``False``.'
def test_available(self):
mock = MagicMock(return_value=[]) with patch.object(daemontools, 'get_all', mock): self.assertFalse(daemontools.available('name'))
'Test for The inverse of daemontools.available.'
def test_missing(self):
mock = MagicMock(return_value=[]) with patch.object(daemontools, 'get_all', mock): self.assertTrue(daemontools.missing('name'))
'Test for Return a list of all available services'
def test_get_all(self):
self.assertRaises(CommandExecutionError, daemontools.get_all) with patch.object(daemontools, 'SERVICE_DIR', 'A'): mock = MagicMock(return_value='A') with patch.object(os, 'listdir', mock): self.assertEqual(daemontools.get_all(), ['A'])
'Test getting the serial number from a certificate'
def test_get_serial(self):
expected = '180720d39cd2db3244ba037417241e90' mock = MagicMock(return_value='CertInfo\r\nCert Serial Number: 180720d39cd2db3244ba037417241e90\r\n\r\nOtherStuff') with patch.dict(certutil.__salt__, {'cmd.run': mock}): out = certutil.get_cert_serial('/path/to/cert.cer') mock.assert_ca...
'Test getting all the serial numbers from a store'
def test_get_serials(self):
expected = ['180720d39cd2db3244ba037417241e90', '1768ac4e5b72bf1d0df0df118b34b959'] mock = MagicMock(return_value='CertInfo\r\n================ Certificate 0 ================\r\nSerial Number: 180720d39cd2db3244ba037417241e90\r\nOtherStuff\r\n\r\n================ Certificate 1 ==========...
'Test adding a certificate to a specific store'
def test_add_store(self):
cmd_mock = MagicMock(return_value='CertInfo\r\n================ Certificate 0 ================\r\nSerial Number: 180720d39cd2db3244ba037417241e90\r\nOtherStuff') cache_mock = MagicMock(return_value='/tmp/cert.cer') with patch.dict(certutil.__salt__, {'cmd.run': cmd_mock, 'cp.cache_file': cach...
'Test removing a certificate to a specific store'
def test_del_store(self):
with patch('salt.modules.win_certutil.get_cert_serial') as cert_serial_mock: cmd_mock = MagicMock(return_value='CertInfo\r\n================ Certificate 0 ================\r\nSerial Number: 180720d39cd2db3244ba037417241e90\r\nOtherStuff') cache_mock = MagicMock(return_value='/tmp/cert...
'Test if it set Windows to use a list of NTP servers'
def test_set_servers(self):
mock_service = MagicMock(return_value=False) mock_cmd = MagicMock(return_value='Failure') with patch.dict(win_ntp.__salt__, {'service.status': mock_service, 'service.start': mock_service, 'cmd.run': mock_cmd}): self.assertFalse(win_ntp.set_servers('pool.ntp.org')) mock_service = MagicMock(return...
'Test if it get list of configured NTP servers'
def test_get_servers(self):
mock_cmd = MagicMock(side_effect=['', 'NtpServer: SALT', 'NtpServer']) with patch.dict(win_ntp.__salt__, {'cmd.run': mock_cmd}): self.assertFalse(win_ntp.get_servers()) self.assertListEqual(win_ntp.get_servers(), ['SALT']) self.assertFalse(win_ntp.get_servers())
'Mock method to return all Discoverable devices'
@staticmethod def discover_devices(lookup_names):
return [['a', 'b', 'c'], ['d', 'e', 'f']]
'Test if return bluetooth version'
def test_version(self):
mock = MagicMock(return_value='5.7') with patch.dict(bluez.__salt__, {'cmd.run': mock}): self.assertDictEqual(bluez.version(), {'PyBluez': '<= 0.18 (Unknown, but installed)', 'Bluez': '5.7'})
'Test of getting address of bluetooth adapter'
def test_address_(self):
mock = MagicMock(return_value='hci : hci0') with patch.dict(bluez.__salt__, {'cmd.run': mock}): self.assertDictEqual(bluez.address_(), {'hci ': {'device': 'hci ', 'path': '/sys/class/bluetooth/hci '}})
'Test of getting address of bluetooth adapter'
def test_power(self):
mock = MagicMock(return_value={}) with patch.object(bluez, 'address_', mock): self.assertRaises(CommandExecutionError, bluez.power, 'hci0', 'on') mock = MagicMock(return_value={'hci0': {'device': 'hci0', 'power': 'on'}}) with patch.object(bluez, 'address_', mock): mock = MagicMock(return...
'Test of enabling bluetooth device'
def test_discoverable(self):
mock = MagicMock(side_effect=[{}, {'hci0': {'device': 'hci0', 'power': 'on'}}, {'hci0': {'device': 'hci0', 'power': 'on'}}]) with patch.object(bluez, 'address_', mock): self.assertRaises(CommandExecutionError, bluez.discoverable, 'hci0') mock = MagicMock(return_value='UP RUNNING ISCAN') ...
'Test of turning off of scanning modes'
def test_noscan(self):
mock = MagicMock(side_effect=[{}, {'hci0': {'device': 'hci0', 'power': 'on'}}, {'hci0': {'device': 'hci0', 'power': 'on'}}]) with patch.object(bluez, 'address_', mock): self.assertRaises(CommandExecutionError, bluez.noscan, 'hci0') mock = MagicMock(return_value='SCAN') with patch.dict(bl...
'Test of scanning of bluetooth devices'
def test_scan(self):
self.assertListEqual(bluez.scan(), [{'a': 'b'}, {'d': 'e'}])
'Test of blocking specific bluetooth device'
def test_block(self):
mock = MagicMock(side_effect=[False, True]) with patch.object(salt.utils.validate.net, 'mac', mock): self.assertRaises(CommandExecutionError, bluez.block, 'DE:AD:BE:EF:CA:ZE') mock = MagicMock(return_value='') with patch.dict(bluez.__salt__, {'cmd.run': mock}): self.assertIsN...
'Test to unblock specific bluetooth device'
def test_unblock(self):
mock = MagicMock(side_effect=[False, True]) with patch.object(salt.utils.validate.net, 'mac', mock): self.assertRaises(CommandExecutionError, bluez.block, 'DE:AD:BE:EF:CA:ZE') mock = MagicMock(return_value='') with patch.dict(bluez.__salt__, {'cmd.run': mock}): self.assertIsN...
'Test to pair bluetooth adapter with a device'
def test_pair(self):
mock = MagicMock(side_effect=[False, True, True]) with patch.object(salt.utils.validate.net, 'mac', mock): self.assertRaises(CommandExecutionError, bluez.pair, 'DE:AD:BE:EF:CA:FE', '1234') self.assertRaises(CommandExecutionError, bluez.pair, 'DE:AD:BE:EF:CA:FE', 'abcd') mock = MagicMock(...
'Test to unpair bluetooth adaptor with a device'
def test_unpair(self):
mock = MagicMock(side_effect=[False, True]) with patch.object(salt.utils.validate.net, 'mac', mock): self.assertRaises(CommandExecutionError, bluez.unpair, 'DE:AD:BE:EF:CA:FE') mock = MagicMock(return_value='Ok') with patch.dict(bluez.__salt__, {'cmd.run': mock}): self.assert...
'Test to start bluetooth service'
def test_start(self):
mock = MagicMock(return_value='Ok') with patch.dict(bluez.__salt__, {'service.start': mock}): self.assertEqual(bluez.start(), 'Ok')
'Test to stop bluetooth service'
def test_stop(self):
mock = MagicMock(return_value='Ok') with patch.dict(bluez.__salt__, {'service.stop': mock}): self.assertEqual(bluez.stop(), 'Ok')
'Mock GetLogicalDrives method'
@staticmethod def GetLogicalDrives():
return 1
'Test if it return usage information for volumes mounted on this minion.'
def test_usage(self):
self.assertDictEqual(win_disk.usage(), {'A:\\': {'available': None, '1K-blocks': None, 'used': None, 'capacity': None, 'filesystem': 'A:\\'}})
'scenario of creating upgrading extensions with possible schema and version specifications'
def test_create_extension_newerthan(self):
with patch('salt.modules.postgres.create_metadata', Mock(side_effect=[[postgres._EXTENSION_NOT_INSTALLED], [postgres._EXTENSION_INSTALLED], [postgres._EXTENSION_NOT_INSTALLED], [postgres._EXTENSION_INSTALLED], [postgres._EXTENSION_NOT_INSTALLED], [postgres._EXTENSION_NOT_INSTALLED], [postgres._EXTENSION_TO_MOVE, po...
'Test language listing'
def test_language_list(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0, 'stdout': test_list_language_csv})): ret = postgres.language_list('testdb', user='testuser', host='testhost', port='testport', password='foo') self.assertDictEqual(ret, {'c': 'c', 'internal': 'internal', 'plpgsql': 'plpgs...
'Test language existence check'
def test_language_exists(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0})): with patch('salt.modules.postgres.psql_query', Mock(return_value=[{'Name': 'internal'}, {'Name': 'c'}, {'Name': 'sql'}, {'Name': 'plpgsql'}])): with patch('salt.modules.postgres.language_exists', Mock(return_value=...
'Test language creation - does not exist in db'
def test_language_create(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0})): with patch('salt.modules.postgres.language_exists', Mock(return_value=False)): postgres.language_create('plpythonu', 'testdb', runas='user', host='testhost', port='testport', user='testuser', password='testpassword...
'Test language creation - already exists in db'
def test_language_create_exists(self):
with patch('salt.modules.postgres.language_exists', Mock(return_value=True)): ret = postgres.language_create('plpythonu', 'testdb', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') self.assertFalse(ret)
'Test language removal - exists in db'
def test_language_remove(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0})): with patch('salt.modules.postgres.language_exists', Mock(return_value=True)): postgres.language_remove('plpgsql', 'testdb', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') ...
'Test language removal - does not exist in db'
def test_language_remove_non_exist(self):
with patch('salt.modules.postgres.language_exists', Mock(return_value=False)): ret = postgres.language_remove('plpgsql', 'testdb', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') self.assertFalse(ret)
'Test privilege listing on a table'
def test_privileges_list_table(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0, 'stdout': test_privileges_list_table_csv})): ret = postgres.privileges_list('awl', 'table', maintenance_db='db_name', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') expected = {'...
'Test privilege listing on a group'
def test_privileges_list_group(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0, 'stdout': test_privileges_list_group_csv})): ret = postgres.privileges_list('admin', 'group', maintenance_db='db_name', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') expected = ...
'Test privilege checks on table'
def test_has_privileges_on_table(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0, 'stdout': test_privileges_list_table_csv})): ret = postgres.has_privileges('baruwa', 'awl', 'table', 'SELECT,INSERT', grant_option=True, maintenance_db='db_name', runas='user', host='testhost', port='testport', user='testuser', p...
'Test privilege checks on group'
def test_has_privileges_on_group(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0, 'stdout': test_privileges_list_group_csv})): ret = postgres.has_privileges('baruwa', 'admin', 'group', maintenance_db='db_name', runas='user', host='testhost', port='testport', user='testuser', password='testpassword') se...
'Test granting privileges on table'
def test_privileges_grant_table(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0})): with patch('salt.modules.postgres.has_privileges', Mock(return_value=False)): ret = postgres.privileges_grant('baruwa', 'awl', 'table', 'ALL', grant_option=True, maintenance_db='db_name', runas='user', host='testho...
'Test granting privileges on group'
def test_privileges_grant_group(self):
with patch('salt.modules.postgres._run_psql', Mock(return_value={'retcode': 0})): with patch('salt.modules.postgres.has_privileges', Mock(return_value=False)): ret = postgres.privileges_grant('baruwa', 'admins', 'group', grant_option=True, maintenance_db='db_name', runas='user', host='testhost',...