本文整理汇总了Python中mock.Mock.get方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.get方法的具体用法?Python Mock.get怎么用?Python Mock.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _happy_path
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def _happy_path(group, mock_zk, num_members):
completion_callback = _extract_callback(mock_zk.get_children_async)
members = []
for member_id in range(834, 834 + num_members):
znode_member_id = ActiveKazooGroup.id_to_znode(member_id)
mock_get_children_result = Mock(name="mock get children async result")
mock_get_children_result.get = Mock(return_value=[znode_member_id])
completion_callback(mock_get_children_result)
mock_zk.get_async.assert_called_with(DEFAULT_PATH + "/" + znode_member_id)
info_callback = _extract_callback(mock_zk.get_async)
member_data = "some data for member %s" % member_id
mock_get_result = Mock(name="mock get async result")
mock_get_result.get = Mock(return_value=(member_data, Mock(name="znode stat")))
info_callback(mock_get_result)
member = Membership(member_id)
members.append(member)
assert group._members[member].result() == member_data
return (frozenset(members), completion_callback)
示例2: test_queryless_all_redis
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_queryless_all_redis(self):
class MockDatastore(object):
pass
raw_data = {
'a': dict(key='a'),
'b': dict(key='b'),
'test:child': dict(key='test:child'),
}
data = dict()
for k, v in raw_data.iteritems():
data[_key(k)] = pickle.dumps(v)
redis = Mock()
redis.keys.return_value = data.keys()
redis.get = lambda k: data[k]
ds = MockDatastore()
ds.query = Mock()
ds.query.side_effect = NotImplementedError
ds.child_datastore = MockDatastore()
ds.child_datastore.serializer = pickle
ds._redis = redis
ds.get = lambda k: pickle.dumps(redis.get(k))
Model.ds = ds
models = Model.all()
expected_keys = data.keys()
actual_keys = [_key(model.key) for model in models]
assert_equals(len(expected_keys), len(actual_keys))
for key in expected_keys:
assert_true(key in actual_keys,
'{0} not among returned keys'.format(key))
示例3: test_mon_hosts
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_mon_hosts(self):
hosts = Mock()
for (name, host) in mon_hosts(('name1', 'name2.localdomain',
'name3:1.2.3.6', 'name4:localhost.localdomain')):
hosts.get(name, host)
expected = [call.get('name1', 'name1'),
call.get('name2', 'name2.localdomain'),
call.get('name3', '1.2.3.6'),
call.get('name4', 'localhost.localdomain')]
result = hosts.mock_calls
assert result == expected
示例4: test_addElementMultiCache
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_addElementMultiCache(self):
cache = Mock()
cache2 = Mock()
cache.get = Mock(return_value=None)
cache2.get = Mock(return_value="test.value")
self.cache_manager.add_cache(cache)
self.cache_manager.add_cache(cache2)
self.cache_manager.add("test.key", "test.value")
self.assertEqual(self.cache_manager.get("test.key"), "test.value")
cache.get.assert_called_with("test.key")
cache2.get.assert_called_with("test.key")
示例5: make_mock_service
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def make_mock_service(self, project_quota, region_quota):
mock_project_method = Mock()
mock_project_method.execute = Mock(return_value={'quotas': project_quota})
mock_projects = Mock()
mock_projects.get = Mock(return_value=mock_project_method)
mock_region_method = Mock()
mock_region_method.execute = Mock(return_value={'quotas': region_quota})
mock_regions = Mock()
mock_regions.get = Mock(return_value=mock_region_method)
mock_service = Mock()
mock_service.projects = Mock(return_value=mock_projects)
mock_service.regions = Mock(return_value=mock_regions)
return mock_service
示例6: test_fails_number_more_than_2
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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))
示例7: test_ayadir_jugador
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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)
示例8: test_must_skip_if_api_manage_swagger_flag_is_not_present
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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()
示例9: test_must_skip_if_api_resource_properties_are_invalid
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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()
示例10: test_stream_inversion_timestamps
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_stream_inversion_timestamps(self):
"""
Test that if stream is inverted, timestamp of last action is the
timestamp of the last action in the previous funnel step.
"""
from analysis import IdentityDict
from analysis import _stream_earliest_action
client = Mock()
client.get = Mock(side_effect=[self.get_stream5()])
start = datetime.datetime(2014,3,20)
end = datetime.datetime(2014,3,21)
step = FunnelStep('stream5', invert=True)
last_user_action = {'0': datetime_to_kronos_time(start),
'1': datetime_to_kronos_time(start)}
step_output = _stream_earliest_action(client, step,
start, end,
timedelta_to_kronos_time(
datetime.timedelta(minutes=5)),
last_user_action,
{'userId': IdentityDict()})
user_action = step_output['user_action']
self.assertEqual(len(user_action), 1)
self.assertEqual(user_action['1'], datetime_to_kronos_time(start))
示例11: test_must_skip_invalid_swagger
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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()
示例12: mock_sublime_settings
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [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
示例13: logged_in
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def logged_in(self, login='fred', travis_user=True):
""" A context manager to do stuff, while logged in as fred. """
response = Response()
response._content = json.dumps(
dict(id=12345, login=login, name='Fred')
)
data = Mock()
data.get = Mock(return_value=response)
data.access_token = GH_TOKEN
true = Mock(return_value=True)
if travis_user:
travis_patch = patch('travis_utils.is_travis_user', true)
travis_patch.start()
with patch('statiki.github', Mock(spec=OAuth2Service)) as gh:
gh.get_auth_session = Mock(return_value=data)
try:
yield self.app.get('/authorized?code="bazooka"')
finally:
if travis_user:
travis_patch.stop()
self.app.get('/logout')
示例14: test_crawl
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_crawl():
html =\
"""<html>
<head>
<title>Python is fun!</title>
</head>
<body>
<div>Python is similar to Ruby, but different.</div>
</body>
</html>"""
response_mock = Mock(url="http://expanded_url.com")
response_mock.read = Mock(return_value=html)
urllib2.urlopen = Mock(return_value=response_mock)
url = "http://a.com"
input_queue = Mock()
input_queue.get = Mock(return_value=url)
output_queue = Queue()
crawler = Crawler()
crawler.crawl(input_queue, output_queue)
expected_result = {'CONTENT': html,
'EXPANDED_URL': 'http://expanded_url.com',
'STATUS': 'OK',
'URL': 'http://a.com'}
eq_(expected_result, output_queue.get())
示例15: test_script_is_executable_generating_configuration_files
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import get [as 别名]
def test_script_is_executable_generating_configuration_files(self):
mocked_db = Mock()
mocked_db.get_all_tables_info = Mock(return_value={'tables': []})
mocked_db_factory = Mock()
mocked_db_factory.get_driver = Mock(return_value=mocked_db)
mocked_excel_writer = Mock()
mocked_excel_writer.generate_excel_file = Mock(return_value=True)
mocked_yaml_configuration = Mock()
mocked_yaml_configuration.generate_yaml_files = Mock(return_value=True)
logger = logging.getLogger('test')
logger.addHandler(logging.NullHandler())
mocked_injector = Mock()
mocked_injector.get = Mock(side_effect=[self.__get_logger(), mocked_db_factory, mocked_excel_writer, mocked_yaml_configuration])
mocked_args = self.__generate_mocked_arguments()
mocked_args.excel_only = False
Scribe(Mock()).run(mocked_args, mocked_injector)
assert mocked_excel_writer.generate_excel_file.called
assert mocked_db_factory.get_driver.called
assert mocked_yaml_configuration.generate_yaml_files.called