Ticket #329: get_dirnode_strings.py

File get_dirnode_strings.py, 1.3 KB (added by kevan, at 2009-07-02T02:51:56Z)

a first shot at making a test program

Line 
1import sys
2
3base = "/Users/kacarstensen/Documents/code/tahoe/support/lib/python2.6/site-packages"
4sys.path.append(base)
5
6from base64 import b32encode
7from test.test_dirnode import FakeClient
8
9class TestProgram:
10    def __init__(self):
11        self.client = FakeClient()
12
13    def create_directory_tree(self):
14        d = self.client.create_empty_dirnode()
15
16        def _create_files(rootdir):
17            # Create a small directory tree
18            # root/
19            # root/file1
20            # root/file2
21            # root/file3
22            self.rootdir = rootdir
23            d = rootdir.add_file(u"file1", upload.Data(u'file1', None))
24            d.addCallback(lambda res:
25                rootdir.add_file(u'file2', upload.Data("bbbb", None)))
26            d.addCallback(lambda res:
27                rootdir.add_file(u'file3', upload.Data("bbbbc", None)))
28            return d
29
30        d.addCallback(_create_files)
31        return d
32
33    def get_string(self):
34        children = self.rootdir._read()
35        def _print_contents(contents):
36            packed_contents = self.rootdir._pack_contents(contents)
37            print packed_contents
38
39        children.addCallback(_print_contents)
40        return children
41
42    def run(self):
43        self.create_directory_tree()
44        self.get_string()
45
46p = TestProgram()
47p.run()