本文整理汇总了Python中mocker.Mocker.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.reset方法的具体用法?Python Mocker.reset怎么用?Python Mocker.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocker.Mocker
的用法示例。
在下文中一共展示了Mocker.reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDelivery
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import reset [as 别名]
class TestDelivery(TwistedTestCase):
"""More delivery testing."""
@inlineCallbacks
def setUp(self):
"""Set up test."""
yield super(TestDelivery, self).setUp()
self.mocker = Mocker()
self.fake_reactor = DummyReactor()
self.content = self.mocker.mock()
self.node_owner_id = 1
self.node_uuid = uuid.uuid4()
self.node_hash = "hash:blah"
self.owner_id = 0
self.free_bytes = 0
self.node_volume_id = uuid.uuid4()
self.content_node = self.mocker.mock()
content_class = lambda _: self.content
MetricsConnector.register_metrics("sli", instance=ExtendedMetrics())
MetricsConnector.register_metrics("root", instance=ExtendedMetrics())
MetricsConnector.register_metrics("user", instance=ExtendedMetrics())
self.factory = StorageServerFactory(
s3_host=None, s3_port=None, s3_key=None, s3_ssl=False,
s3_secret=None, content_class=content_class,
reactor=self.fake_reactor)
@inlineCallbacks
def tearDown(self):
"""Tear down test."""
MetricsConnector.unregister_metrics()
try:
self.mocker.verify()
finally:
yield super(TestDelivery, self).tearDown()
self.mocker.restore()
@inlineCallbacks
def test_new_volume_generation_ok(self):
"""Test new volume generation delivery ok."""
user = self.mocker.mock()
expect(self.content.get_user_by_id('user_id')
).count(1).result(succeed(user))
expect(user.broadcast).count(1).result(lambda *a, **kw: None)
# test
self.mocker.replay()
notif = VolumeNewGeneration('user_id', 'vol_id', 23)
yield self.factory.deliver_volume_new_generation(notif)
@inlineCallbacks
def test_new_volume_generation_not_connected(self):
"""Test new volume generation delivery for a not connected user."""
expect(self.content.get_user_by_id('user_id')
).count(1).result(succeed(None))
# test
self.mocker.replay()
notif = VolumeNewGeneration('user_id', 'vol_id', 23)
yield self.factory.deliver_volume_new_generation(notif)
@inlineCallbacks
def test_new_volume_generation_broadcasting_message(self):
"""Test new volume generation delivery with correct message."""
deferred = defer.Deferred()
protocol = self.mocker.mock()
def test(resp, filter):
"""Check that the broadcast message info is ok."""
self.assertEqual(resp.type,
protocol_pb2.Message.VOLUME_NEW_GENERATION)
self.assertEqual(resp.volume_new_generation.volume, 'vol_id')
self.assertEqual(resp.volume_new_generation.generation, 66)
# other session, and generations
self.mocker.reset()
expect(protocol.session_id).count(0, 1).result(uuid.uuid4())
expect(protocol.working_caps).count(0, 1).result(['generations'])
self.mocker.replay()
self.assertTrue(filter(protocol))
# same session, and generations
self.mocker.reset()
expect(protocol.session_id).count(0, 1).result(session_id)
expect(protocol.working_caps).count(0, 1).result(['generations'])
self.mocker.replay()
self.assertFalse(filter(protocol))
deferred.callback(None)
user = self.mocker.mock()
expect(self.content.get_user_by_id('user_id')
).count(1).result(succeed(user))
expect(user.broadcast).result(test)
# test
self.mocker.replay()
session_id = uuid.uuid4()
notif = VolumeNewGeneration('user_id', 'vol_id', 66, session_id)
yield self.factory.deliver_volume_new_generation(notif)
yield deferred
#.........这里部分代码省略.........