]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_cli.py
1b4375ef4b99af9b092350b11543d895154897d6
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_cli.py
1
2 from twisted.trial import unittest
3
4 from allmydata.util import fileutil
5 from allmydata import uri
6
7 # at least import the CLI scripts, even if we don't have any real tests for
8 # them yet.
9
10 from allmydata.scripts import cli, tahoe_ls, tahoe_get, tahoe_put, tahoe_rm
11 _hush_pyflakes = [tahoe_ls, tahoe_get, tahoe_put, tahoe_rm]
12
13
14 class CLI(unittest.TestCase):
15     def test_options(self):
16         fileutil.rm_dir("cli/test_options")
17         fileutil.make_dirs("cli/test_options")
18         open("cli/test_options/node.url","w").write("http://localhost:8080/\n")
19         #private_uri = uri.DirnodeURI("furl", "key").to_string()
20         filenode_uri = uri.WriteableSSKFileURI(writekey="\x00"*16,
21                                                fingerprint="\x00"*32)
22         private_uri = uri.NewDirectoryURI(filenode_uri).to_string()
23         open("cli/test_options/my_private_dir.cap", "w").write(private_uri + "\n")
24         o = cli.ListOptions()
25         o.parseOptions(["--node-directory", "cli/test_options"])
26         self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
27         self.failUnlessEqual(o['root-uri'], private_uri)
28         self.failUnlessEqual(o['vdrive_pathname'], "")
29
30         o = cli.ListOptions()
31         o.parseOptions(["--node-directory", "cli/test_options",
32                         "--node-url", "http://example.org:8111/"])
33         self.failUnlessEqual(o['node-url'], "http://example.org:8111/")
34         self.failUnlessEqual(o['root-uri'], private_uri)
35         self.failUnlessEqual(o['vdrive_pathname'], "")
36
37         o = cli.ListOptions()
38         o.parseOptions(["--node-directory", "cli/test_options",
39                         "--root-uri", "private"])
40         self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
41         self.failUnlessEqual(o['root-uri'], private_uri)
42         self.failUnlessEqual(o['vdrive_pathname'], "")
43
44         o = cli.ListOptions()
45         o.parseOptions(["--node-directory", "cli/test_options"])
46         self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
47         self.failUnlessEqual(o['vdrive_pathname'], "")
48
49         o = cli.ListOptions()
50         other_filenode_uri = uri.WriteableSSKFileURI(writekey="\x11"*16,
51                                                      fingerprint="\x11"*32)
52         other_uri = uri.NewDirectoryURI(other_filenode_uri).to_string()
53         o.parseOptions(["--node-directory", "cli/test_options",
54                         "--root-uri", other_uri])
55         self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
56         self.failUnlessEqual(o['root-uri'], other_uri)
57         self.failUnlessEqual(o['vdrive_pathname'], "")
58
59         o = cli.ListOptions()
60         o.parseOptions(["--node-directory", "cli/test_options",
61                         "--root-uri", other_uri, "subdir"])
62         self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
63         self.failUnlessEqual(o['root-uri'], other_uri)
64         self.failUnlessEqual(o['vdrive_pathname'], "subdir")