本文整理汇总了Python中mock.Mock.set方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.set方法的具体用法?Python Mock.set怎么用?Python Mock.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_must_skip_if_definition_body_is_not_present
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_skip_if_definition_body_is_not_present(self, SwaggerEditorMock):
event_id = "id"
properties = {
"RestApiId": {"Ref": "restid"},
"Path": "/hello",
"Method": "GET"
}
mock_api = SamResource({
"Type": "AWS::Serverless::Api",
"Properties": {
"DefinitionUri": "s3://bucket/key",
}
})
SwaggerEditorMock.is_valid = Mock()
SwaggerEditorMock.is_valid.return_value = False
template_mock = Mock()
template_mock.get = Mock()
template_mock.set = Mock()
template_mock.get.return_value = mock_api
self.plugin._add_api_to_swagger(event_id, properties, template_mock)
SwaggerEditorMock.is_valid.assert_called_with(None)
template_mock.get.assert_called_with('restid')
SwaggerEditorMock.assert_not_called()
template_mock.set.assert_not_called()
示例2: test_must_skip_if_api_resource_properties_are_invalid
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_skip_if_api_resource_properties_are_invalid(self, SwaggerEditorMock):
event_id = "id"
properties = {
"RestApiId": {"Ref": "restid"},
"Path": "/hello",
"Method": "GET"
}
mock_api = SamResource({
"Type": "AWS::Serverless::Api",
"Properties": "this is not a valid property"
})
SwaggerEditorMock.is_valid = Mock()
template_mock = Mock()
template_mock.get = Mock()
template_mock.set = Mock()
template_mock.get.return_value = mock_api
self.plugin._add_api_to_swagger(event_id, properties, template_mock)
SwaggerEditorMock.is_valid.assert_not_called()
template_mock.get.assert_called_with('restid')
SwaggerEditorMock.assert_not_called()
template_mock.set.assert_not_called()
示例3: test_must_process_functions
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_process_functions(self, SamTemplateMock):
template_dict = {"a": "b"}
function1 = SamResource({"Type": "AWS::Serverless::Function"})
function2 = SamResource({"Type": "AWS::Serverless::Function"})
function3 = SamResource({"Type": "AWS::Serverless::Function"})
function_resources = [("id1", function1), ("id2", function2), ("id3", function3)]
api_events = ["event1", "event2"]
sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.set = Mock()
sam_template.iterate = Mock()
sam_template.iterate.return_value = function_resources
self.plugin._get_api_events.return_value = api_events
self.plugin.on_before_transform_template(template_dict)
SamTemplateMock.assert_called_with(template_dict)
sam_template.set.assert_called_with(IMPLICIT_API_LOGICAL_ID, ImplicitApiResource().to_dict())
# Make sure this is called only for Functions
sam_template.iterate.assert_any_call("AWS::Serverless::Function")
sam_template.iterate.assert_any_call("AWS::Serverless::Api")
self.plugin._get_api_events.assert_has_calls([call(function1), call(function2), call(function3)])
self.plugin._process_api_events.assert_has_calls([
call(function1, ["event1", "event2"], sam_template, None),
call(function2, ["event1", "event2"], sam_template, None),
call(function3, ["event1", "event2"], sam_template, None),
])
self.plugin._maybe_remove_implicit_api.assert_called_with(sam_template)
示例4: test_must_skip_invalid_swagger
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_skip_invalid_swagger(self, SwaggerEditorMock):
event_id = "id"
properties = {
"RestApiId": {"Ref": "restid"},
"Path": "/hello",
"Method": "GET"
}
original_swagger = {"this": "is", "valid": "swagger"}
mock_api = SamResource({
"Type": "AWS::Serverless::Api",
"Properties": {
"DefinitionBody": original_swagger,
"a": "b"
}
})
SwaggerEditorMock.is_valid = Mock()
SwaggerEditorMock.is_valid.return_value = False
template_mock = Mock()
template_mock.get = Mock()
template_mock.set = Mock()
template_mock.get.return_value = mock_api
self.plugin._add_api_to_swagger(event_id, properties, template_mock)
SwaggerEditorMock.is_valid.assert_called_with(original_swagger)
template_mock.get.assert_called_with('restid')
SwaggerEditorMock.assert_not_called()
template_mock.set.assert_not_called()
示例5: test_fails_number_more_than_2
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_fails_number_more_than_2(self):
r = Mock()
r.get = Mock(return_value=1)
r.set = Mock(return_value=True)
r.zadd = Mock(return_value=True)
casino = Casino(r)
self.assertRaises(casino.escoger_juego(3))
示例6: mock_sublime_settings
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def mock_sublime_settings(dictionary):
def setter(key, value):
dictionary[key] = value
settings = Mock()
settings.get = lambda key, default_value = None: default_value if not key in dictionary else dictionary[key]
settings.set = setter
return settings
示例7: test_must_collect_errors_and_raise_on_invalid_events
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_collect_errors_and_raise_on_invalid_events(self, SamTemplateMock):
template_dict = {"a": "b"}
function_resources = [("id1", "function1"), ("id2", "function2"), ("id3", "function3")]
api_event_errors = [InvalidEventException("eventid1", "msg"), InvalidEventException("eventid3", "msg"), InvalidEventException("eventid3", "msg")]
sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.set = Mock()
sam_template.iterate = Mock()
sam_template.iterate.return_value = function_resources
self.plugin._get_api_events.return_value = ["1", "2"]
self.plugin._process_api_events.side_effect = api_event_errors
with self.assertRaises(InvalidDocumentException) as context:
self.plugin.on_before_transform_template(template_dict)
# Verify the content of exception. There are two exceptions embedded one inside another
# InvalidDocumentException -> InvalidResourceException -> contains the msg from InvalidEventException
causes = context.exception.causes
self.assertEquals(3, len(causes))
for index, cause in enumerate(causes):
self.assertTrue(isinstance(cause, InvalidResourceException))
# Resource's logicalID must be correctly passed
self.assertEquals(function_resources[index][0], cause._logical_id)
# Message must directly come from InvalidEventException
self.assertEquals(api_event_errors[index].message, cause._message)
# Must cleanup even if there an exception
self.plugin._maybe_remove_implicit_api.assert_called_with(sam_template)
示例8: test_ayadir_jugador
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_ayadir_jugador(self):
r = Mock()
r.get= Mock(return_value=1)
r.set = Mock(return_value=True)
r.zadd = Mock(return_value=True)
casino = Casino(r)
self.assertEqual(casino.ayadir_jugador("pepe", 29), True)
示例9: test_must_skip_if_api_manage_swagger_flag_is_not_present
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_must_skip_if_api_manage_swagger_flag_is_not_present(self, SwaggerEditorMock):
event_id = "id"
properties = {
"RestApiId": {"Ref": "restid"},
"Path": "/hello",
"Method": "GET"
}
original_swagger = {"this": "is a valid swagger"}
mock_api = SamResource({
"Type": "AWS::Serverless::Api",
"Properties": {
"DefinitionBody": original_swagger,
"StageName": "prod",
# __MANAGE_SWAGGER flag is *not* present
}
})
SwaggerEditorMock.is_valid = Mock()
template_mock = Mock()
template_mock.get = Mock()
template_mock.set = Mock()
template_mock.get.return_value = mock_api
self.plugin._add_api_to_swagger(event_id, properties, template_mock)
SwaggerEditorMock.is_valid.assert_called_with(original_swagger)
template_mock.get.assert_called_with('restid')
SwaggerEditorMock.assert_not_called()
template_mock.set.assert_not_called()
示例10: mc_factory
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def mc_factory(self, was_404):
"""
churn out mocked caches with a preset .get(). Also a rapper?
"""
mc = Mock()
ret = was_404
mc.get = Mock(return_value=ret)
mc.set = Mock()
return mc
示例11: test_fails_number_less_than_0
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_fails_number_less_than_0(self):
r = Mock()
r.get = Mock(return_value=1)
r.set = Mock(return_value=True)
r.zadd = Mock(return_value=True)
casino = Casino(r)
self.assertRaises(casino.ayadir_jugador("pepe", -1))
self.assertRaises(casino.escoger_juego(-1))
self.assertRaises(casino.ingresar_creditos("pepe", -1))
self.assertRaises(casino.sacar_creditos("pepe", -1))
示例12: test_fails_tupla
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_fails_tupla(self):
r = Mock()
r.get = Mock(return_value=1)
r.set = Mock(return_value=True)
r.zadd = Mock(return_value=True)
casino = Casino(r)
self.assertRaises(Exception, casino.ayadir_jugador((1, 2, 3), 2))
self.assertRaises(Exception, casino.ingresar_creditos((1, 2, 3), 2))
self.assertRaises(Exception, casino.abandonar_juego((1, 2, 3), 2))
self.assertRaises(Exception, casino.obtener_creditos_varios_jugadores((1, 2, 3), 2))
self.assertRaises(Exception, casino.obtener_creditos((1, 2)))
示例13: MockBackendMixin
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
class MockBackendMixin(object):
"""
Mocks a cache backend which is to be mixed with the Cache class.
"""
def __init__(self, *args, **kwargs):
self._cache = Mock()
def add(self, key, value, timeout=None, version=None):
self._cache.add(key, value, timeout, version=version)
def set(self, key, value, timeout=None, version=None):
self._cache.set(key, value, timeout, version=version)
def get(self, key, default=None, version=None):
val = self._cache.get(key, version=version)
if val is not None:
return val
return default
def delete(self, key, version=None):
self._cache.delete(key, version=version)
示例14: test_fails_bool
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def test_fails_bool(self):
r = Mock()
r.get = Mock(return_value=1)
r.set = Mock(return_value=True)
r.zadd = Mock(return_value=True)
casino = Casino(r)
self.assertRaises(Exception, casino.ayadir_jugador("pepe", True))
self.assertRaises(Exception, casino.sacar_creditos("pepe", True))
self.assertRaises(Exception, casino.ingresar_creditos("pepe", True))
self.assertRaises(Exception, casino.abandonar_juego("pepe", True))
self.assertRaises(Exception, casino.obtener_creditos_varios_jugadores("pepe", True))
self.assertRaises(Exception, casino.ayadir_jugador(True, "pepe"))
self.assertRaises(Exception, casino.escoger_juego(True))
self.assertRaises(Exception, casino.obtener_creditos(True))
示例15: do_init_and_set
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import set [as 别名]
def do_init_and_set(self, memcachering_mock, telnet_mock, read_until_ret_list):
tn_mock = Mock()
telnet_mock.return_value = tn_mock
read_until_mock = Mock()
def read_until_ret_func(*args, **kwargs):
return read_until_ret_list.pop(0)
read_until_mock.side_effect = read_until_ret_func
tn_mock.read_until = read_until_mock
ring_mock = Mock()
memcachering_mock.return_value = ring_mock
ring_mock.set = Mock()
endpoint = 'test.lwgyhw.cfg.usw2.cache.amazonaws.com:11211'
mc = MemcacheClient(endpoint)
mc.set('foo', 'bar')
mc.stop_timer()
ring_mock.set.assert_called_with('foo', 'bar')