当前位置: 首页>>代码示例>>Python>>正文


Python mock.ANY属性代码示例

本文整理汇总了Python中mock.ANY属性的典型用法代码示例。如果您正苦于以下问题:Python mock.ANY属性的具体用法?Python mock.ANY怎么用?Python mock.ANY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在mock的用法示例。


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

示例1: testAddAnchorCertificateSuccess

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def testAddAnchorCertificateSuccess(self, mock_certificate, mock_addpayload):
    mock_certobj = mock.MagicMock()
    mock_certobj.subject_cn = 'My Cert Subject'
    mock_certobj.osx_fingerprint = '0011223344556677889900'
    mock_certificate.return_value = mock_certobj

    profile = profiles.NetworkProfile('testuser')
    profile.AddAnchorCertificate('my_cert')

    mock_certificate.assert_called_once_with('my_cert')
    mock_addpayload.assert_called_once_with(
        {profiles.PAYLOADKEYS_IDENTIFIER:
             'com.megacorp.networkprofile.0011223344556677889900',
         profiles.PAYLOADKEYS_TYPE: 'com.apple.security.pkcs1',
         profiles.PAYLOADKEYS_DISPLAYNAME: 'My Cert Subject',
         profiles.PAYLOADKEYS_CONTENT: profiles.plistlib.Data('my_cert'),
         profiles.PAYLOADKEYS_ENABLED: True,
         profiles.PAYLOADKEYS_VERSION: 1,
         profiles.PAYLOADKEYS_UUID: mock.ANY}) 
开发者ID:google,项目名称:macops,代码行数:21,代码来源:profiles_test.py

示例2: testSyncClockToNtp

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def testSyncClockToNtp(self, request, subproc, sleep):
    os.environ['TZ'] = 'UTC'
    time.tzset()
    return_time = mock.Mock()
    return_time.ref_time = 1453220630.64458
    request.side_effect = iter([None, None, None, return_time])
    subproc.return_value = True
    # Too Few Retries
    self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp)
    sleep.assert_has_calls([mock.call(30), mock.call(30)])
    # Sufficient Retries
    ntp.SyncClockToNtp(retries=3, server='time.google.com')
    request.assert_called_with(mock.ANY, 'time.google.com', version=3)
    subproc.assert_has_calls([
        mock.call(
            r'X:\Windows\System32\cmd.exe /c date 01-19-2016', shell=True),
        mock.call(r'X:\Windows\System32\cmd.exe /c time 16:23:50', shell=True)
    ])
    # Socket Error
    request.side_effect = ntp.socket.gaierror
    self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp)
    # NTP lib error
    request.side_effect = ntp.ntplib.NTPException
    self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp) 
开发者ID:google,项目名称:glazier,代码行数:26,代码来源:ntp_test.py

示例3: testEncryptionLevel

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def testEncryptionLevel(self, info, tpm, virtual, model):
    model.return_value = 'HP Z440 Workstation'
    tpm.return_value = False
    virtual.return_value = True
    # virtual machine
    self.assertEqual(self.buildinfo.EncryptionLevel(), 'none')
    info.assert_called_with(
        _REGEXP('^Virtual machine type .*'), mock.ANY)
    virtual.return_value = False
    self.buildinfo.EncryptionLevel.cache_clear()
    # tpm
    tpm.return_value = True
    self.assertEqual(self.buildinfo.EncryptionLevel(), 'tpm')
    info.assert_called_with(_REGEXP('^TPM detected .*'))
    self.buildinfo.EncryptionLevel.cache_clear()
    # default
    self.assertEqual(self.buildinfo.EncryptionLevel(), 'tpm') 
开发者ID:google,项目名称:glazier,代码行数:19,代码来源:buildinfo_test.py

示例4: _test_api_call

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def _test_api_call(self, call, endpoint, request, expected_query_params, api_response, expected_result):
        """
        Tests a VirusTotalApi call by mocking out the HTTP request.

        Args:
            call: function in VirusTotalApi to call.
            endpoint: endpoint of VirusTotal API that is hit (appended to base url)
            request: call arguments
            expected_query_params: query parameters that should be passed to API
            api_response: the expected response by the API
            expected_result: what call should return (given the api response provided)
        """
        with patch.object(self.vt, '_requests') as request_mock:
            request_mock.multi_get.return_value = api_response
            result = call(request)
            param_list = [self.vt.BASE_DOMAIN + endpoint.format(param) for param in expected_query_params]
            request_mock.multi_get.assert_called_with(param_list, file_download=ANY)
            T.assert_equal(result, expected_result) 
开发者ID:Yelp,项目名称:threat_intel,代码行数:20,代码来源:virustotal_test.py

示例5: test_main_minimal

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_main_minimal():
    with patch('arctic.scripts.arctic_create_user.logger', autospec=True) as logger, \
         patch('arctic.scripts.arctic_create_user.MongoClient', autospec=True) as MC, \
         patch('arctic.scripts.arctic_create_user.get_mongodb_uri', autospec=True) as get_mongodb_uri, \
         patch('arctic.scripts.arctic_create_user.do_db_auth', autospec=True) as do_db_auth:
        run_as_main(main, '--host', 'some_host',
                          '--password', 'asdf',
                          'user')
    get_mongodb_uri.assert_called_once_with('some_host')
    MC.assert_called_once_with(get_mongodb_uri.return_value)
    assert do_db_auth.call_args_list == [call('some_host',
                                              MC.return_value,
                                              'admin')]
    assert MC.return_value.__getitem__.call_args_list == [call('arctic_user')]
    db = MC.return_value.__getitem__.return_value
    assert [call('user', ANY, read_only=False)] == db.add_user.call_args_list
    assert logger.info.call_args_list == [call('Granted: user [WRITE] to arctic_user'),
                                          call('User creds: arctic_user/user/asdf')] 
开发者ID:man-group,项目名称:arctic,代码行数:20,代码来源:test_arctic_create_user.py

示例6: test_main_with_db_write

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_main_with_db_write():
    with patch('arctic.scripts.arctic_create_user.MongoClient', autospec=True) as MC, \
         patch('arctic.scripts.arctic_create_user.get_mongodb_uri', autospec=True) as get_mongodb_uri, \
         patch('arctic.scripts.arctic_create_user.do_db_auth', autospec=True) as do_db_auth:
        run_as_main(main, '--host', 'some_host',
                    '--db', 'some_db',
                    '--write',
                    'jblackburn')
    get_mongodb_uri.assert_called_once_with('some_host')
    MC.assert_called_once_with(get_mongodb_uri.return_value)
    assert do_db_auth.call_args_list == [call('some_host',
                                              MC.return_value,
                                              'some_db')]
    assert MC.return_value.__getitem__.call_args_list == [call('some_db')]
    db = MC.return_value.__getitem__.return_value
    assert [call('jblackburn', ANY, read_only=False)] == db.add_user.call_args_list 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_arctic_create_user.py

示例7: test_ArcticTransaction_writes_if_base_data_corrupted

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_ArcticTransaction_writes_if_base_data_corrupted():

    vs = Mock(spec=VersionStore)
    ts1 = pd.DataFrame(index=[1, 2], data={'a': [1.0, 2.0]})
    vs.read.side_effect = OperationFailure('some failure')
    vs.write.return_value = VersionedItem(symbol=sentinel.symbol, library=sentinel.library, version=2,
                                          metadata=None, data=None, host=sentinel.host)
    vs.read_metadata.return_value = VersionedItem(symbol=sentinel.symbol, library=sentinel.library, version=1,
                                                  metadata=None, data=None, host=sentinel.host)
    vs.list_versions.return_value = [{'version': 2}, {'version': 1}]

    with ArcticTransaction(vs, sentinel.symbol, sentinel.user, sentinel.log) as cwb:
        cwb.write(sentinel.symbol, ts1, metadata={1: 2})

    vs.write.assert_called_once_with(sentinel.symbol, ANY, prune_previous_version=True, metadata={1: 2})
    assert vs.list_versions.call_args_list == [call(sentinel.symbol)] 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_version_store_audit.py

示例8: test_ArcticTransaction_writes_no_data_found

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_ArcticTransaction_writes_no_data_found():
    vs = Mock(spec=VersionStore)
    ts1 = pd.DataFrame(index=[1, 2], data={'a': [1.0, 2.0]})
    vs.read.side_effect = NoDataFoundException('no data')
    vs.write.return_value = VersionedItem(symbol=sentinel.symbol, library=sentinel.library, version=1,
                                          metadata=None, data=None, host=sentinel.host)
    vs.list_versions.side_effect = [[],
                                   [{'version': 1}],
                                   ]

    with ArcticTransaction(vs, sentinel.symbol, sentinel.user, sentinel.log) as cwb:
        cwb.write(sentinel.symbol, ts1, metadata={1: 2})

    assert vs.write.call_args_list == [call(sentinel.symbol, ANY, prune_previous_version=True, metadata={1: 2})]
    assert vs.list_versions.call_args_list == [call(sentinel.symbol, latest_only=True),
                                              call(sentinel.symbol)] 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_version_store_audit.py

示例9: test_ArcticTransaction_writes_no_data_found_deleted

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_ArcticTransaction_writes_no_data_found_deleted():
    vs = Mock(spec=VersionStore)
    ts1 = pd.DataFrame(index=[1, 2], data={'a': [1.0, 2.0]})
    vs.read.side_effect = NoDataFoundException('no data')
    vs.write.return_value = VersionedItem(symbol=sentinel.symbol, library=sentinel.library, version=3,
                                          metadata=None, data=None, host=sentinel.host)
    vs.list_versions.side_effect = [[{'version': 2}, {'version': 1}],
                                   [{'version': 3}, {'version': 2}],
                                   ]

    with ArcticTransaction(vs, sentinel.symbol, sentinel.user, sentinel.log) as cwb:
        cwb.write(sentinel.symbol, ts1, metadata={1: 2})

    assert vs.write.call_args_list == [call(sentinel.symbol, ANY, prune_previous_version=True, metadata={1: 2})]
    assert vs.list_versions.call_args_list == [call(sentinel.symbol, latest_only=True),
                                              call(sentinel.symbol)] 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_version_store_audit.py

示例10: test_log_commit_send_notifications_valid_project

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_log_commit_send_notifications_valid_project(self, log, notif):
        """ Test the log_commit_send_notifications method. """
        output = pagure.lib.tasks_services.log_commit_send_notifications(
            name="test",
            commits=["hash1", "hash2"],
            abspath="/path/to/git",
            branch="master",
            default_branch="master",
            namespace=None,
            username=None,
        )
        self.assertIsNone(output)
        log.assert_called_once_with(
            ANY, ANY, ["hash1", "hash2"], "/path/to/git"
        )
        notif.assert_called_once_with(
            "/path/to/git", ANY, "master", ["hash1", "hash2"]
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:20,代码来源:test_pagure_lib_task_services.py

示例11: test_webhook_notification_no_webhook

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_webhook_notification_no_webhook(self, call_wh):
        """ Test the webhook_notification method. """

        output = pagure.lib.tasks_services.webhook_notification(
            topic="topic",
            msg={"payload": ["a", "b", "c"]},
            namespace=None,
            name="test",
            user=None,
        )
        self.assertIsNone(output)

        project = pagure.lib.query._get_project(self.session, "test")
        call_wh.assert_called_once_with(
            ANY,
            "topic",
            {"payload": ["a", "b", "c"]},
            ["http://foo.com/api/flag", "http://bar.org/bar"],
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:test_pagure_lib_task_services.py

示例12: testResourceContainerWarning

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def testResourceContainerWarning(self):
    """Check the warning if a ResourceContainer isn't used when it should be."""

    class TestGetRequest(messages.Message):
      item_id = messages.StringField(1)

    @api_config.api('myapi', 'v0', hostname='example.appspot.com')
    class MyApi(remote.Service):

      @api_config.method(TestGetRequest, message_types.VoidMessage,
                         path='test/{item_id}')
      def Test(self, unused_request):
        return message_types.VoidMessage()

    # Verify that there's a warning and the name of the method is included
    # in the warning.
    api_config._logger.warning = mock.Mock()
    self.generator.pretty_print_config_to_json(MyApi)
    api_config._logger.warning.assert_called_with(mock.ANY, 'myapi.test', TestGetRequest) 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:21,代码来源:api_config_test.py

示例13: test_call_with_invalid_method

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_call_with_invalid_method(self):
        self.handler.side_effect = werkzeug.exceptions.BadRequest()

        body = self.mw(env("/_app-metrics/metrics", REQUEST_METHOD='POST'), self.start_response)

        expected_body = json.dumps(werkzeug.exceptions.MethodNotAllowed.description)
        assert_equal(b"".join(body), expected_body.encode('utf8'))

        assert_equal(
            self.start_response.call_args_list,
            [mock.call("405 METHOD NOT ALLOWED", mock.ANY)]
        )

        headers = dict(self.start_response.call_args_list[0][0][1])
        assert_equal(headers['Content-Type'], "application/json")
        assert_equal(headers['Content-Length'], str(len(expected_body)))
        allow = {x.strip() for x in headers['Allow'].split(",")}
        assert_equal(allow, {"HEAD", "GET"}) 
开发者ID:avalente,项目名称:appmetrics,代码行数:20,代码来源:test_wsgi.py

示例14: test_push_datapackage

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_push_datapackage(storage):

    # Prepare and call
    descriptor = 'data/datapackage/datapackage.json'
    storage.buckets = ['data___data']  # Without patch it's a reflection
    module.push_datapackage(descriptor=descriptor, backend='backend')

    # Assert mocked calls
    storage.create.assert_called_with(
        ['data___data'],
        [{'fields': [
            {'name': 'id', 'type': 'integer', 'format': 'default'},
            {'name': 'city', 'type': 'string', 'format': 'default'}],
          'missingValues': ['']}])
    storage.write.assert_called_with('data___data', ANY)

    # Assert writen data
    data = storage.write.call_args[0][1]
    assert list(data) == [
        (1, 'London'),
        (2, 'Paris'),
    ] 
开发者ID:frictionlessdata,项目名称:datapackage-py,代码行数:24,代码来源:test_pushpull.py

示例15: test_recovery_code_creation

# 需要导入模块: import mock [as 别名]
# 或者: from mock import ANY [as 别名]
def test_recovery_code_creation(self,
                                    mock_http_request,
                                    mock_cookie_agent,
                                    mock_is_authenticated):
        api = Api('https://api.test:4430')
        credentials = UsernamePassword('username', 'password')

        mock_is_authenticated.return_value = True
        session = Session(credentials, api, 'fake path')
        session._uuid = '123'

        response = yield session.update_recovery_code('RECOVERY_CODE')
        mock_http_request.assert_called_with(
            ANY, 'https://api.test:4430/1/users/123',
            method='PUT',
            token=None,
            values={'user[recovery_code_salt]': ANY,
                    'user[recovery_code_verifier]': ANY}) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:20,代码来源:test_users.py


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