• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mock.call函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中salttesting.mock.call函数的典型用法代码示例。如果您正苦于以下问题:Python call函数的具体用法?Python call怎么用?Python call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了call函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_repo_add_mod_ref

    def test_repo_add_mod_ref(self):
        '''
        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:
        '''
        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__.xml.call.call_args_list,
                [
                    call('ar', url, name),
                    call('--gpg-auto-import-keys', 'refresh', name)
                ]
            )
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                '--gpg-auto-import-keys', 'mr', '--refresh', name
            )
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:zypper_test.py


示例2: test_installed_cert_hash_different

    def test_installed_cert_hash_different(self):
        '''
            Test installing a certificate into the OSX keychain when it's already installed but
            the certificate has changed
        '''
        expected = {
            'changes': {'installed': 'Friendly Name', 'uninstalled': 'Friendly Name'},
            'comment': 'Found a certificate with the same name but different hash, removing it.\n',
            'name': '/path/to/cert.p12',
            'result': True
        }

        list_mock = MagicMock(side_effect=[['Friendly Name'], []])
        friendly_mock = MagicMock(return_value='Friendly Name')
        install_mock = MagicMock(return_value='1 identity imported.')
        uninstall_mock = MagicMock(return_value='removed.')
        hash_mock = MagicMock(side_effect=['ABCD', 'XYZ'])
        with patch.dict(keychain.__salt__, {'keychain.list_certs': list_mock,
                                            'keychain.get_friendly_name': friendly_mock,
                                            'keychain.install': install_mock,
                                            'keychain.uninstall': uninstall_mock,
                                            'keychain.get_hash': hash_mock}):
            out = keychain.installed('/path/to/cert.p12', 'passw0rd')
            list_mock.assert_has_calls(calls=[call('/Library/Keychains/System.keychain'),
                                              call('/Library/Keychains/System.keychain')])
            friendly_mock.assert_called_once_with('/path/to/cert.p12', 'passw0rd')
            install_mock.assert_called_once_with('/path/to/cert.p12', 'passw0rd', '/Library/Keychains/System.keychain')
            uninstall_mock.assert_called_once_with('Friendly Name', '/Library/Keychains/System.keychain',
                                                   keychain_password=None)
            self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:30,代码来源:mac_keychain_test.py


示例3: test_get_pkg_id_with_files

    def test_get_pkg_id_with_files(self, pkg_id_pkginfo_mock):
        '''
            Test getting a the id for a package
        '''
        expected = ['com.apple.this']
        cmd_mock = MagicMock(side_effect=[
            '/path/to/PackageInfo\n/path/to/some/other/fake/PackageInfo',
            '',
            ''
        ])
        pkg_id_pkginfo_mock.side_effect = [['com.apple.this'], []]
        temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
        remove_mock = MagicMock()

        with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock,
                                              'temp.dir': temp_mock,
                                              'file.remove': remove_mock}):
            out = macpackage.get_pkg_id('/path/to/file.pkg')

            temp_mock.assert_called_once_with(prefix='pkg-')
            cmd_calls = [
                call('xar -t -f /path/to/file.pkg | grep PackageInfo', python_shell=True, output_loglevel='quiet'),
                call('xar -x -f /path/to/file.pkg /path/to/PackageInfo /path/to/some/other/fake/PackageInfo',
                     cwd='/tmp/dmg-ABCDEF', output_loglevel='quiet')
            ]
            cmd_mock.assert_has_calls(cmd_calls)

            pkg_id_pkginfo_calls = [
                call('/path/to/PackageInfo'),
                call('/path/to/some/other/fake/PackageInfo')
            ]
            pkg_id_pkginfo_mock.assert_has_calls(pkg_id_pkginfo_calls)
            remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')

            self.assertEqual(out, expected)
开发者ID:bryson,项目名称:salt,代码行数:35,代码来源:mac_package_test.py


示例4: test_set_proxy_windows_no_ftp

    def test_set_proxy_windows_no_ftp(self):
        '''
            Test to make sure that we correctly set the proxy info
            on Windows
        '''
        proxy.__grains__['os'] = 'Windows'
        mock_reg = MagicMock()
        mock_cmd = MagicMock()

        with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
            out = proxy.set_proxy_win('192.168.0.1', 3128, types=['http', 'https'],
                                      bypass_hosts=['.moo.com', '.salt.com'])

            calls = [
                call('HKEY_CURRENT_USER',
                     'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
                     'ProxyServer',
                     'http=192.168.0.1:3128;https=192.168.0.1:3128;'),
                call('HKEY_CURRENT_USER',
                     'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
                     'ProxyEnable',
                     1,
                     vtype='REG_DWORD'),
                call('HKEY_CURRENT_USER',
                     'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
                     'ProxyOverride',
                     '<local>;.moo.com;.salt.com')
            ]
            mock_reg.assert_has_calls(calls)
            mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
            self.assertTrue(out)
开发者ID:bryson,项目名称:salt,代码行数:31,代码来源:proxy_test.py


示例5: test_install_ruby_nonroot

 def test_install_ruby_nonroot(self):
     mock = MagicMock(return_value={'retcode': 0, 'stdout': 'stdout'})
     expected = [
         call('/usr/local/rvm/bin/rvm autolibs disable 2.0.0', runas='rvm', cwd=None),
         call('/usr/local/rvm/bin/rvm install --disable-binary 2.0.0', runas='rvm', cwd=None)]
     with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
         rvm.install_ruby('2.0.0', runas='rvm')
         self.assertEqual(mock.call_args_list, expected)
开发者ID:shineforever,项目名称:ops,代码行数:8,代码来源:rvm_test.py


示例6: test_install_ruby_nonroot

 def test_install_ruby_nonroot(self):
     mock = MagicMock(return_value={"retcode": 0, "stdout": "stdout"})
     expected = [
         call("/usr/local/rvm/bin/rvm autolibs disable 2.0.0", runas="rvm", cwd=None),
         call("/usr/local/rvm/bin/rvm install --disable-binary 2.0.0", runas="rvm", cwd=None),
     ]
     with patch.dict(rvm.__salt__, {"cmd.run_all": mock}):
         rvm.install_ruby("2.0.0", runas="rvm")
         self.assertEqual(mock.call_args_list, expected)
开发者ID:DaveQB,项目名称:salt,代码行数:9,代码来源:rvm_test.py


示例7: _test_call

 def _test_call(self, function, expected_sql, *args, **kwargs):
     connect_mock = MagicMock()
     mysql._connect = connect_mock
     with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
         function(*args, **kwargs)
         if isinstance(expected_sql, dict):
             calls = call().cursor().execute("{0}".format(expected_sql["sql"]), expected_sql["sql_args"])
         else:
             calls = call().cursor().execute("{0}".format(expected_sql))
         connect_mock.assert_has_calls(calls)
开发者ID:penta-srl,项目名称:salt,代码行数:10,代码来源:mysql_test.py


示例8: test_stages

 def test_stages(self, call_stage_mock):
     '''
     This is a very basic test and needs expansion, since call_stage is mocked!
     '''
     overstate = salt.overstate.OverState(self.master_config)
     overstate.over = overstate._OverState__sort_stages(OVERSTATE_SLS)
     overstate.stages()
     expected_calls = [call('all', {'require': {'mysql': 'webservers'}, 'match': '*'}),
                       call('mysql', {'match': 'db*', 'sls': {'mysql.server': 'drbd'}}),
                       call('webservers', {'require': ['mysql'], 'match': 'web*'})]
     call_stage_mock.assert_has_calls(expected_calls, any_order=False)
开发者ID:DavideyLee,项目名称:salt,代码行数:11,代码来源:overstate_test.py


示例9: test_gen_keys

 def test_gen_keys(self):
     with patch('salt.utils.fopen', mock_open()):
         open_priv_wb = call('/keydir/keyname.pem', 'wb+')
         open_pub_wb = call('/keydir/keyname.pub', 'wb+')
         with patch('os.path.isfile', return_value=True):
             self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048), '/keydir/keyname.pem')
             self.assertNotIn(open_priv_wb, salt.utils.fopen.mock_calls)
             self.assertNotIn(open_pub_wb, salt.utils.fopen.mock_calls)
         with patch('os.path.isfile', return_value=False):
             with patch('salt.utils.fopen', mock_open()):
                 crypt.gen_keys('/keydir', 'keyname', 2048)
                 salt.utils.fopen.assert_has_calls([open_priv_wb, open_pub_wb], any_order=True)
开发者ID:DaveQB,项目名称:salt,代码行数:12,代码来源:crypt_test.py


示例10: test_install_pkgs

    def test_install_pkgs(self):
        '''
        Test package install behavior for the following conditions:
        - only base package name is given ('png')
        - a flavor is specified ('vim--gtk2')
        - a branch is specified ('ruby%2.3')
        '''
        class ListPackages(object):
            def __init__(self):
                self._iteration = 0

            def __call__(self):
                pkg_lists = [
                     {'vim': '7.4.1467p1-gtk2'},
                     {'png': '1.6.23', 'vim': '7.4.1467p1-gtk2', 'ruby': '2.3.1p1'}
                ]
                pkgs = pkg_lists[self._iteration]
                self._iteration += 1
                return pkgs

        parsed_targets = (
            {'vim--gtk2': None, 'png': None, 'ruby%2.3': None},
            "repository"
        )
        cmd_out = {
            'retcode': 0,
            'stdout': 'quirks-2.241 signed on 2016-07-26T16:56:10Z',
            'stderr': ''
        }
        run_all_mock = MagicMock(return_value=cmd_out)
        patches = {
            'cmd.run_all': run_all_mock,
            'pkg_resource.parse_targets': MagicMock(return_value=parsed_targets),
            'pkg_resource.stringify': MagicMock(),
            'pkg_resource.sort_pkglist': MagicMock(),
        }

        with patch.dict(openbsdpkg.__salt__, patches):
            with patch('salt.modules.openbsdpkg.list_pkgs', ListPackages()):
                added = openbsdpkg.install()
                expected = {
                    'png': {'new': '1.6.23', 'old': ''},
                    'ruby': {'new': '2.3.1p1', 'old': ''}
                }
                self.assertDictEqual(added, expected)
        expected_calls = [
            call('pkg_add -x -I png--%', output_loglevel='trace', python_shell=False),
            call('pkg_add -x -I ruby--%2.3', output_loglevel='trace', python_shell=False),
            call('pkg_add -x -I vim--gtk2%', output_loglevel='trace', python_shell=False),
        ]
        run_all_mock.assert_has_calls(expected_calls, any_order=True)
        self.assertEqual(run_all_mock.call_count, 3)
开发者ID:bryson,项目名称:salt,代码行数:52,代码来源:openbsdpkg_test.py


示例11: test_set_proxy_osx

    def test_set_proxy_osx(self):
        '''
            Test to make sure we can set the proxy settings on OSX
        '''
        proxy.__grains__['os'] = 'Darwin'
        expected = {'changes': {
            'new': [
                {'port': '3128',
                 'server': '192.168.0.1',
                 'service': 'http',
                 'user': 'frank'},
                {'port': '3128',
                 'server': '192.168.0.1',
                 'service': 'https',
                 'user': 'frank'},
                {'port': '3128',
                 'server': '192.168.0.1',
                 'service': 'ftp',
                 'user': 'frank'},
                {'bypass_domains': ['salt.com', 'test.com']}]
            },
            'comment': 'http proxy settings updated correctly\nhttps proxy settings updated correctly\nftp proxy '
                       'settings updated correctly\nProxy bypass domains updated correctly\n',
            'name': '192.168.0.1',
            'result': True}

        set_proxy_mock = MagicMock(return_value=True)
        patches = {
            'proxy.get_http_proxy': MagicMock(return_value={}),
            'proxy.get_https_proxy': MagicMock(return_value={}),
            'proxy.get_ftp_proxy': MagicMock(return_value={}),
            'proxy.get_proxy_bypass': MagicMock(return_value=[]),
            'proxy.set_http_proxy': set_proxy_mock,
            'proxy.set_https_proxy': set_proxy_mock,
            'proxy.set_ftp_proxy': set_proxy_mock,
            'proxy.set_proxy_bypass': set_proxy_mock,
        }

        with patch.dict(proxy.__salt__, patches):
            out = proxy.managed('192.168.0.1', '3128', user='frank', password='passw0rd',
                                bypass_domains=['salt.com', 'test.com'])

            calls = [
                call('192.168.0.1', '3128', 'frank', 'passw0rd', 'Ethernet'),
                call('192.168.0.1', '3128', 'frank', 'passw0rd', 'Ethernet'),
                call('192.168.0.1', '3128', 'frank', 'passw0rd', 'Ethernet'),
                call(['salt.com', 'test.com'], 'Ethernet')
            ]

            set_proxy_mock.assert_has_calls(calls)
            self.assertEqual(out, expected)
开发者ID:HowardMei,项目名称:saltstack,代码行数:51,代码来源:proxy_test.py


示例12: test_list_attrs_hex

    def test_list_attrs_hex(self):
        '''
            Test listing all of the extended attributes of a file with hex
        '''
        expected = {'com.test': 'first', 'com.other': 'second'}
        mock = MagicMock(side_effect=['com.test\ncom.other', 'first', 'second'])
        with patch.dict(xattr.__salt__, {'cmd.run': mock}):
            out = xattr.list('/path/to/file', True)

            calls = [
                call('xattr "/path/to/file"'),
                call('xattr -p -x "com.test" "/path/to/file"'),
                call('xattr -p -x "com.other" "/path/to/file"')
            ]
            mock.assert_has_calls(calls)
            self.assertEqual(out, expected)
开发者ID:HowardMei,项目名称:saltstack,代码行数:16,代码来源:mac_xattr_test.py


示例13: test_get_disk_timeout

    def test_get_disk_timeout(self):
        '''
            Test to make sure we can get the disk timeout value
        '''
        mock = MagicMock()
        mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)", self.query_ouput]

        with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
            ret = powercfg.get_disk_timeout()
            calls = [
                call('powercfg /getactivescheme', python_shell=False),
                call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE', python_shell=False)
            ]
            mock.assert_has_calls(calls)

            self.assertEqual({'ac': 30, 'dc': 15}, ret)
开发者ID:dmyerscough,项目名称:salt,代码行数:16,代码来源:win_powercfg_test.py


示例14: test_get_rule

    def test_get_rule(self):
        '''
        Test if it get firewall rule(s) info
        '''
        val = 'No rules match the specified criteria.'
        mock_cmd = MagicMock(side_effect=['salt', val])
        with patch.dict(win_firewall.__salt__, {'cmd.run': mock_cmd}):
            self.assertDictEqual(win_firewall.get_rule(), {'all': 'salt'})

            self.assertFalse(win_firewall.get_rule())

            calls = [
                call(['netsh', 'advfirewall', 'firewall', 'show', 'rule', 'name=all'], python_shell=False),
                call(['netsh', 'advfirewall', 'firewall', 'show', 'rule', 'name=all'], python_shell=False)
            ]
            mock_cmd.assert_has_calls(calls)
开发者ID:HowardMei,项目名称:saltstack,代码行数:16,代码来源:win_firewall_test.py


示例15: test_set_special

 def test_set_special(self, write_cron_lines_mock):
     expected_write_call = call('DUMMY_USER',
                                ['5 0 * * * /tmp/no_script.sh\n',
                                 '# Lines below here are managed by Salt, do not edit\n',
                                 '@hourly echo Hi!\n'])
     ret = cron.set_special('DUMMY_USER', '@hourly', 'echo Hi!')
     write_cron_lines_mock.assert_has_calls(expected_write_call)
开发者ID:penta-srl,项目名称:salt,代码行数:7,代码来源:cron_test.py


示例16: test_repo_noadd_mod_ref

    def test_repo_noadd_mod_ref(self):
        '''
        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:
        '''
        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.mod_repo(
                name,
                **{'url': url, 'refresh': True, 'gpgautoimport': True}
            )
            self.assertEqual(
                zypper.__zypper__.xml.call.call_args_list,
                [call('--gpg-auto-import-keys', 'refresh', name)]
            )
            zypper.__zypper__.refreshable.xml.call.assert_called_once_with(
                '--gpg-auto-import-keys', 'mr', '--refresh', name
            )
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:zypper_test.py


示例17: test_windows_7

    def test_windows_7(self):
        '''
            Test to make sure we can get the hibernate timeout value on windows 7
        '''
        mock = MagicMock()
        mock.side_effect = ["Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)", self.query_ouput]

        with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
            with patch.dict(powercfg.__grains__, {'osrelease': '7'}):
                ret = powercfg.get_hibernate_timeout()
                calls = [
                    call('powercfg /getactivescheme', python_shell=False),
                    call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP', python_shell=False)
                ]
                mock.assert_has_calls(calls)

                self.assertEqual({'ac': 30, 'dc': 15}, ret)
开发者ID:DaveQB,项目名称:salt,代码行数:17,代码来源:win_powercfg_test.py


示例18: _runner

 def _runner(self, expected_ret, test=False, check=False, delete=False,
             delete_assertion=False):
     mock_check = MagicMock(return_value=check)
     mock_delete = MagicMock(return_value=delete)
     with patch.dict(ipset.__opts__, {'test': test}):
         with patch.dict(ipset.__salt__, {'ipset.check': mock_check,
                                          'ipset.delete': mock_delete}):
             actual_ret = ipset.absent(self.fake_name, self.fake_entries, set_name=self.fake_name)
     mock_check.assert_has_calls([call(self.fake_name, e, 'ipv4') for e in self.fake_entries], any_order=True)
     if delete_assertion:
         expected_calls = [call(self.fake_name, e, 'ipv4', set_name=self.fake_name) for e in self.fake_entries]
         if delete is not True:
             expected_calls = expected_calls[:1]
         mock_delete.assert_has_calls(expected_calls, any_order=True)
     else:
         mock_delete.assert_not_called()
     self.assertDictEqual(actual_ret, expected_ret)
开发者ID:bryson,项目名称:salt,代码行数:17,代码来源:ipset_test.py


示例19: test_traversal_spec_init

    def test_traversal_spec_init(self):
        mock_dc_name = MagicMock()
        mock_traversal_spec = MagicMock()
        mock_traversal_spec_ini = MagicMock(return_value=mock_traversal_spec)
        mock_get_service_instance_from_managed_object = MagicMock()
        patch_traversal_spec_str = \
                'salt.utils.vmware.vmodl.query.PropertyCollector.TraversalSpec'

        with patch(patch_traversal_spec_str, mock_traversal_spec_ini):
            vmware.get_cluster(self.mock_dc, 'fake_cluster')
        mock_traversal_spec_ini.assert_has_calls(
            [call(path='childEntity',
                  skip=False,
                  type=vim.Folder),
            call(path='hostFolder',
                  skip=True,
                  type=vim.Datacenter,
                  selectSet=[mock_traversal_spec])])
开发者ID:bryson,项目名称:salt,代码行数:18,代码来源:cluster_test.py


示例20: test_user_chpass

 def test_user_chpass(self):
     """
     Test changing a MySQL user password in mysql exec module
     """
     connect_mock = MagicMock()
     mysql._connect = connect_mock
     with patch.dict(mysql.__salt__, {"config.option": MagicMock()}):
         mysql.user_chpass("testuser", password="BLUECOW")
         calls = (
             call()
             .cursor()
             .execute(
                 "UPDATE mysql.user SET password=PASSWORD(%(password)s) WHERE User=%(user)s AND Host = %(host)s;",
                 {"password": "BLUECOW", "user": "testuser", "host": "localhost"},
             ),
             call().cursor().execute("FLUSH PRIVILEGES;"),
         )
         connect_mock.assert_has_calls(calls, any_order=True)
开发者ID:penta-srl,项目名称:salt,代码行数:18,代码来源:mysql_test.py



注:本文中的salttesting.mock.call函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mock.mock_open函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.ensure_in_syspath函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap