本文整理汇总了Python中mock.Mock.message方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.message方法的具体用法?Python Mock.message怎么用?Python Mock.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_mock_scheduled_tasks
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def create_mock_scheduled_tasks(cls):
jobs = []
for name in ["foo", "bar", "baz"]:
job = Mock()
job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
job.failure_count = 0
job.assignedTask = Mock(spec=AssignedTask)
job.assignedTask.slaveHost = "slavehost"
job.assignedTask.task = Mock(spec=TaskConfig)
job.assignedTask.task.maxTaskFailures = 1
job.assignedTask.task.executorConfig = Mock(spec=ExecutorConfig)
job.assignedTask.task.executorConfig.data = Mock()
job.assignedTask.task.metadata = []
job.assignedTask.task.owner = Identity(role="mchucarroll")
job.assignedTask.task.environment = "test"
job.assignedTask.task.jobName = "woops"
job.assignedTask.task.numCpus = 2
job.assignedTask.task.ramMb = 2
job.assignedTask.task.diskMb = 2
job.assignedTask.instanceId = 4237894
job.assignedTask.assignedPorts = None
job.status = ScheduleStatus.RUNNING
mockEvent = Mock(spec=TaskEvent)
mockEvent.timestamp = 28234726395
mockEvent.status = ScheduleStatus.RUNNING
mockEvent.message = "Hi there"
job.taskEvents = [mockEvent]
jobs.append(job)
return jobs
示例2: test_agent_policies
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_agent_policies(self):
# set up data
gc = Mock()
service_key = "service_key"
resource_id = "resource_id"
pdpm = PolicyDecisionPointManager(gc)
invocation = Mock()
mock_header = Mock()
invocation.message_annotations = {}
invocation.message = {"argument1": 0}
invocation.headers = {
"op": "op",
"process": "process",
"request": "request",
"ion-actor-id": "ion-actor-id",
"receiver": "resource-registry",
"sender-type": "sender-type",
"sender-service": "Unknown",
"ion-actor-roles": {"org_name": ["SUPERUSER"]},
}
invocation.get_message_receiver.return_value = "service_key"
invocation.get_service_name.return_value = "Unknown"
invocation.get_message_sender.return_value = ["Unknown", "Unknown"]
def get_header_value(key, default):
return invocation.headers.get(key, default)
mock_header.side_effect = get_header_value
invocation.get_header_value = mock_header
mock_args = Mock()
process = Mock()
process.org_governance_name = "org_name"
process.resource_id = "resource_id"
invocation.args = {"process": process}
def get_arg_value(key, default="Unknown"):
return invocation.args.get(key, default)
mock_args.side_effect = get_arg_value
invocation.get_arg_value = mock_args
gc.system_root_org_name = "sys_org_name"
# check that service policies result in denying the request
pdpm.set_service_policy_rules(service_key, self.deny_SUPERUSER_rule)
pdpm.set_resource_policy_rules(resource_id, self.permit_SUPERUSER_rule)
response = pdpm.check_agent_request_policies(invocation)
self.assertEqual(response.value, "Deny")
# check that resource policies result in denying the request
pdpm.set_service_policy_rules(service_key, self.permit_SUPERUSER_rule)
pdpm.set_resource_policy_rules(resource_id, self.deny_SUPERUSER_rule)
response = pdpm.check_agent_request_policies(invocation)
self.assertEqual(response.value, "Deny")
# check that both service and resource policies need to allow a request
pdpm.set_service_policy_rules(service_key, self.permit_SUPERUSER_rule)
pdpm.set_resource_policy_rules(resource_id, self.permit_SUPERUSER_rule)
response = pdpm.check_agent_request_policies(invocation)
self.assertEqual(response.value, "Permit")
示例3: create_mock_scheduled_tasks
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def create_mock_scheduled_tasks(cls):
jobs = []
for name in ['foo', 'bar', 'baz']:
job = Mock()
job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
job.failure_count = 0
job.assignedTask = Mock(spec=AssignedTask)
job.assignedTask.slaveHost = 'slavehost'
job.assignedTask.task = Mock(spec=TaskConfig)
job.assignedTask.task.maxTaskFailures = 1
job.assignedTask.task.packagesDEPRECATED = []
job.assignedTask.task.owner = Identity(role='mchucarroll')
job.assignedTask.task.environment = 'test'
job.assignedTask.task.jobName = 'woops'
job.assignedTask.task.numCpus = 2
job.assignedTask.task.ramMb = 2
job.assignedTask.task.diskMb = 2
job.assignedTask.instanceId = 4237894
job.assignedTask.assignedPorts = None
job.status = ScheduleStatus.RUNNING
mockEvent = Mock(spec=TaskEvent)
mockEvent.timestamp = 28234726395
mockEvent.status = ScheduleStatus.RUNNING
mockEvent.message = "Hi there"
job.taskEvents = [mockEvent]
jobs.append(job)
return jobs
示例4: create_mock_scheduled_tasks
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def create_mock_scheduled_tasks(cls):
jobs = []
for name in ['foo', 'bar', 'baz']:
job_key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
job = Mock()
job.key = job_key
job.failure_count = 0
job.assignedTask = Mock(spec=AssignedTask)
job.assignedTask.taskId = 1287391823
job.assignedTask.slaveHost = 'slavehost'
job.assignedTask.task = Mock(spec=TaskConfig)
job.assignedTask.task.executorConfig = Mock()
job.assignedTask.task.maxTaskFailures = 1
job.assignedTask.task.metadata = []
job.assignedTask.task.job = job_key
job.assignedTask.task.owner = Identity(role=cls.TEST_ROLE)
job.assignedTask.task.environment = cls.TEST_ENV
job.assignedTask.task.jobName = name
job.assignedTask.task.numCpus = 2
job.assignedTask.task.ramMb = 2
job.assignedTask.task.diskMb = 2
job.assignedTask.instanceId = 4237894
job.assignedTask.assignedPorts = {}
job.status = ScheduleStatus.RUNNING
mockEvent = Mock(spec=TaskEvent)
mockEvent.timestamp = 28234726395
mockEvent.status = ScheduleStatus.RUNNING
mockEvent.message = "Hi there"
job.taskEvents = [mockEvent]
jobs.append(job)
return jobs
示例5: test_should_not_exit_when_command_is_ignore_and_message_is_given
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_should_not_exit_when_command_is_ignore_and_message_is_given(self, mock_exit):
options = Mock()
options.message = 'ignore message'
validate_command_line_options(
'ignore', options, self.fake_show_help_callback)
mock_exit.assert_not_called()
示例6: test_should_execute_show_help_callback_when_no_ignore_message_is_given
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_should_execute_show_help_callback_when_no_ignore_message_is_given(self, _):
options = Mock()
options.message = None
validate_command_line_options(
'ignore', options, self.fake_show_help_callback)
self.assertTrue(self._show_help_callback_has_been_called)
示例7: test_should_exit_with_appropriate_code_when_command_is_ignore_and_no_message_was_given
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_should_exit_with_appropriate_code_when_command_is_ignore_and_no_message_was_given(self, mock_exit):
options = Mock()
options.message = None
validate_command_line_options(
'ignore', options, self.fake_show_help_callback)
mock_exit.assert_called_with(EXIT_CODE_MISSING_MESSAGE_OPTION)
示例8: event
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def event():
result = Mock()
for k, v in DEFAULT_PLUGIN_CONFIGURATION.items():
setattr(result.project, k, v)
result.message = 'An error has occured'
result.error.return_value = result.message
return result
示例9: create_blank_response
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def create_blank_response(cls, code, msg):
response = Mock(spec=Response)
response.responseCode = code
mock_msg = Mock()
mock_msg.message = msg
response.details = [mock_msg]
response.messageDEPRECATED = msg
response.result = Mock(spec=Result)
return response
示例10: test_service_policies
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_service_policies(self):
gc = Mock()
service_key = 'service_key'
pdpm = PolicyDecisionPointManager(gc)
# see that the PDP for service is the default
self.assertEqual(pdpm.get_service_pdp(service_key), pdpm.load_common_service_pdp)
pdpm.load_service_policy_rules(service_key, self.permit_ION_MANAGER_rule)
# see that the PDP for service is not the default anymore
self.assertNotEqual(pdpm.get_service_pdp(service_key), pdpm.load_common_service_pdp)
# check request without a service_key raises NotFound error
invocation = Mock()
invocation.message_annotations = {}
invocation.get_message_receiver.return_value = None
with self.assertRaises(NotFound) as chk_res:
pdpm.check_service_request_policies(invocation)
self.assertIn(chk_res.exception.message, 'No receiver for this message')
# check that, because actor does not have ION_MANAGER role, policy evaluates to a denial
# (really Not Applicable, because of the inelegant hack of a policy we are setting up our pdp with)
mock_header = Mock()
invocation.message_annotations = {}
invocation.message = {'argument1': 0}
invocation.headers = {'op': 'op', 'process': 'process', 'request': 'request', 'ion-actor-id': 'ion-actor-id', 'receiver': 'resource-registry',
'sender-type': 'sender-type', 'sender-service': 'Unknown', 'ion-actor-roles': {'org_name': ['ion-actor-roles']}}
invocation.get_message_receiver.return_value = 'service_key'
invocation.get_service_name.return_value = 'Unknown'
invocation.get_message_sender.return_value = ['Unknown','Unknown']
def get_header_value(key, default):
return invocation.headers.get(key, default)
mock_header.side_effect = get_header_value
invocation.get_header_value = mock_header
mock_args = Mock()
process = Mock()
process.org_governance_name = 'org_name'
invocation.args = {'process': process}
def get_arg_value(key, default):
return invocation.args.get(key, default)
mock_args.side_effect = get_arg_value
invocation.get_arg_value = mock_args
gc.system_root_org_name = 'sys_org_name'
response = pdpm.check_service_request_policies(invocation)
self.assertEqual(response.value, "NotApplicable")
# check that policy evaluates to Permit because actor has ION_MANAGER role
invocation.message_annotations = {}
invocation.headers = {'op': 'op', 'process': 'process', 'request': 'request', 'ion-actor-id': 'ion-actor-id', 'receiver': 'resource-registry',
'sender-type': 'sender-type', 'sender-service': 'sender-service', 'ion-actor-roles': {'sys_org_name': ['ION_MANAGER']}}
response = pdpm.check_service_request_policies(invocation)
self.assertEqual(response.value, "Permit")
示例11: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def setUp(self): # pylint: disable=C0103
"""Test setup."""
os.mkdir(TMP)
self.queuename = os.path.join(TMP, "wq")
ctrl = Mock()
ctrl.message = "start"
ctrl.config = ConfigParser()
ctrl.config.add_section("obsticket")
ctrl.config.set("obsticket", "prjdir", TMP)
self.participant = obsticket.ParticipantHandler()
self.participant.handle_lifecycle_control(ctrl)
示例12: event
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def event():
result = Mock()
for k, v in DEFAULT_PLUGIN_CONFIGURATION.items():
setattr(result.project, k, v)
result.get_level_display = Mock()
result.get_level_display.return_value = 'ERROR'
result.message = 'An error has occured'
return result
示例13: test_handle_lifecycle_control
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def test_handle_lifecycle_control(self):
ctrl = Mock()
ctrl.message = "start"
ctrl.config = ConfigParser()
self.assertRaises(RuntimeError,
self.participant.handle_lifecycle_control, ctrl)
ctrl.config.add_section("obs")
ctrl.config.set("obs", "oscrc", "oscrc_file")
self.participant.handle_lifecycle_control(ctrl)
ctrl.config.add_section("check_yaml")
ctrl.config.set("check_yaml", "spec_pattern", "test")
self.participant.handle_lifecycle_control(ctrl)
示例14: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def setUp(self): # pylint: disable=C0103
"""Test setup."""
BaseTestParticipantHandler.setUp(self)
ctrl = Mock()
ctrl.message = "start"
ctrl.config = ConfigParser()
ctrl.config.add_section("obs")
ctrl.config.add_section("defineimage")
ctrl.config.add_section("testing")
ctrl.config.set("obs", "oscrc", "oscrc_file")
ctrl.config.set("defineimage", "imagetypes", "testing")
ctrl.config.set("testing", "always_include", "base-tests")
self.ctrl = ctrl
示例15: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import message [as 别名]
def setUp(self):
"""Set up the tests."""
BaseTestParticipantHandler.setUp(self)
os.mkdir(TEMP_DIR)
config = ConfigParser()
config.add_section("obs")
config.set("obs", "oscrc", "oscrc_file")
config.add_section("getbuildlog")
config.set("getbuildlog", "logdir", "test_tmp")
ctrl = Mock()
ctrl.message = "start"
ctrl.config = config
self.participant.handle_lifecycle_control(ctrl)