Ticket #939: 939tests.darcspatch.txt

File 939tests.darcspatch.txt, 19.0 KB (added by kevan, at 2010-02-12T06:30:19Z)

tests for #939 -- review this one

Line 
1Thu Feb 11 22:21:37 PST 2010  Kevan Carstensen <kevan@isnotajoke.com>
2  * Add tests for #939
3
4New patches:
5
6[Add tests for #939
7Kevan Carstensen <kevan@isnotajoke.com>**20100212062137
8 Ignore-this: 5459e8c64ba76cca70aa720e68549637
9] {
10hunk ./src/allmydata/test/test_cli.py 372
11         self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:")
12         self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir")
13         self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir/file")
14+        # calling get_alias with a path that doesn't include an alias and
15+        # default set to something that isn't in the aliases argument should
16+        # raise an UnknownAliasError.
17+        def ga4(path):
18+            return get_alias(aliases, path, "badddefault:")
19+        self.failUnlessRaises(common.UnknownAliasError, ga4, "afile")
20+        self.failUnlessRaises(common.UnknownAliasError, ga4, "a/dir/path/")
21+
22+        def ga5(path):
23+            old = common.pretend_platform_uses_lettercolon
24+            try:
25+                common.pretend_platform_uses_lettercolon = True
26+                retval = get_alias(aliases, path, "baddefault:")
27+            finally:
28+                common.pretend_platform_uses_lettercolon = old
29+            return retval
30+        self.failUnlessRaises(common.UnknownAliasError, ga5, "C:\\Windows")
31 
32 
33 class Help(unittest.TestCase):
34hunk ./src/allmydata/test/test_cli.py 594
35 
36         return d
37 
38+
39+class Ln(GridTestMixin, CLITestMixin, unittest.TestCase):
40+    def _create_test_file(self):
41+        data = "puppies" * 1000
42+        path = os.path.join(self.basedir, "datafile")
43+        f = open(path, 'wb')
44+        f.write(data)
45+        f.close()
46+        self.datafile = path
47+
48+    def test_ln_without_alias(self):
49+        # if invoked without an alias when the 'tahoe' alias doesn't
50+        # exist, 'tahoe ln' should output a useful error message and not
51+        # a stack trace
52+        self.basedir = "cli/Ln/ln_without_alias"
53+        self.set_up_grid()
54+        d = self.do_cli("ln", "from", "to")
55+        def _check((rc, out, err)):
56+            self.failUnlessEqual(rc, 1)
57+            self.failUnlessIn("error:", err)
58+        d.addCallback(_check)
59+        # Make sure that validation extends to the "to" parameter
60+        d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
61+        d.addCallback(lambda ign: self._create_test_file())
62+        d.addCallback(lambda ign: self.do_cli("put", self.datafile,
63+                                              "havasu:from"))
64+        d.addCallback(lambda ign: self.do_cli("ln", "havasu:from", "to"))
65+        d.addCallback(_check)
66+        return d
67+
68+    def test_ln_with_nonexistent_alias(self):
69+        # If invoked with aliases that don't exist, 'tahoe ln' should
70+        # output a useful error message and not a stack trace.
71+        self.basedir = "cli/Ln/ln_with_nonexistent_alias"
72+        self.set_up_grid()
73+        d = self.do_cli("ln", "havasu:from", "havasu:to")
74+        def _check((rc, out, err)):
75+            self.failUnlessEqual(rc, 1)
76+            self.failUnlessIn("error:", err)
77+        d.addCallback(_check)
78+        # Make sure that validation occurs on the to parameter if the
79+        # from parameter passes.
80+        d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
81+        d.addCallback(lambda ign: self._create_test_file())
82+        d.addCallback(lambda ign: self.do_cli("put", self.datafile,
83+                                              "havasu:from"))
84+        d.addCallback(lambda ign: self.do_cli("ln", "havasu:from", "huron:to"))
85+        d.addCallback(_check)
86+        return d
87+
88+
89 class Put(GridTestMixin, CLITestMixin, unittest.TestCase):
90 
91     def test_unlinked_immutable_stdin(self):
92hunk ./src/allmydata/test/test_cli.py 862
93         d.addCallback(lambda (rc,out,err): self.failUnlessEqual(out, DATA2))
94         return d
95 
96+    def test_put_with_nonexistent_alias(self):
97+        # when invoked with an alias that doesn't exist, 'tahoe put'
98+        # should output a useful error message, not a stack trace
99+        self.basedir = "cli/Put/put_with_nonexistent_alias"
100+        self.set_up_grid()
101+        d = self.do_cli("put", "somefile", "fake:afile")
102+        def _check((rc, out, err)):
103+            self.failUnlessEqual(rc, 1)
104+            self.failUnlessIn("error:", err)
105+        d.addCallback(_check)
106+        return d
107+
108+
109 class List(GridTestMixin, CLITestMixin, unittest.TestCase):
110     def test_list(self):
111         self.basedir = "cli/List/list"
112hunk ./src/allmydata/test/test_cli.py 939
113         d.addCallback(_check5)
114         return d
115 
116+    def test_list_without_alias(self):
117+        # doing just 'tahoe ls' without specifying an alias or first
118+        # doing 'tahoe create-alias tahoe' should fail gracefully.
119+        self.basedir = "cli/List/list_without_alias"
120+        self.set_up_grid()
121+        d = self.do_cli("ls")
122+        def _check((rc, out, err)):
123+            self.failUnlessEqual(rc, 1)
124+            self.failUnlessIn("error:", err)
125+        d.addCallback(_check)
126+        return d
127+
128+    def test_list_with_nonexistent_alias(self):
129+        # doing 'tahoe ls' while specifying an alias that doesn't already
130+        # exist should fail with an informative error message
131+        self.basedir = "cli/List/list_with_nonexistent_alias"
132+        self.set_up_grid()
133+        d = self.do_cli("ls", "nonexistent:")
134+        def _check((rc, out, err)):
135+            self.failUnlessEqual(rc, 1)
136+            self.failUnlessIn("error:", err)
137+            self.failUnlessIn("nonexistent", err)
138+        d.addCallback(_check)
139+        return d
140+
141+
142 class Mv(GridTestMixin, CLITestMixin, unittest.TestCase):
143     def test_mv_behavior(self):
144         self.basedir = "cli/Mv/mv_behavior"
145hunk ./src/allmydata/test/test_cli.py 1060
146                               "mv moved the wrong thing"))
147         return d
148 
149+    def test_mv_without_alias(self):
150+        # doing 'tahoe mv' without explicitly specifying an alias or
151+        # creating the default 'tahoe' alias should fail with a useful
152+        # error message.
153+        self.basedir = "cli/Mv/mv_without_alias"
154+        self.set_up_grid()
155+        d = self.do_cli("mv", "afile", "anotherfile")
156+        def _check((rc, out, err)):
157+            self.failUnlessEqual(rc, 1)
158+            self.failUnlessIn("error:", err)
159+        d.addCallback(_check)
160+        # check to see that the validation extends to the
161+        # target argument by making an alias that will work with the first
162+        # one.
163+        d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
164+        def _create_a_test_file(ign):
165+            self.test_file_path = os.path.join(self.basedir, "afile")
166+            f = open(self.test_file_path, "wb")
167+            f.write("puppies" * 100)
168+            f.close()
169+        d.addCallback(_create_a_test_file)
170+        d.addCallback(lambda ign: self.do_cli("put", self.test_file_path,
171+                                              "havasu:afile"))
172+        d.addCallback(lambda ign: self.do_cli("mv", "havasu:afile",
173+                                              "anotherfile"))
174+        d.addCallback(_check)
175+        return d
176+
177+    def test_mv_with_nonexistent_alias(self):
178+        # doing 'tahoe mv' with an alias that doesn't exist should fail
179+        # with an informative error message.
180+        self.basedir = "cli/Mv/mv_with_nonexistent_alias"
181+        self.set_up_grid()
182+        d = self.do_cli("mv", "fake:afile", "fake:anotherfile")
183+        def _check((rc, out, err)):
184+            self.failUnlessEqual(rc, 1)
185+            self.failUnlessIn("error:", err)
186+            self.failUnlessIn("fake", err)
187+        d.addCallback(_check)
188+        # check to see that the validation extends to the
189+        # target argument by making an alias that will work with the first
190+        # one.
191+        d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
192+        def _create_a_test_file(ign):
193+            self.test_file_path = os.path.join(self.basedir, "afile")
194+            f = open(self.test_file_path, "wb")
195+            f.write("puppies" * 100)
196+            f.close()
197+        d.addCallback(_create_a_test_file)
198+        d.addCallback(lambda ign: self.do_cli("put", self.test_file_path,
199+                                              "havasu:afile"))
200+        d.addCallback(lambda ign: self.do_cli("mv", "havasu:afile",
201+                                              "fake:anotherfile"))
202+        d.addCallback(_check)
203+        return d
204+
205+
206 class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
207 
208     def test_not_enough_args(self):
209hunk ./src/allmydata/test/test_cli.py 1229
210         d.addCallback(_get_resp2)
211         return d
212 
213+    def test_cp_with_nonexistent_alias(self):
214+        # when invoked with an alias or aliases that don't exist, 'tahoe cp'
215+        # should output a sensible error message rather than a stack trace.
216+        self.basedir = "cli/Cp/cp_with_nonexistent_alias"
217+        self.set_up_grid()
218+        d = self.do_cli("cp", "fake:file1", "fake:file2")
219+        def _check((rc, out, err)):
220+            self.failUnlessEqual(rc, 1)
221+            self.failUnlessIn("error:", err)
222+        d.addCallback(_check)
223+        # 'tahoe cp' actually processes the target argument first, so we
224+        # need to check to make sure that validation extends to the
225+        # source argument.
226+        d.addCallback(lambda ign: self.do_cli("create-alias", "tahoe"))
227+        d.addCallback(lambda ign: self.do_cli("cp", "fake:file1",
228+                                              "tahoe:file2"))
229+        d.addCallback(_check)
230+        return d
231+
232+
233 class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
234 
235     def writeto(self, path, data):
236hunk ./src/allmydata/test/test_cli.py 1655
237         d.addErrback(_cleanup)
238         return d
239 
240+    def test_backup_without_alias(self):
241+        # 'tahoe backup' should output a sensible error message when invoked
242+        # without an alias instead of a stack trace.
243+        self.basedir = os.path.dirname(self.mktemp())
244+        self.set_up_grid()
245+        source = os.path.join(self.basedir, "file1")
246+        d = self.do_cli('backup', source, source)
247+        def _check((rc, out, err)):
248+            self.failUnlessEqual(rc, 1)
249+            self.failUnlessIn("error:", err)
250+        d.addCallback(_check)
251+        return d
252+
253+    def test_backup_with_nonexistent_alias(self):
254+        # 'tahoe backup' should output a sensible error message when invoked
255+        # with a nonexistent alias.
256+        self.basedir = os.path.dirname(self.mktemp())
257+        self.set_up_grid()
258+        source = os.path.join(self.basedir, "file1")
259+        d = self.do_cli("backup", source, "nonexistent:" + source)
260+        def _check((rc, out, err)):
261+            self.failUnlessEqual(rc, 1)
262+            self.failUnlessIn("error:", err)
263+            self.failUnlessIn("nonexistent", err)
264+        d.addCallback(_check)
265+        return d
266+
267 
268 class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
269 
270hunk ./src/allmydata/test/test_cli.py 1976
271 
272         return d
273 
274+    def test_check_without_alias(self):
275+        # 'tahoe check' should output a sensible error message if it needs to
276+        # find the default alias and can't
277+        self.basedir = "cli/Check/check_without_alias"
278+        self.set_up_grid()
279+        d = self.do_cli("check")
280+        def _check((rc, out, err)):
281+            self.failUnlessEqual(rc, 1)
282+            self.failUnlessIn("error:", err)
283+        d.addCallback(_check)
284+        d.addCallback(lambda ign: self.do_cli("deep-check"))
285+        d.addCallback(_check)
286+        return d
287+
288+    def test_check_with_nonexistent_alias(self):
289+        # 'tahoe check' should output a sensible error message if it needs to
290+        # find an alias and can't.
291+        self.basedir = "cli/Check/check_with_nonexistent_alias"
292+        self.set_up_grid()
293+        d = self.do_cli("check", "nonexistent:")
294+        def _check((rc, out, err)):
295+            self.failUnlessEqual(rc, 1)
296+            self.failUnlessIn("error:", err)
297+            self.failUnlessIn("nonexistent", err)
298+        d.addCallback(_check)
299+        return d
300+
301+
302 class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
303     def test_get(self):
304         self.basedir = "cli/Errors/get"
305hunk ./src/allmydata/test/test_cli.py 2037
306 
307         return d
308 
309+
310+class Get(GridTestMixin, CLITestMixin, unittest.TestCase):
311+    def test_get_without_alias(self):
312+        # 'tahoe get' should output a useful error message when invoked
313+        # without an explicit alias and when the default 'tahoe' alias
314+        # hasn't been created yet.
315+        self.basedir = "cli/Get/get_without_alias"
316+        self.set_up_grid()
317+        d = self.do_cli('get', 'file')
318+        def _check((rc, out, err)):
319+            self.failUnlessEqual(rc, 1)
320+            self.failUnlessIn("error:", err)
321+        d.addCallback(_check)
322+        return d
323+
324+    def test_get_with_nonexistent_alias(self):
325+        # 'tahoe get' should output a useful error message when invoked with
326+        # an explicit alias that doesn't exist.
327+        self.basedir = "cli/Get/get_with_nonexistent_alias"
328+        self.set_up_grid()
329+        d = self.do_cli("get", "nonexistent:file")
330+        def _check((rc, out, err)):
331+            self.failUnlessEqual(rc, 1)
332+            self.failUnlessIn("error:", err)
333+            self.failUnlessIn("nonexistent", err)
334+        d.addCallback(_check)
335+        return d
336+
337+
338+class Manifest(GridTestMixin, CLITestMixin, unittest.TestCase):
339+    def test_manifest_without_alias(self):
340+        # 'tahoe manifest' should output a useful error message when invoked
341+        # without an explicit alias when the default 'tahoe' alias is
342+        # missing.
343+        self.basedir = "cli/Manifest/manifest_without_alias"
344+        self.set_up_grid()
345+        d = self.do_cli("manifest")
346+        def _check((rc, out, err)):
347+            self.failUnlessEqual(rc, 1)
348+            self.failUnlessIn("error:", err)
349+        d.addCallback(_check)
350+        return d
351+
352+    def test_manifest_with_nonexistent_alias(self):
353+        # 'tahoe manifest' should output a useful error message when invoked
354+        # with an explicit alias that doesn't exist.
355+        self.basedir = "cli/Manifest/manifest_with_nonexistent_alias"
356+        self.set_up_grid()
357+        d = self.do_cli("manifest", "nonexistent:")
358+        def _check((rc, out, err)):
359+            self.failUnlessEqual(rc, 1)
360+            self.failUnlessIn("error:", err)
361+            self.failUnlessIn("nonexistent", err)
362+        d.addCallback(_check)
363+        return d
364+
365+
366+class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
367+    def test_mkdir_with_nonexistent_alias(self):
368+        # when invoked with an alias that doesn't exist, 'tahoe mkdir'
369+        # should output a sensible error message rather than a stack
370+        # trace.
371+        self.basedir = "cli/Mkdir/mkdir_with_nonexistent_alias"
372+        self.set_up_grid()
373+        d = self.do_cli("mkdir", "havasu:")
374+        def _check((rc, out, err)):
375+            self.failUnlessEqual(rc, 1)
376+            self.failUnlessIn("error:", err)
377+        d.addCallback(_check)
378+        return d
379+
380+
381+class Rm(GridTestMixin, CLITestMixin, unittest.TestCase):
382+    def test_rm_without_alias(self):
383+        # 'tahoe rm' should behave sensibly when invoked without an explicit
384+        # alias before the default 'tahoe' alias has been created.
385+        self.basedir = "cli/Rm/rm_without_alias"
386+        self.set_up_grid()
387+        d = self.do_cli("rm", "afile")
388+        def _check((rc, out, err)):
389+            self.failUnlessIn("error:", err)
390+            self.failUnlessEqual(rc, 1)
391+        d.addCallback(_check)
392+        return d
393+
394+    def test_rm_with_nonexistent_alias(self):
395+        # 'tahoe rm' should behave sensibly when invoked with an explicit
396+        # alias that doesn't exist.
397+        self.basedir = "cli/Rm/rm_with_nonexistent_alias"
398+        self.set_up_grid()
399+        d = self.do_cli("rm", "nonexistent:afile")
400+        def _check((rc, out, err)):
401+            self.failUnlessEqual(rc, 1)
402+            self.failUnlessIn("error:", err)
403+            self.failUnlessIn("nonexistent", err)
404+        d.addCallback(_check)
405+        return d
406+
407+
408 class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
409     def test_empty_directory(self):
410         self.basedir = "cli/Stats/empty_directory"
411hunk ./src/allmydata/test/test_cli.py 2163
412         d.addCallback(_check_stats)
413 
414         return d
415+
416+    def test_stats_without_alias(self):
417+        # when invoked with no explicit alias and before the default 'tahoe'
418+        # alias is created, 'tahoe stats' should output an informative error
419+        # message, not a stack trace.
420+        self.basedir = "cli/Stats/stats_without_alias"
421+        self.set_up_grid()
422+        d = self.do_cli("stats")
423+        def _check((rc, out, err)):
424+            self.failUnlessEqual(rc, 1)
425+            self.failUnlessIn("error:", err)
426+        d.addCallback(_check)
427+        return d
428+
429+    def test_stats_with_nonexistent_alias(self):
430+        # when invoked with an explicit alias that doesn't exist,
431+        # 'tahoe stats' should output a useful error message.
432+        self.basedir = "cli/Stats/stats_with_nonexistent_alias"
433+        self.set_up_grid()
434+        d = self.do_cli("stats", "havasu:")
435+        def _check((rc, out, err)):
436+            self.failUnlessEqual(rc, 1)
437+            self.failUnlessIn("error:", err)
438+        d.addCallback(_check)
439+        return d
440+
441+
442+class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
443+    def test_webopen_with_nonexistent_alias(self):
444+        # when invoked with an alias that doesn't exist, 'tahoe webopen'
445+        # should output an informative error message instead of a stack
446+        # trace.
447+        self.basedir = "cli/Webopen/webopen_with_nonexistent_alias"
448+        self.set_up_grid()
449+        d = self.do_cli("webopen", "fake:")
450+        def _check((rc, out, err)):
451+            self.failUnlessEqual(rc, 1)
452+            self.failUnlessIn("error:", err)
453+        d.addCallback(_check)
454+        return d
455}
456
457Context:
458
459[adding pycrypto to the auto dependencies
460secorp@allmydata.com**20100206054314
461 Ignore-this: b873fc00a6a5b001d30d479e6053cf2f
462]
463[docs running.html - "tahoe run ." does not work with the current installation, replaced with "tahoe start ."
464secorp@allmydata.com**20100206165320
465 Ignore-this: fdb2dcb0e417d303cd43b1951a4f8c03
466]
467[code coverage: replace figleaf with coverage.py, should work on py2.6 now.
468Brian Warner <warner@lothar.com>**20100203165421
469 Ignore-this: 46ab590360be6a385cb4fc4e68b6b42c
470 
471 It still lacks the right HTML report (the builtin report is very pretty, but
472 lacks the "lines uncovered" numbers that I want), and the half-finished
473 delta-from-last-run measurements.
474]
475[More comprehensive changes and ticket references for NEWS
476david-sarah@jacaranda.org**20100202061256
477 Ignore-this: 696cf0106e8a7fd388afc5b55fba8a1b
478]
479[docs: install.html: link into Python 2.5.5 download page
480zooko@zooko.com**20100202065852
481 Ignore-this: 1a9471b8175b7de5741d8445a7ede29d
482]
483[TAG allmydata-tahoe-1.6.0
484zooko@zooko.com**20100202061125
485 Ignore-this: dee6ade7ac1452cf5d1d9c69a8146d84
486]
487Patch bundle hash:
4883436934a7272219efe32924ef2f22168b8eb8264