From b9624502c99fa9d4f9eb31e271a5a468d8341e6b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 16 Apr 2007 17:21:37 -0700 Subject: [PATCH] download: more test coverage --- src/allmydata/test/test_encode.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/allmydata/test/test_encode.py b/src/allmydata/test/test_encode.py index fcbcabca..08200e36 100644 --- a/src/allmydata/test/test_encode.py +++ b/src/allmydata/test/test_encode.py @@ -142,7 +142,11 @@ class Encode(unittest.TestCase): return d 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() data = "happy happy joy joy" * 4 e.setup(StringIO(data)) @@ -175,7 +179,7 @@ class Roundtrip(unittest.TestCase): client = None target = download.Data() fd = download.FileDownloader(client, URI, target) - for shnum in range(NUM_SHARES): + for shnum in range(AVAILABLE_SHARES): bucket = all_shareholders[shnum] fd.add_share_bucket(shnum, bucket) fd._got_all_shareholders(None) @@ -189,6 +193,14 @@ class Roundtrip(unittest.TestCase): 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): return self.send_and_recover(100) -- 2.45.2