test: use patch() to control Tub creation
This reduces the dependency on the internals of storage_client.py
This commit is contained in:
parent
e301ac88ea
commit
e147aa3da2
|
@ -1,4 +1,4 @@
|
||||||
from mock import Mock
|
from mock import Mock, patch
|
||||||
from allmydata.util import base32
|
from allmydata.util import base32
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
@ -39,14 +39,8 @@ class TestStorageFarmBroker(unittest.TestCase):
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def test_threshold_reached(self):
|
def test_threshold_reached(self):
|
||||||
introducer = Mock()
|
introducer = Mock()
|
||||||
tub = Mock()
|
|
||||||
broker = StorageFarmBroker(True)
|
broker = StorageFarmBroker(True)
|
||||||
done = ConnectedEnough(broker, 5).when_connected_enough()
|
done = ConnectedEnough(broker, 5).when_connected_enough()
|
||||||
broker.tubs['0'] = tub
|
|
||||||
broker.tubs['1'] = tub
|
|
||||||
broker.tubs['2'] = tub
|
|
||||||
broker.tubs['3'] = tub
|
|
||||||
broker.tubs['42'] = tub
|
|
||||||
broker.use_introducer(introducer)
|
broker.use_introducer(introducer)
|
||||||
# subscribes to "storage" to learn of new storage nodes
|
# subscribes to "storage" to learn of new storage nodes
|
||||||
subscribe = introducer.mock_calls[0]
|
subscribe = introducer.mock_calls[0]
|
||||||
|
@ -62,9 +56,11 @@ class TestStorageFarmBroker(unittest.TestCase):
|
||||||
|
|
||||||
def add_one_server(x):
|
def add_one_server(x):
|
||||||
data["anonymous-storage-FURL"] = "pb://{}@nowhere/fake".format(base32.b2a(str(x)))
|
data["anonymous-storage-FURL"] = "pb://{}@nowhere/fake".format(base32.b2a(str(x)))
|
||||||
got_announcement('v0-1234-{}'.format(x), data)
|
tub = Mock()
|
||||||
self.assertEqual(tub.mock_calls[-1][0], 'connectTo')
|
with patch("allmydata.storage_client.Tub", side_effect=[tub]):
|
||||||
got_connection = tub.mock_calls[-1][1][1]
|
got_announcement('v0-1234-{}'.format(x), data)
|
||||||
|
self.assertEqual(tub.mock_calls[-1][0], 'connectTo')
|
||||||
|
got_connection = tub.mock_calls[-1][1][1]
|
||||||
rref = Mock()
|
rref = Mock()
|
||||||
rref.callRemote = Mock(return_value=succeed(1234))
|
rref.callRemote = Mock(return_value=succeed(1234))
|
||||||
got_connection(rref)
|
got_connection(rref)
|
||||||
|
|
Loading…
Reference in New Issue