davclient 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,53 @@
1
+ DavClient (davclient and the dav utility) is copyrighted free software by Thomas Flemming
2
+ <thomas dot flemming at usit dot uio do no> and contributors. You can redistribute it
3
+ and/or modify it under either the terms of the GPL2 or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise make them
13
+ Freely Available, such as by posting said modifications to Usenet or an
14
+ equivalent medium, or by allowing the author to include your
15
+ modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict with
21
+ standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent) on where
30
+ to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of the
33
+ software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ 5. The scripts and library files supplied as input to or produced as
45
+ output from the software do not automatically fall under the
46
+ copyright of the software, but belong to whomever generated them,
47
+ and may be sold commercially, and may be aggregated with this
48
+ software.
49
+
50
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
51
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
52
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53
+ PURPOSE.
data/Manifest ADDED
@@ -0,0 +1,31 @@
1
+ LICENSE
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ bin/dav
6
+ davclient.gemspec
7
+ examples/remove_ds_store.rb
8
+ examples/simple_find.rb
9
+ lib/davclient.rb
10
+ lib/davclient/curl_commands.rb
11
+ lib/davclient/dav-ls.rb
12
+ lib/davclient/dav-propfind.rb
13
+ lib/davclient/dav-put.rb
14
+ lib/davclient/davcli.rb
15
+ lib/davclient/hpricot_extensions.rb
16
+ lib/davclient/simple.rb
17
+ tests/dav.rb
18
+ tests/tc_dav-cat.rb
19
+ tests/tc_dav-cd.rb
20
+ tests/tc_dav-cp.rb
21
+ tests/tc_dav-delete.rb
22
+ tests/tc_dav-get.rb
23
+ tests/tc_dav-ls.rb
24
+ tests/tc_dav-mkcol.rb
25
+ tests/tc_dav-mv.rb
26
+ tests/tc_dav-propfind.rb
27
+ tests/tc_dav-put.rb
28
+ tests/tc_webdav_basic.rb
29
+ tests/tc_webdav_publish.rb
30
+ tests/test_helper.rb
31
+ tests/ts_davclient.rb
data/README.rdoc CHANGED
@@ -5,9 +5,7 @@
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- A scriptable WebDAV command line client for
9
-
10
- WebDAV command line client written in Ruby for managing content on
8
+ A scriptable WebDAV command line client for Ruby for managing content on
11
9
  webservers that support the WebDAV extensions.
12
10
 
13
11
  This is still very much work in progress. Especially the command line interface
@@ -43,30 +41,71 @@ on how to add username etc. to the '~/.netrc' file.
43
41
 
44
42
  == COMMAND LINE SYNOPSIS:
45
43
 
46
- >dav cd http://test.webdav.org/dav/
44
+ bash $ dav cd http://test.webdav.org/dav/
47
45
  http://test.webdav.org/dav/
48
- >dav ls
46
+ bash $ dav ls
49
47
  images/
50
48
  index.html
51
- >dav pwd
49
+ bash $ dav pwd
52
50
  http://test.webdav.org/dav/
51
+ bash $ get ./index.html
52
+ bash $ dav --help
53
+ usage: dav COMMAND [ARGS]
54
+
55
+ Available dav commands:
56
+ ls List files on webdav server
57
+ pwd Print current working url
58
+ cd Change current working url
59
+ cp Copy resource
60
+ mv Move resource
61
+ rm Remove resource
62
+ cat Print content of resource
63
+ mkdir Create remote collection (directory) (mkcol alias)
64
+ get Download resource
65
+ put Upload local file
66
+ propfind Print webdav properties for url
67
+ mkcol Make collection
68
+ options Display webservers WebDAV options
69
+ edit Edit contents of remote file with editor
70
+
71
+ == USE WITH IRB:
72
+
73
+ IRB can also be used as an interactive dav console:
74
+
75
+ bash $ irb -rubygems -rdavclient/simple
76
+ >> cd "https://webdav.org/projects/"
77
+ => "https://webdav.org/projects/"
78
+ >> pwd
79
+ => "https://webdav.org/projects/"
80
+ >> content = get "index.html"
81
+ => "index.html"
82
+ >> ls
83
+ index.html
84
+ >> cd ".."
85
+ => "https://webdav.org/"
86
+
53
87
 
54
88
  == INSTALL:
55
89
 
90
+ If you can type the command 'curl' in your terminal window, everything is ok.
91
+
92
+ DavClient uses the command line utility cURL to interact with servers.
93
+ Curl comes preinstalled on Mac OS X. It can also be downloaded from
94
+ http://curl.haxx.se/ . If you are using debian or ubuntu, it
95
+ can be installed with apt-get:
96
+
97
+ sudo apt-get install curl
98
+
99
+ Then install DavClient:
100
+
56
101
  [sudo] gem install davclient
57
102
 
58
103
  or
59
104
 
60
105
  git clone git://github.com/thomasfl/davclient.git
61
106
  cd davclient
62
- gem build Rakefile
63
- sudo gem install davclient-x.x.x.gem
107
+ sudo rake install
64
108
 
65
- Curl comes preinstalled on Mac OS X. It can be downloaded from
66
- http://curl.haxx.se/ . If you are using debian or ubuntu, it
67
- can be installed by:
68
-
69
- sudo apt-get install curl
70
109
 
71
110
  == Background:
72
111
 
data/Rakefile ADDED
@@ -0,0 +1,94 @@
1
+ # Rakefile for DavClient -*- ruby -*-
2
+ # Usage:
3
+ #
4
+ # rake package Create gem
5
+ # rake rdoc Create doc
6
+ # rake upload-docs Upload docs to rubyforge
7
+ #
8
+ # rake install Create and install gem
9
+ # rake manifest Create manifest
10
+ # rake release Release to rubyforge
11
+
12
+ require 'rake/rdoctask'
13
+ require 'rake/gempackagetask'
14
+
15
+ GEM_VERSION = "0.0.6"
16
+
17
+ spec = Gem::Specification.new do |s|
18
+ s.name = "davclient"
19
+ s.version = GEM_VERSION
20
+ s.author = "Thomas Flemming"
21
+ s.email = "thomasfl@usit.uio.no"
22
+ s.homepage = "http://folk.uio.no/thomasfl"
23
+ s.platform = Gem::Platform::RUBY
24
+ s.summary = "Command line WebDAV client and Ruby library."
25
+ s.description = "WebDAV command line client written in Ruby for managing " +
26
+ "content on webservers that support the WebDAV extensions."
27
+ s.requirements << "cURL command line tool available from http://curl.haxx.se/"
28
+ s.requirements << "Servername, username and password must be supplied in ~/.netrc file."
29
+ s.files = ["lib/davclient.rb","lib/davclient/hpricot_extensions.rb",
30
+ "lib/davclient/curl_commands.rb", "bin/dav", "lib/davclient/davcli.rb",
31
+ "lib/davclient/dav-put.rb", "lib/davclient/dav-ls.rb",
32
+ "lib/davclient/dav-propfind.rb"]
33
+ s.executables = ["dav"]
34
+ s.require_path = "lib"
35
+ s.rubyforge_project = "davclient"
36
+ # s.test_files = FileList["{test}/**/*test.rb"].to_a
37
+ s.has_rdoc = true
38
+ s.extra_rdoc_files = ["README.rdoc"]
39
+ s.add_dependency("hpricot", ">= 0.6")
40
+ s.add_dependency("ZenTest", ">= 3.5") # For tests
41
+ end
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.need_zip = false
45
+ pkg.need_tar = false
46
+ end
47
+
48
+
49
+ html_dir = 'doc/html'
50
+ library = 'Ruby DavClient'
51
+ Rake::RDocTask.new('rdoc') do |t|
52
+ t.rdoc_files.include('README.rdoc',
53
+ 'lib/davclient.rb',
54
+ 'lib/davclient/hpricot_extensions.rb',
55
+ 'lib/davclient/simple.rb')
56
+ t.main = 'README.rdoc'
57
+ t.title = "#{library} API documentation"
58
+ t.rdoc_dir = html_dir
59
+ end
60
+
61
+ rubyforge_user = 'thomasfl'
62
+ rubyforge_project = 'davclient'
63
+ rubyforge_path = "/var/www/gforge-projects/#{rubyforge_project}/"
64
+ desc 'Upload documentation to RubyForge.'
65
+ task 'upload-docs' => ['rdoc'] do
66
+ sh "scp -r #{html_dir}/* " +
67
+ "#{rubyforge_user}@rubyforge.org:#{rubyforge_path}"
68
+ end
69
+
70
+
71
+ website_dir = 'site'
72
+ desc 'Update project website to RubyForge.'
73
+ task 'upload-site' do
74
+ sh "scp -r #{website_dir}/* " +
75
+ "#{rubyforge_user}@rubyforge.org:/var/www/gforge-projects/project/"
76
+ end
77
+
78
+ desc 'Update API docs and project website to RubyForge.'
79
+ task 'publish' => ['upload-docs', 'upload-site']
80
+
81
+
82
+
83
+ require 'echoe'
84
+
85
+ Echoe.new('davclient', GEM_VERSION) do |p|
86
+ p.description = "Command line WebDAV client and Ruby library."
87
+ p.url = "http://davclient.rubyforge.org/davclient"
88
+ p.author = "Thomas Flemming"
89
+ p.email = "thomasfl@usit.uio.no"
90
+ p.ignore_pattern = ["svn_user.yml", "svn_project.rake"]
91
+ p.project = "davclient"
92
+ end
93
+
94
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/davclient.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{davclient}
5
+ s.version = "0.0.6"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Thomas Flemming"]
9
+ s.date = %q{2009-09-22}
10
+ s.default_executable = %q{dav}
11
+ s.description = %q{Command line WebDAV client and Ruby library.}
12
+ s.email = %q{thomasfl@usit.uio.no}
13
+ s.executables = ["dav"]
14
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc", "bin/dav", "lib/davclient.rb", "lib/davclient/curl_commands.rb", "lib/davclient/dav-ls.rb", "lib/davclient/dav-propfind.rb", "lib/davclient/dav-put.rb", "lib/davclient/davcli.rb", "lib/davclient/hpricot_extensions.rb", "lib/davclient/simple.rb"]
15
+ s.files = ["LICENSE", "Manifest", "README.rdoc", "Rakefile", "bin/dav", "davclient.gemspec", "examples/remove_ds_store.rb", "examples/simple_find.rb", "lib/davclient.rb", "lib/davclient/curl_commands.rb", "lib/davclient/dav-ls.rb", "lib/davclient/dav-propfind.rb", "lib/davclient/dav-put.rb", "lib/davclient/davcli.rb", "lib/davclient/hpricot_extensions.rb", "lib/davclient/simple.rb", "tests/dav.rb", "tests/tc_dav-cat.rb", "tests/tc_dav-cd.rb", "tests/tc_dav-cp.rb", "tests/tc_dav-delete.rb", "tests/tc_dav-get.rb", "tests/tc_dav-ls.rb", "tests/tc_dav-mkcol.rb", "tests/tc_dav-mv.rb", "tests/tc_dav-propfind.rb", "tests/tc_dav-put.rb", "tests/tc_webdav_basic.rb", "tests/tc_webdav_publish.rb", "tests/test_helper.rb", "tests/ts_davclient.rb"]
16
+ s.homepage = %q{http://davclient.rubyforge.org/davclient}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Davclient", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{davclient}
20
+ s.rubygems_version = %q{1.3.5}
21
+ s.summary = %q{Command line WebDAV client and Ruby library.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'davclient'
4
+
5
+ # Remove all resources (files) named ".DS_Store"
6
+
7
+ url = ARGV[0]
8
+
9
+ WebDAV.find(url, :recursive => true ) do | item |
10
+ puts item.href if(item.isCollection?)
11
+ if(item.basename == ".DS_Store")
12
+ puts "Removing: " + item.href
13
+ WebDAV.delete(item.href)
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'davclient/simple'
3
+
4
+ # Simply print the url of all files and collections on server
5
+
6
+ cd "https://vortex-dav.uio.no/brukere/thomasfl/"
7
+
8
+ find do |item|
9
+ puts item.href
10
+ end
@@ -6,8 +6,6 @@ require 'hpricot'
6
6
  # Extensions to the Hpricot XML parser.
7
7
  module Hpricot
8
8
 
9
-
10
-
11
9
  class Elem
12
10
 
13
11
  # Makes properties available as simple method calls.
@@ -0,0 +1,44 @@
1
+ # A minimalistic API for interacting with WebDAV servers.
2
+ #
3
+ # If commands needs to Simple WebDAV API for use in scripts where namespacing is not necessary.
4
+
5
+ # :stopdoc:
6
+
7
+ require 'davclient'
8
+ require 'davclient/dav-ls'
9
+
10
+ # :startdoc:
11
+
12
+ # Change working directory.
13
+ #
14
+ # Examples:
15
+ #
16
+ # require 'davclient/simple'
17
+ #
18
+ # cd("https://example.webdav.org/collection/")
19
+ # content = get("index.html")
20
+ # print content
21
+ def cd(args)
22
+ WebDAV.cd(args)
23
+ end
24
+
25
+ def pwd
26
+ WebDAV.CWURL
27
+ end
28
+
29
+ def find(*args, &block)
30
+ WebDAV.find(*args, &block)
31
+ end
32
+
33
+ def ls(*args)
34
+ if(args == [])
35
+ LsCLI.ls([WebDAV.CWURL])
36
+ else
37
+ LsCLI.ls(*args)
38
+ end
39
+ end
40
+
41
+ def get(args)
42
+ WebDAV.get(args)
43
+ end
44
+
data/lib/davclient.rb CHANGED
@@ -15,7 +15,16 @@ require 'davclient/curl_commands'
15
15
 
16
16
  # :startdoc:
17
17
 
18
- # WebDAV client
18
+ # Main WebDAV client. Current working URL is stored in a tempfile named /tmp/cwurl.pid, where pid is the parent process.
19
+ # Username an password is stored in the ~/.netrc file. This means there is no need to set up any sessions or connections.
20
+ #
21
+ # If a change directory command is executed with a relative path, like for instance WebDAV.cd("../collection"), it will
22
+ # raise an exception if current working url has not been set. First a change directory command is executed it should
23
+ # use an absolute URL, like for instance WebDAV.cd("https://www.webdav.org/collection/").
24
+ #
25
+ # If using an URL with a server name not found in the ~/.netrc file, instructions for adding
26
+ # the necessary servername, username and password will be printed to stdout.
27
+ #
19
28
  module WebDAV
20
29
 
21
30
  # :stopdoc:
@@ -28,9 +37,9 @@ module WebDAV
28
37
  VERSION
29
38
  end
30
39
 
31
- # Returns current working url. Used by command line utilites
40
+ # Returns current working url.
32
41
  def self.CWURL
33
- return $CWURL if($CWURL) # Used by tests
42
+ return $CWURL if($CWURL)
34
43
  cwurl = nil
35
44
  filename = cwurl_filename
36
45
  if(File.exists?(filename))
@@ -54,14 +63,17 @@ module WebDAV
54
63
  # url = url + "/" if(not(url =~ /\/$/))
55
64
 
56
65
  if(not(url =~ /^http.?:\/\//))then
57
- warn "#{$0}: Error: illegal url: " + url
58
- exit
66
+ raise "illegal url: " + url
59
67
  end
60
68
  end
61
69
  return url
62
70
  end
63
71
 
64
- # Returns true if url is a collection
72
+ # Boolean function that returns true if url is a collection
73
+ #
74
+ # Example:
75
+ #
76
+ # WebDAV.isCollection("../test.html") => false
65
77
  def self.isCollection?(url)
66
78
  url = absoluteUrl(url)
67
79
  url = url + "/" if(not(url =~ /\/$/))
@@ -74,6 +86,9 @@ module WebDAV
74
86
  end
75
87
 
76
88
  # Change current working url. Takes relative pathnames.
89
+ # First time this method is called, an absolute URL
90
+ # must be used. Raises exception if servername is not
91
+ # found in ~/.netrc file.
77
92
  #
78
93
  # Examples:
79
94
  #
@@ -91,10 +106,12 @@ module WebDAV
91
106
  end
92
107
  end
93
108
 
94
- # Sets current working url by storing url in a tempfile with parent process pid
109
+ # Sets current working url.
110
+ #
111
+ # Current working url is stored in aa tempfile with parent process pid
95
112
  # as part of the filename.
96
113
  def self.CWURL=(url)
97
- $CWURL = url # Used by tests
114
+ $CWURL = url
98
115
  File.open(cwurl_filename, 'w') {|f| f.write(url) }
99
116
  end
100
117
 
@@ -118,8 +135,9 @@ module WebDAV
118
135
  # Example:
119
136
  #
120
137
  # WebDAV.proppatch("https://dav.webdav.org/folder","<contentLastModified>2007-12-12 12:00:00 GMT</contentLastModified>
121
- def self.proppatch(href, property)
122
- curl_command = CURL_PROPPATCH + " \""+href+"\""
138
+ def self.proppatch(url, property)
139
+ url = absoluteUrl(url)
140
+ curl_command = CURL_PROPPATCH + " \""+url+"\""
123
141
  curl_command = curl_command.gsub("<!--property-and-value-->",property)
124
142
  response = exec_curl(curl_command)
125
143
  if(not(response =~ /200 OK/)) then
@@ -131,7 +149,8 @@ module WebDAV
131
149
  # Get WebDAV properties
132
150
  #
133
151
  # Examples:
134
- # item = propfind(url) - Returns a Hpricot::Elem object
152
+ #
153
+ # item = propfind(url) - Returns an Hpricot::Elem object
135
154
  #
136
155
  # xml = propfind(url, :xml => true) - Returns xml for debugging.
137
156
  def self.propfind(*args)
@@ -181,9 +200,37 @@ module WebDAV
181
200
  # puts folder.href
182
201
  # end
183
202
  #
203
+ # If no url is specified, current working url is used.
204
+ #
205
+ # cd("https://webdav.org")
206
+ # find() do |item|
207
+ # print item.title
208
+ # end
184
209
  def self.find(*args, &block)
185
- href = args[0]
186
- options = args[1]
210
+
211
+ if(args.size == 0)
212
+ href = self.CWURL
213
+ elsif(args.size == 1)
214
+ if(args[0].class == String)
215
+ href = args[0]
216
+ else
217
+ options = args[0]
218
+ end
219
+ elsif(args.size == 2)
220
+ href = args[0]
221
+ options = args[1]
222
+ else
223
+ raise "Illegal number of arguments."
224
+ end
225
+
226
+ if(href == nil )
227
+ if(WebDAV.CWURL == nil)
228
+ raise "no current working url set"
229
+ else
230
+ href = WebDAV.CWURL
231
+ end
232
+ end
233
+
187
234
  type = nil
188
235
  recursive = false
189
236
  if(options)then
@@ -219,7 +266,7 @@ module WebDAV
219
266
 
220
267
  else
221
268
  # Filter result set
222
- if((type == "collection" or type == "folder") and item.collection )then
269
+ if((type == "collection" or type == "folder" or type == "directory") and item.isCollection? )then
223
270
  items_filtered.push(item)
224
271
  if(block) then
225
272
  yield item
data/tests/dav.rb ADDED
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # This script is used to execute the 'dav' command line utility
4
+ # without re-installing the ruby gem
5
+
6
+ require 'test_helper'
7
+ require 'rubygems'
8
+ require 'davclient'
9
+ require 'davclient/davcli'
10
+
11
+ DavCLI.dav(ARGV)
12
+
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+ require 'rubygems'
4
+ require 'davclient'
5
+ require 'davclient'
6
+ require 'davclient/davcli'
7
+ require 'test/unit'
8
+ require 'test/zentest_assertions'
9
+
10
+
11
+ class TestDavCat < Test::Unit::TestCase
12
+
13
+ def cat(*args)
14
+ out, err = util_capture do
15
+ DavCLI.cat(*args)
16
+ end
17
+ return [out.string, err.string]
18
+ end
19
+
20
+ def test_basic_cat
21
+ url = "https://vortex-dav.uio.no/brukere/thomasfl/testfile.html"
22
+ content = WebDAV.get(url)
23
+
24
+ out, err = cat([url])
25
+ assert_equal content , out
26
+ end
27
+
28
+ def test_relative_urls
29
+ WebDAV.cd("https://vortex-dav.uio.no/brukere/thomasfl/")
30
+ content = WebDAV.get("testfile.html")
31
+ assert content
32
+ end
33
+
34
+ end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'test/unit'
4
+ require 'test_helper'
5
+ require 'davclient'
6
+ require 'davclient/davcli'
7
+ require 'test/zentest_assertions'
8
+
9
+ class TestWDavCd < Test::Unit::TestCase
10
+
11
+ def cd(*args)
12
+ out, err = util_capture do
13
+ DavCLI.cd(*args)
14
+ end
15
+ return ["", ""]
16
+ return [out.string, err.string]
17
+ end
18
+
19
+ def test_basic_cd
20
+ url = "https://vortex-dav.uio.no/prosjekter/it-avisa/nyheter/2006/"
21
+ out, err = cd([url])
22
+ assert_equal url, WebDAV.CWURL
23
+ end
24
+
25
+ def test_pathname
26
+ url = "https://vortex-dav.uio.no/prosjekter/it-avisa/nyheter/2006/"
27
+ out, err = cd([url])
28
+ assert_equal url, WebDAV.CWURL
29
+ out, err = cd([".."])
30
+ assert_equal url = "https://vortex-dav.uio.no/prosjekter/it-avisa/nyheter/", WebDAV.CWURL
31
+
32
+ out, err = WebDAV.cd("../../../brukere/thomasfl/")
33
+ assert_equal "https://vortex-dav.uio.no/brukere/thomasfl/", WebDAV.CWURL
34
+
35
+ exception = false
36
+ begin
37
+ out, err = WebDAV.cd(["../../../../../../"])
38
+ rescue Exception
39
+ exception = true
40
+ end
41
+ assert exception, "Should have raised an exception"
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+ require 'rubygems'
4
+ require 'davclient'
5
+ require 'davclient/davcli'
6
+ require 'test/unit'
7
+ require 'test/zentest_assertions'
8
+
9
+ class TestCP < Test::Unit::TestCase
10
+
11
+ def cp(*args)
12
+ out, err = util_capture do
13
+ DavCLI.cp(*args)
14
+ end
15
+ return [out.string, err.string]
16
+ end
17
+
18
+ def test_cp
19
+ $DEBUG = false
20
+ src = "https://vortex-dav.uio.no/brukere/thomasfl/testfile.html"
21
+ dest = "https://vortex-dav.uio.no/brukere/thomasfl/testfile_copy.html"
22
+ WebDAV.delete(dest)
23
+ assert !WebDAV.exists?(dest)
24
+
25
+ WebDAV.cp(src,dest)
26
+ assert WebDAV.exists?(dest)
27
+ end
28
+
29
+ def test_propfind_command_line
30
+ src = "https://vortex-dav.uio.no/brukere/thomasfl/testfile.html"
31
+ dest = "https://vortex-dav.uio.no/brukere/thomasfl/testfile_copy.html"
32
+ WebDAV.delete(dest)
33
+ assert !WebDAV.exists?(dest)
34
+
35
+ out, err = cp([src,dest])
36
+ assert WebDAV.exists?(dest)
37
+
38
+ # Relative url
39
+ WebDAV.delete(dest)
40
+ assert !WebDAV.exists?(dest)
41
+
42
+
43
+ WebDAV.cd("https://vortex-dav.uio.no/brukere/thomasfl/")
44
+ dest = "testfile_copy.html"
45
+
46
+ out, err = cp([src,dest])
47
+ assert WebDAV.exists?(dest)
48
+ end
49
+
50
+
51
+ end