From 4f001bedb301617d7c1f06f5c768785f136f7bce Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Thu, 7 Jun 2007 18:36:25 -0700
Subject: [PATCH] test_encode.py: further refactoring of send_and_recover

---
 src/allmydata/test/test_encode.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/allmydata/test/test_encode.py b/src/allmydata/test/test_encode.py
index c0ade44d..d108b9bf 100644
--- a/src/allmydata/test/test_encode.py
+++ b/src/allmydata/test/test_encode.py
@@ -251,10 +251,24 @@ class Roundtrip(unittest.TestCase):
                          max_segment_size=25,
                          bucket_modes={},
                          ):
+        if AVAILABLE_SHARES is None:
+            AVAILABLE_SHARES = k_and_happy_and_n[2]
+        data = make_data(datalen)
+        d = self.send(k_and_happy_and_n, AVAILABLE_SHARES,
+                      max_segment_size, bucket_modes, data)
+        # that fires with (thingA_hash, e, shareholders)
+        d.addCallback(self.recover, AVAILABLE_SHARES)
+        # that fires with newdata
+        def _downloaded(newdata):
+            self.failUnless(newdata == data)
+        d.addCallback(_downloaded)
+        return d
+
+    def send(self, k_and_happy_and_n, AVAILABLE_SHARES, max_segment_size,
+             bucket_modes, data):
         NUM_SHARES = k_and_happy_and_n[2]
         if AVAILABLE_SHARES is None:
             AVAILABLE_SHARES = NUM_SHARES
-        data = make_data(datalen)
         # force use of multiple segments
         options = {"max_segment_size": max_segment_size,
                    "needed_and_happy_and_total_shares": k_and_happy_and_n}
@@ -276,15 +290,14 @@ class Roundtrip(unittest.TestCase):
                            'fileid': "F" * 20,
                            })
         d = e.start()
-        d.addCallback(self.recover, nonkey, e, shareholders, AVAILABLE_SHARES)
-        def _downloaded(newdata):
-            self.failUnless(newdata == data)
-        d.addCallback(_downloaded)
+        def _sent(thingA_hash):
+            return (thingA_hash, e, shareholders)
+        d.addCallback(_sent)
         return d
 
-    def recover(self, thingA_hash, nonkey, e, shareholders, AVAILABLE_SHARES):
+    def recover(self, (thingA_hash, e, shareholders), AVAILABLE_SHARES):
         URI = pack_uri(storage_index="S" * 20,
-                       key=nonkey,
+                       key=e.key,
                        thingA_hash=thingA_hash,
                        needed_shares=e.required_shares,
                        total_shares=e.num_shares,
-- 
2.45.2