smugsync 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'smugsync'
4
+ require 'assert_same'
5
+
6
+ # mocks
7
+ require 'mock/smug_server'
8
+ require 'mock/command'
9
+ require 'mock/oauth/tokens/request_token'
10
+
11
+ class SmugTestCase < Test::Unit::TestCase
12
+
13
+ include Smug
14
+
15
+ @@server_dir = File.expand_path(File.join(File.dirname(__FILE__), "server"))
16
+ @@local_dir = File.expand_path(File.join(File.dirname(__FILE__), "local"))
17
+
18
+ def self.server_dir
19
+ @@server_dir
20
+ end
21
+
22
+ def default_test
23
+ end
24
+
25
+ def execute(command)
26
+ @command_output = nil
27
+ $stdout = @stdout = StringIO.new
28
+ $stderr = @stderr = StringIO.new
29
+
30
+ previous_dir = Dir.pwd
31
+ Dir.chdir(@@local_dir)
32
+ command = Smug.const_get("#{command.to_s.capitalize}Command").new
33
+ begin
34
+ command.exec
35
+ rescue SystemExit
36
+ # do not exit, we'll want to check command output
37
+ end
38
+ @command_output = [@stdout.string, @stderr.string].reject { |out| out.empty? }.join("\n")
39
+ Dir.chdir(previous_dir)
40
+
41
+ $stdout = STDOUT
42
+ $stderr = STDERR
43
+ end
44
+
45
+ def command_output
46
+ @command_output
47
+ end
48
+
49
+ def prepare_server_dir(structure)
50
+ FileUtils::rm_rf(Dir.glob(@@server_dir + "/**"))
51
+ prepare_dir(@@server_dir, structure)
52
+ end
53
+
54
+ def prepare_local_dir(structure)
55
+ FileUtils::rm_rf(Dir.glob(@@local_dir + "/**"))
56
+ FileUtils::rm_rf(@@local_dir + "/.smug")
57
+
58
+ return if structure == :empty
59
+
60
+ FileUtils::mkdir(@@local_dir + "/.smug")
61
+ File.open(@@local_dir + "/.smug/accesstoken", "w+") do |f|
62
+ f.puts JSON.pretty_generate(OAuth::RequestToken::TEST_ACCESS_TOKEN)
63
+ end
64
+ prepare_dir(@@local_dir, structure)
65
+ end
66
+
67
+ private
68
+
69
+ def prepare_dir(dir, structure)
70
+ previous_dir = Dir.pwd
71
+ lines = structure.split("\n")
72
+ indentation = lines.first =~ /^(\s+)/ ? $1.length : 0
73
+ lines.each do |line|
74
+ is_folder = line =~ /^(\s+)/ && $1.length == indentation
75
+ line.strip!
76
+ if is_folder
77
+ FileUtils::cd(dir)
78
+ FileUtils::mkdir(line)
79
+ FileUtils::cd(line)
80
+ else
81
+ # this is a file
82
+ FileUtils::touch(line)
83
+ end
84
+ end
85
+ Dir.chdir(previous_dir)
86
+ end
87
+
88
+ end
@@ -0,0 +1,55 @@
1
+ require 'smug_test_case'
2
+
3
+ class StatusCommandTest < SmugTestCase
4
+
5
+ def test_empty_local_dir
6
+ prepare_local_dir(:empty)
7
+ execute "status"
8
+ assert_same command_output, <<-END
9
+ Fatal: Not a SmugMug folder (or any parent up to root).
10
+ Run 'smug init' to initialize current folder as SmugMug folder.
11
+ END
12
+ end
13
+
14
+ def test_status
15
+ prepare_server_dir <<-END
16
+ Sample Folder 1
17
+ Pic 1.png
18
+ Pic 2.jpg
19
+ Pic 3.jpg
20
+ Pic 4.jpg
21
+ pic 5.jpg
22
+ sample folder 2
23
+ Pic 1.png
24
+ Pic 2.jpg
25
+ sAmple foLder 3
26
+ Pic 1.png
27
+ Pic 2.jpg
28
+ END
29
+ prepare_local_dir <<-END
30
+ Sample Folder 1
31
+ Pic 1.png
32
+ Pic 3.jpg
33
+ pic 4.jpg
34
+ Pic 5.jpg
35
+ sample folder 2
36
+ Pic 1.png
37
+ Pic 2.jpg
38
+ sample folder 4
39
+ Pic 1.png
40
+ Pic 2.jpg
41
+ END
42
+ execute "fetch"
43
+ execute "status"
44
+ assert_same command_output, <<-END
45
+ not_uploaded Sample Folder 1/Pic 5.jpg
46
+ not_uploaded Sample Folder 1/pic 4.jpg
47
+ not_downloaded Sample Folder 1/pic 5.jpg
48
+ not_downloaded Sample Folder 1/Pic 2.jpg
49
+ not_downloaded Sample Folder 1/Pic 4.jpg
50
+ not_downloaded sAmple foLder 3/(2 files)
51
+ not_uploaded sample folder 4/(2 files)
52
+ END
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smugsync
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Alexander Dymo
13
+ autorequire: smugsync
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-05-31 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: bundler
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 23
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: assert_same
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 0
46
+ - 1
47
+ - 0
48
+ version: 0.1.0
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: trollop
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 87
60
+ segments:
61
+ - 1
62
+ - 16
63
+ - 0
64
+ version: 1.16.0
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: json
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 15
76
+ segments:
77
+ - 1
78
+ - 6
79
+ - 0
80
+ version: 1.6.0
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: oauth
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 15
92
+ segments:
93
+ - 0
94
+ - 4
95
+ - 0
96
+ version: 0.4.0
97
+ type: :runtime
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: system_timer
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 31
108
+ segments:
109
+ - 1
110
+ - 2
111
+ - 0
112
+ version: 1.2.0
113
+ type: :runtime
114
+ version_requirements: *id006
115
+ description:
116
+ email: adymo@kdevelop.org
117
+ executables:
118
+ - smug
119
+ extensions: []
120
+
121
+ extra_rdoc_files: []
122
+
123
+ files:
124
+ - .gitignore
125
+ - AUTHORS
126
+ - COPYING
127
+ - README.md
128
+ - Rakefile
129
+ - bin/smug
130
+ - lib/smugsync.rb
131
+ - lib/smugsync/albums.rb
132
+ - lib/smugsync/command.rb
133
+ - lib/smugsync/config.rb
134
+ - lib/smugsync/console.rb
135
+ - lib/smugsync/download.rb
136
+ - lib/smugsync/fetch.rb
137
+ - lib/smugsync/init.rb
138
+ - lib/smugsync/status.rb
139
+ - lib/smugsync/upload.rb
140
+ - lib/smugsync/utils.rb
141
+ - smugsync.gemspec
142
+ - smugsync.kdev4
143
+ - test/local/.gitignore
144
+ - test/mock/command.rb
145
+ - test/mock/oauth/tokens/request_token.rb
146
+ - test/mock/smug_server.rb
147
+ - test/server/.gitignore
148
+ - test/smug_test_case.rb
149
+ - test/status_command_test.rb
150
+ homepage: http://github.com/adymo/smugsync
151
+ licenses: []
152
+
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.8.15
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: .
183
+ test_files:
184
+ - test/local/.gitignore
185
+ - test/mock/command.rb
186
+ - test/mock/oauth/tokens/request_token.rb
187
+ - test/mock/smug_server.rb
188
+ - test/server/.gitignore
189
+ - test/smug_test_case.rb
190
+ - test/status_command_test.rb