當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。