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


Python mock.PropertyMock方法代码示例

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


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

示例1: _init_rest

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def _init_rest(application, post_requset):
    connection = MagicMock()
    connection._login_timeout = 120
    connection._network_timeout = None
    connection.errorhandler = Mock(return_value=None)
    connection._ocsp_mode = Mock(return_value=OCSPMode.FAIL_OPEN)
    type(connection).application = PropertyMock(return_value=application)
    type(connection)._internal_application_name = PropertyMock(
        return_value=CLIENT_NAME
    )
    type(connection)._internal_application_version = PropertyMock(
        return_value=CLIENT_VERSION
    )

    rest = SnowflakeRestful(host='testaccount.snowflakecomputing.com',
                            port=443,
                            connection=connection)
    rest._post_request = post_requset
    return rest 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:21,代码来源:test_unit_auth.py

示例2: test_get_s3_file_object_http_400_error

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_get_s3_file_object_http_400_error():
    """Tests Get S3 file object with HTTP 400 error.

    Looks like HTTP 400 is returned when AWS token expires and S3.Object.load is called.
    """
    load_method = MagicMock(
        side_effect=botocore.exceptions.ClientError(
            {'Error': {'Code': '400', 'Message': 'Bad Request'}},
            operation_name='mock load'))
    s3object = MagicMock(load=load_method)
    client = Mock()
    client.Object.return_value = s3object
    client.load.return_value = None
    type(client).s3path = PropertyMock(return_value='s3://testbucket/')
    meta = {
        'client': client,
        'stage_info': {
            'location': 'sfc-teststage/rwyitestacco/users/1234/',
            'locationType': 'S3',
        }
    }
    filename = "/path1/file2.txt"
    akey = SnowflakeS3Util.get_file_header(meta, filename)
    assert akey is None
    assert meta['result_status'] == ResultStatus.RENEW_TOKEN 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:27,代码来源:test_unit_s3_util.py

示例3: test_fetch_current_log_pos_return_first_token

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_fetch_current_log_pos_return_first_token(self):
        """
        Test fetch_current_log_pos should return the the first encountered token
        """
        cursor_mock = Mock(spec_set=DatabaseChangeStream).return_value
        type(cursor_mock).alive = PropertyMock(return_value=True)
        type(cursor_mock).resume_token = PropertyMock(side_effect=['token1', 'token2',
                                                                   'token3', 'token4'])
        cursor_mock.try_next.side_effect = [{}, {}, {}]

        mock_enter = Mock()
        mock_enter.return_value = cursor_mock

        mock_watch = Mock().return_value
        mock_watch.__enter__ = mock_enter
        mock_watch.__exit__ = Mock()

        self.mongo.database = Mock(spec_set=Database).return_value
        self.mongo.database.watch.return_value = mock_watch

        self.assertDictEqual({
            'token': 'token1'
        }, self.mongo.fetch_current_log_pos()) 
开发者ID:transferwise,项目名称:pipelinewise,代码行数:25,代码来源:test_fastsync_tap_mongodb.py

示例4: test_decrypt_data_key_unsuccessful_matching_provider_invalid_key_id

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_decrypt_data_key_unsuccessful_matching_provider_invalid_key_id(self):
        mock_encrypted_data_key = MagicMock()
        mock_encrypted_data_key.key_provider.provider_id = sentinel.provider_id
        mock_encrypted_data_key.key_provider.key_info = sentinel.key_info

        mock_master_key_provider = MockMasterKeyProvider(
            provider_id=sentinel.provider_id, mock_new_master_key=sentinel.master_key
        )
        with patch.object(
            mock_master_key_provider, "master_key_for_decrypt", new_callable=PropertyMock, side_effect=InvalidKeyIdError
        ) as mock_master_key:
            with pytest.raises(DecryptKeyError) as excinfo:
                mock_master_key_provider.decrypt_data_key(
                    encrypted_data_key=mock_encrypted_data_key,
                    algorithm=sentinel.algorithm,
                    encryption_context=sentinel.encryption_context,
                )
            excinfo.match("Unable to decrypt data key")
            mock_master_key.assert_called_once_with(sentinel.key_info) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:21,代码来源:test_providers_base_master_key_provider.py

示例5: test_init_raspi_tty_ser

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_init_raspi_tty_ser(self, mocker, transport):  # noqa: F811
        mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None
        device_tree_model = mocker.mock_open(read_data=b"Raspberry Pi")
        mocker.patch('nfc.clf.pn532.open', device_tree_model)
        type(transport.tty).port = PropertyMock(return_value='/dev/ttyS0')
        stty = mocker.patch('os.system')
        stty.return_value = -1
        sys.platform = "linux"

        transport.write.return_value = None
        transport.read.side_effect = [
            ACK(), RSP('03 32010607'),                    # GetFirmwareVersion
            ACK(), RSP('15'),                             # SAMConfiguration
        ]
        device = nfc.clf.pn532.init(transport)
        assert isinstance(device, nfc.clf.pn532.Device)
        assert stty.mock_calls == []
        assert transport.write.mock_calls == [call(_) for _ in [
            HEX(10 * '00') + CMD('02'),                   # GetFirmwareVersion
            HEX(10 * '00') + CMD('14 010000'),            # SAMConfiguration
        ]]
        assert transport.read.mock_calls == [
            call(timeout=100), call(timeout=100),
            call(timeout=100), call(timeout=100),
        ] 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:27,代码来源:test_clf_pn532.py

示例6: test_init_T4A

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_init_T4A(
        mocker, rats_response, max_send, max_recv, result):  # noqa: F811
    clf = nfc.ContactlessFrontend()
    mocker.patch.object(clf, 'exchange', autospec=True)
    mocker.patch('nfc.ContactlessFrontend.max_send_data_size',
                 new_callable=mock.PropertyMock).return_value = max_send
    mocker.patch('nfc.ContactlessFrontend.max_recv_data_size',
                 new_callable=mock.PropertyMock).return_value = max_recv

    target = nfc.clf.RemoteTarget("106A")
    target.sens_res = HEX("4403")
    target.sel_res = HEX("20")
    target.sdd_res = HEX("04832F9A272D80")

    rats_command = 'E070' if max_recv < 256 else 'E080'
    clf.exchange.return_value = HEX(rats_response)
    tag = nfc.tag.activate(clf, target)
    clf.exchange.assert_called_once_with(HEX(rats_command), 0.03)
    assert isinstance(tag, nfc.tag.tt4.Type4Tag)
    assert str(tag) == result 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:22,代码来源:test_tag_tt4.py

示例7: test_whatchanged_pagination

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_whatchanged_pagination(self):
        self.page.raw = 'line\n'
        Git().commit(self.page, message=u'one')
        self.page.raw += 'line 2\n'
        Git().commit(self.page, message=u'two')
        self.page.raw += 'line 3\n'
        Git().commit(self.page, message=u'three')
        with patch('waliki.git.views.settings') as s_mock:
            type(s_mock).WALIKI_PAGINATE_BY = PropertyMock(return_value=2)
            response1 = self.client.get(reverse('waliki_whatchanged'))
            response2 = self.client.get(reverse('waliki_whatchanged', args=('2',)))

        # first page has no previous page
        self.assertIsNone(response1.context[0]['prev'])
        self.assertEqual(response1.context[0]['next'], 2)
        self.assertIsNone(response2.context[0]['next'])
        self.assertEqual(response2.context[0]['prev'], 1)

        changes1 = response1.context[0]['changes']
        changes2 = response2.context[0]['changes']
        self.assertEqual(len(changes1), 2)
        self.assertEqual(len(changes2), 1)
        self.assertEqual(changes1[0]['message'], 'three')
        self.assertEqual(changes1[1]['message'], 'two')
        self.assertEqual(changes2[0]['message'], 'one') 
开发者ID:mgaitan,项目名称:waliki,代码行数:27,代码来源:test_git.py

示例8: test_state_is_ready___run_is_started

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_state_is_ready___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, input_file=fake_related_file(), settings_file=fake_related_file())
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.run_analysis_signature', PropertyMock(return_value=sig_res)):
                    analysis.run(initiator)

                    sig_res.link.assert_called_once_with(record_run_analysis_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_run_analysis_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例9: test_state_is_not_running___run_is_started

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_state_is_not_running___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis.generate_inputs(initiator)

                    sig_res.link.assert_called_once_with(record_generate_input_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_generate_input_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例10: test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'status': [
                        'Analysis status must be one of [NEW, INPUTS_GENERATION_ERROR, INPUTS_GENERATION_CANCELLED, READY, RUN_COMPLETED, RUN_CANCELLED, RUN_ERROR]'
                    ]}, ex.exception.detail)
                    self.assertEqual(status, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例11: test_portfolio_has_no_location_file___validation_error_is_raised_revoke_is_not_called

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_portfolio_has_no_location_file___validation_error_is_raised_revoke_is_not_called(self, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=Analysis.status_choices.NEW, run_task_id=task_id)

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'portfolio': ['"location_file" must not be null']}, ex.exception.detail)

                    self.assertEqual(Analysis.status_choices.NEW, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:19,代码来源:test_analysis_model.py

示例12: test_load_script

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_load_script(self, isfile_mock, script_mock):
        """Test command to load a script."""
        script_name = 'Foo.js'
        script_type = 'proxy'
        engine = 'Oracle Nashorn'
        valid_engines = ['ECMAScript : Oracle Nashorn']

        isfile_mock.return_value = True

        class_mock = MagicMock()
        class_mock.load.return_value = 'OK'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', script_name, '--script-type', script_type,
                                              '--engine', engine, '--file-path', script_name])
        class_mock.load.assert_called_with(script_name, script_type, engine, script_name, scriptdescription='')
        self.assertEqual(result.exit_code, 0) 
开发者ID:Grunny,项目名称:zap-cli,代码行数:22,代码来源:cli_test.py

示例13: test_load_script_engine_error

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_load_script_engine_error(self, isfile_mock, script_mock):
        """Testing that an error is raised when an invalid engine is provided."""
        isfile_mock.return_value = True

        valid_engines = ['ECMAScript : Oracle Nashorn']
        class_mock = MagicMock()
        class_mock.load.return_value = 'OK'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', 'Foo.js', '--script-type', 'proxy',
                                              '--engine', 'Invalid Engine', '--file-path', 'Foo.js'])
        self.assertEqual(result.exit_code, 2)
        self.assertFalse(class_mock.load.called) 
开发者ID:Grunny,项目名称:zap-cli,代码行数:18,代码来源:cli_test.py

示例14: test_load_script_unknown_error

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_load_script_unknown_error(self, isfile_mock, script_mock):
        """Testing that an error is raised when an erro response is received from the API."""
        script_name = 'Foo.js'
        script_type = 'proxy'
        engine = 'Oracle Nashorn'
        valid_engines = ['ECMAScript : Oracle Nashorn']

        isfile_mock.return_value = True

        class_mock = MagicMock()
        class_mock.load.return_value = 'Internal Error'
        engines = PropertyMock(return_value=valid_engines)
        type(class_mock).list_engines = engines
        script_mock.return_value = class_mock

        result = self.runner.invoke(cli.cli, ['--boring', '--api-key', '', 'scripts', 'load',
                                              '--name', script_name, '--script-type', script_type,
                                              '--engine', engine, '--file-path', script_name])
        self.assertEqual(result.exit_code, 2)
        class_mock.load.assert_called_with(script_name, script_type, engine, script_name, scriptdescription='') 
开发者ID:Grunny,项目名称:zap-cli,代码行数:22,代码来源:cli_test.py

示例15: test_find_payments

# 需要导入模块: import mock [as 别名]
# 或者: from mock import PropertyMock [as 别名]
def test_find_payments(self):
        cls = LowestBalanceFirstMethod(Decimal('100.00'))
        s1 = Mock(spec_set=CCStatement)
        type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s1).principal = PropertyMock(return_value=Decimal('10.00'))
        s2 = Mock(spec_set=CCStatement)
        type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00'))
        type(s2).principal = PropertyMock(return_value=Decimal('25.00'))
        s3 = Mock(spec_set=CCStatement)
        type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00'))
        type(s3).principal = PropertyMock(return_value=Decimal('1234.56'))
        s4 = Mock(spec_set=CCStatement)
        type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00'))
        type(s4).principal = PropertyMock(return_value=Decimal('3.00'))
        assert cls.find_payments([s1, s2, s3, s4]) == [
            Decimal('2.00'),
            Decimal('5.00'),
            Decimal('2.00'),
            Decimal('91.00')
        ] 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:22,代码来源:test_interest.py


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