tahoe-lafs/src/allmydata/test/test_no_network.py
Brian Warner 96834da0a2 Simplify immutable download API: use just filenode.read(consumer, offset, size)
* remove Downloader.download_to_data/download_to_filename/download_to_filehandle
* remove download.Data/FileName/FileHandle targets
* remove filenode.download/download_to_data/download_to_filename methods
* leave Downloader.download (the whole Downloader will go away eventually)
* add util.consumer.MemoryConsumer/download_to_data, for convenience
  (this is mostly used by unit tests, but it gets used by enough non-test
   code to warrant putting it in allmydata.util)
* update tests
* removes about 180 lines of code. Yay negative code days!

Overall plan is to rewrite immutable/download.py and leave filenode.read() as
the sole read-side API.
2009-12-01 17:53:30 -05:00

43 lines
1.1 KiB
Python

# Test the NoNetworkGrid test harness
from twisted.trial import unittest
from twisted.application import service
from allmydata.test.no_network import NoNetworkGrid
from allmydata.immutable.upload import Data
from allmydata.util.consumer import download_to_data
class Harness(unittest.TestCase):
def setUp(self):
self.s = service.MultiService()
self.s.startService()
def tearDown(self):
return self.s.stopService()
def test_create(self):
basedir = "no_network/Harness/create"
g = NoNetworkGrid(basedir)
g.startService()
return g.stopService()
def test_upload(self):
basedir = "no_network/Harness/upload"
g = NoNetworkGrid(basedir)
g.setServiceParent(self.s)
c0 = g.clients[0]
DATA = "Data to upload" * 100
data = Data(DATA, "")
d = c0.upload(data)
def _uploaded(res):
n = c0.create_node_from_uri(res.uri)
return download_to_data(n)
d.addCallback(_uploaded)
def _check(res):
self.failUnlessEqual(res, DATA)
d.addCallback(_check)
return d