download: more test coverage

This commit is contained in:
Brian Warner 2007-04-16 17:21:37 -07:00
parent 6bdabd2cea
commit b9624502c9

View File

@ -142,7 +142,11 @@ class Encode(unittest.TestCase):
return d return d
class Roundtrip(unittest.TestCase): class Roundtrip(unittest.TestCase):
def send_and_recover(self, NUM_SHARES, NUM_SEGMENTS=4, bucket_modes={}): def send_and_recover(self, NUM_SHARES, NUM_SEGMENTS=4,
AVAILABLE_SHARES=None,
bucket_modes={}):
if AVAILABLE_SHARES is None:
AVAILABLE_SHARES = NUM_SHARES
e = encode.Encoder() e = encode.Encoder()
data = "happy happy joy joy" * 4 data = "happy happy joy joy" * 4
e.setup(StringIO(data)) e.setup(StringIO(data))
@ -175,7 +179,7 @@ class Roundtrip(unittest.TestCase):
client = None client = None
target = download.Data() target = download.Data()
fd = download.FileDownloader(client, URI, target) fd = download.FileDownloader(client, URI, target)
for shnum in range(NUM_SHARES): for shnum in range(AVAILABLE_SHARES):
bucket = all_shareholders[shnum] bucket = all_shareholders[shnum]
fd.add_share_bucket(shnum, bucket) fd.add_share_bucket(shnum, bucket)
fd._got_all_shareholders(None) fd._got_all_shareholders(None)
@ -189,6 +193,14 @@ class Roundtrip(unittest.TestCase):
return d return d
def test_not_enough_shares(self):
d = self.send_and_recover(100, AVAILABLE_SHARES=10)
def _done(res):
self.failUnless(isinstance(res, Failure))
self.failUnless(res.check(download.NotEnoughPeersError))
d.addBoth(_done)
return d
def test_one_share_per_peer(self): def test_one_share_per_peer(self):
return self.send_and_recover(100) return self.send_and_recover(100)