]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - test/uri_utilities_test.rb
Made the output filename the responsibility of the website subclass.
[dead/whatever-dl.git] / test / uri_utilities_test.rb
1 #
2 # Copyright Michael Orlitzky
3 #
4 # http://michael.orlitzky.com/
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # http://www.fsf.org/licensing/licenses/gpl.html
17 #
18
19 require 'test/unit'
20 require 'src/uri_utilities.rb'
21
22 class UriUtilitiesTest < Test::Unit::TestCase
23
24 def test_system_call_exception_on_connection_refused
25 uu = UriUtilities.new()
26
27 # *Hopefully* this connection is refused.
28 example_uri = 'http://localhost:1/'
29 uri = URI.parse(example_uri)
30
31 assert_raise Errno::ECONNREFUSED do
32 uu.download_with_progress_bar(uri, 'dummy.tmp')
33 end
34
35 # This should be gone since there was an error.
36 assert(!File.exists?('dummy.tmp'))
37 end
38
39
40 def test_access_denied_on_unwritable_outfile
41 # Get rid of the dummy file if it already exists.
42 File.delete('dummy.tmp') if File.exists?('dummy.tmp')
43
44 File.new('dummy.tmp', 'w')
45
46 # Make the new file unwritable
47 File.chmod(0400, 'dummy.tmp')
48
49 uu = UriUtilities.new()
50
51 # *Hopefully* this connection is refused.
52 example_uri = 'http://localhost:1/'
53 uri = URI.parse(example_uri)
54
55 assert_raise Errno::EACCES do
56 uu.download_with_progress_bar(uri, 'dummy.tmp')
57 end
58
59 # This should *not* be deleted, since it was unwritable,
60 # and we got an IO error instead of an HTTP or connection
61 # error.
62 assert(File.exists?('dummy.tmp'))
63
64 # Ok, now we delete it anyway since it will mess up the other tests.
65 File.delete('dummy.tmp')
66 end
67 end