]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test/common.py: update FakeMutableFileNode to new contents= callable scheme
authorBrian Warner <warner@lothar.com>
Tue, 13 Oct 2009 05:21:54 +0000 (22:21 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 13 Oct 2009 05:21:54 +0000 (22:21 -0700)
src/allmydata/test/common.py

index 2be08878569f86e51ed7a531ae13cbab31698a96..5bc2f141a2dfef3fce1d678a3e93554a5837eb89 100644 (file)
@@ -157,13 +157,22 @@ class FakeMutableFileNode:
     def __init__(self, storage_broker, secret_holder,
                  default_encoding_parameters, history):
         self.init_from_uri(make_mutable_file_uri())
-    def create(self, initial_contents, key_generator=None, keysize=None):
+    def create(self, contents, key_generator=None, keysize=None):
+        initial_contents = self._get_initial_contents(contents)
         if len(initial_contents) > self.MUTABLE_SIZELIMIT:
             raise FileTooLargeError("SDMF is limited to one segment, and "
                                     "%d > %d" % (len(initial_contents),
                                                  self.MUTABLE_SIZELIMIT))
         self.all_contents[self.storage_index] = initial_contents
         return defer.succeed(self)
+    def _get_initial_contents(self, contents):
+        if isinstance(contents, str):
+            return contents
+        if contents is None:
+            return ""
+        assert callable(contents), "%s should be callable, not %s" % \
+               (contents, type(contents))
+        return contents(self)
     def init_from_uri(self, filecap):
         assert isinstance(filecap, str)
         if filecap.startswith("URI:SSK:"):