nolij_web 1.0.0
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/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +50 -0
- data/Rakefile +9 -0
- data/lib/nolij_web/attribute_missing_error.rb +4 -0
- data/lib/nolij_web/authentication_error.rb +4 -0
- data/lib/nolij_web/connection.rb +179 -0
- data/lib/nolij_web/connection_configuration_error.rb +4 -0
- data/lib/nolij_web/handler.rb +208 -0
- data/lib/nolij_web/version.rb +5 -0
- data/lib/nolij_web.rb +13 -0
- data/nolij_web.gemspec +33 -0
- data/test/nolij_web/attribute_missing_error_test.rb +7 -0
- data/test/nolij_web/authentication_error_test.rb +7 -0
- data/test/nolij_web/connection_configuration_error_test.rb +7 -0
- data/test/nolij_web/connection_test.rb +404 -0
- data/test/nolij_web/handler_test.rb +210 -0
- data/test/nolij_web/test_stubs/bad_nolij_config.yml +3 -0
- data/test/nolij_web/test_stubs/document_submitted_success.xml +3 -0
- data/test/nolij_web/test_stubs/folder_info.xml +27 -0
- data/test/nolij_web/test_stubs/nolij_config.yml +3 -0
- data/test/nolij_web/test_stubs/text_file.txt +1 -0
- data/test/nolij_web/test_stubs/version_info.xml +2 -0
- data/test/nolij_web/version_test.rb +7 -0
- data/test/test_helper.rb +11 -0
- metadata +187 -0
@@ -0,0 +1,404 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe NolijWeb::Connection do
|
4
|
+
# Format cookies for webmock headers
|
5
|
+
def to_cookie(cookies = {})
|
6
|
+
cookies.sort_by{|k, v| k.to_s}.collect{|c| "#{c[0]}=#{c[1]}"}.join('; ')
|
7
|
+
end
|
8
|
+
|
9
|
+
# Set up basic configured connection as @conn
|
10
|
+
def setup_configured_connection
|
11
|
+
username = 'test_monkey'
|
12
|
+
pw = 'test_banana'
|
13
|
+
@base_url = 'http://banana.example.com/NolijWeb'
|
14
|
+
@conn = NolijWeb::Connection.new({:username => username, :password => pw, :base_url => @base_url})
|
15
|
+
end
|
16
|
+
|
17
|
+
#stubs connection and requests for full authenticated round trip
|
18
|
+
def stub_connection_round_trip(connection)
|
19
|
+
@cookies = {'k' => 'v', 'a' => 'b'}
|
20
|
+
|
21
|
+
@stubbed_login = stub_request(:post, "#{@base_url}/j_spring_security_check").
|
22
|
+
with(:body => {"j_password"=> connection.instance_variable_get(:@password), "j_username"=> connection.instance_variable_get(:@username)}).to_return(:status => 200, :headers => {'Set-Cookie' => to_cookie(@cookies)})
|
23
|
+
|
24
|
+
@stubbed_logout = stub_request(:get, "#{@base_url}/j_spring_security_logout").with(:headers => {'Cookie' => to_cookie(@cookies)})
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '# initialize' do
|
28
|
+
describe 'with no config' do
|
29
|
+
it "should raise config error" do
|
30
|
+
err = lambda{NolijWeb::Connection.new(nil)}.must_raise(NolijWeb::ConnectionConfigurationError)
|
31
|
+
err.to_s.must_match /invalid configuration/i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'defaults initialization behavior' do
|
36
|
+
before do
|
37
|
+
@conn = NolijWeb::Connection.new({})
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have nil connection instance var" do
|
41
|
+
@conn.instance_variable_get(:@connection).must_be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have nil cookies instance var" do
|
45
|
+
@conn.instance_variable_get(:@cookies).must_be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have string username instance var" do
|
49
|
+
@conn.instance_variable_get(:@username).must_be_kind_of(String)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have string password instance var" do
|
53
|
+
@conn.instance_variable_get(:@password).must_be_kind_of(String)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have string base_url instance var" do
|
57
|
+
@conn.instance_variable_get(:@base_url).must_be_kind_of(String)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'set config for new instances' do
|
62
|
+
describe "with hash config" do
|
63
|
+
before do
|
64
|
+
@conn = NolijWeb::Connection.new({:username => 'test_monkey', :password => 'banana oooeee', :base_url => 'http://testsomething.example.com/NolijWeb'})
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have string username instance var" do
|
68
|
+
@conn.instance_variable_get(:@username).must_equal 'test_monkey'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have string password instance var" do
|
72
|
+
@conn.instance_variable_get(:@password).must_equal 'banana oooeee'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have string base_url instance var" do
|
76
|
+
@conn.instance_variable_get(:@base_url).must_equal 'http://testsomething.example.com/NolijWeb'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should have hash config" do
|
80
|
+
@conn.instance_variable_get(:@config).must_be_kind_of(Hash)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with yaml config" do
|
85
|
+
before do
|
86
|
+
@conn = NolijWeb::Connection.new(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'nolij_config.yml'))
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have string username instance var" do
|
90
|
+
@conn.instance_variable_get(:@username).must_equal 'monkey'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have string password instance var" do
|
94
|
+
@conn.instance_variable_get(:@password).must_equal 'banana'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have string base_url instance var" do
|
98
|
+
@conn.instance_variable_get(:@base_url).must_equal 'http://testsomething2.example.com/NolijWeb'
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should have hash config" do
|
102
|
+
@conn.instance_variable_get(:@config).must_be_kind_of(Hash)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#configure' do
|
109
|
+
before do
|
110
|
+
@conn = NolijWeb::Connection.new({})
|
111
|
+
@conn.configure({:username => 'new_user', :password => 'new_password', :base_url => 'http://newsomething.example.com/NolijWeb'})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should define config" do
|
115
|
+
@conn.instance_variable_get(:@config).must_be_kind_of(Hash)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should define base_url" do
|
119
|
+
@conn.instance_variable_get(:@base_url).must_equal 'http://newsomething.example.com/NolijWeb'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should define username" do
|
123
|
+
@conn.instance_variable_get(:@username).must_equal 'new_user'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should define password" do
|
127
|
+
@conn.instance_variable_get(:@password).must_equal 'new_password'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should define nil connection" do
|
131
|
+
@conn.instance_variable_get(:@connection).must_be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should define nil cookies" do
|
135
|
+
@conn.instance_variable_get(:@cookies).must_be_nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#configure_with' do
|
140
|
+
before do
|
141
|
+
@conn = NolijWeb::Connection.new({})
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should raild ConnectionConfigurationError for invalid string parameter" do
|
145
|
+
err = lambda{
|
146
|
+
@conn.configure_with([])
|
147
|
+
}.must_raise(NolijWeb::ConnectionConfigurationError)
|
148
|
+
err.to_s.must_match /invalid request/i
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should raise ConnectionConfigurationError for invalid syntax" do
|
152
|
+
err = lambda{
|
153
|
+
@conn.configure_with(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'bad_nolij_config.yml'))
|
154
|
+
}.must_raise(NolijWeb::ConnectionConfigurationError)
|
155
|
+
err.to_s.must_match /invalid syntax/i
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should raise ConnectionConfigurationError for no file" do
|
159
|
+
err = lambda{
|
160
|
+
@conn.configure_with('gobble.yml')
|
161
|
+
}.must_raise(NolijWeb::ConnectionConfigurationError)
|
162
|
+
err.to_s.must_match /not found/i
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#establish_connection' do
|
167
|
+
before do
|
168
|
+
setup_configured_connection
|
169
|
+
stub_connection_round_trip(@conn)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should request login url" do
|
173
|
+
@conn.establish_connection
|
174
|
+
assert_requested @stubbed_login
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should assign instance var cookies" do
|
178
|
+
@conn.establish_connection
|
179
|
+
@conn.instance_variable_get(:@cookies).must_equal @cookies
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should assign not nil connection" do
|
183
|
+
@conn.establish_connection
|
184
|
+
@conn.instance_variable_get(:@connection).wont_be_nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#close_connection' do
|
189
|
+
describe "when not logged in" do
|
190
|
+
before do
|
191
|
+
setup_configured_connection
|
192
|
+
@stubbed_logout = stub_request(:get, "#{@base_url}/j_spring_security_logout")
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should not request logout url" do
|
196
|
+
@conn.close_connection
|
197
|
+
@conn.connection.must_be_nil
|
198
|
+
assert_not_requested @stubbed_logout
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should set nil connection" do
|
202
|
+
@conn.instance_variable_set(:@connection, MiniTest::Mock.new)
|
203
|
+
@conn.close_connection
|
204
|
+
@conn.instance_variable_get(:@connection).must_be_nil
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should set nil cookies" do
|
208
|
+
@conn.instance_variable_set(:@cookies, MiniTest::Mock.new)
|
209
|
+
@conn.close_connection
|
210
|
+
@conn.instance_variable_get(:@cookies).must_be_nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "when logged in" do
|
215
|
+
before do
|
216
|
+
setup_configured_connection
|
217
|
+
stub_connection_round_trip(@conn)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should request logout url" do
|
221
|
+
assert @conn.establish_connection
|
222
|
+
@conn.close_connection
|
223
|
+
assert_requested @stubbed_logout
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should reset nil connection" do
|
227
|
+
assert @conn.establish_connection
|
228
|
+
@conn.instance_variable_get(:@connection).wont_be_nil
|
229
|
+
@conn.close_connection
|
230
|
+
@conn.instance_variable_get(:@connection).must_be_nil
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should set not nil cookies" do
|
234
|
+
assert @conn.establish_connection
|
235
|
+
@conn.instance_variable_get(:@cookies).wont_be_nil
|
236
|
+
@conn.close_connection
|
237
|
+
@conn.instance_variable_get(:@cookies).must_be_nil
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#get_custom_connection" do
|
243
|
+
before do
|
244
|
+
setup_configured_connection
|
245
|
+
stub_connection_round_trip(@conn)
|
246
|
+
@stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should not open connection" do
|
250
|
+
@conn.get_custom_connection('go')
|
251
|
+
assert_not_requested @stubbed_login
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should get input path at base url with cookies" do
|
255
|
+
@conn.get_custom_connection('go')
|
256
|
+
assert_requested @stubbed_get
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should not close connection" do
|
260
|
+
@conn.get_custom_connection('go')
|
261
|
+
assert_not_requested @stubbed_logout
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#get' do
|
266
|
+
before do
|
267
|
+
setup_configured_connection
|
268
|
+
stub_connection_round_trip(@conn)
|
269
|
+
@stubbed_get = stub_request(:get, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should open connection" do
|
273
|
+
@conn.get('go')
|
274
|
+
assert_requested @stubbed_login
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should get input path at base url with cookies" do
|
278
|
+
@conn.get('go')
|
279
|
+
assert_requested @stubbed_get
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should close connection" do
|
283
|
+
@conn.get('go', {})
|
284
|
+
assert_requested @stubbed_logout
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "#delete_custom_connection" do
|
289
|
+
before do
|
290
|
+
setup_configured_connection
|
291
|
+
stub_connection_round_trip(@conn)
|
292
|
+
@stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should not open connection" do
|
296
|
+
@conn.delete_custom_connection('go')
|
297
|
+
assert_not_requested @stubbed_login
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should get input path at base url with cookies" do
|
301
|
+
@conn.delete_custom_connection('go')
|
302
|
+
assert_requested @stubbed_get
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should not close connection" do
|
306
|
+
@conn.delete_custom_connection('go')
|
307
|
+
assert_not_requested @stubbed_logout
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe '#delete' do
|
312
|
+
before do
|
313
|
+
setup_configured_connection
|
314
|
+
stub_connection_round_trip(@conn)
|
315
|
+
@stubbed_get = stub_request(:delete, "#{@base_url}/go").to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should open connection" do
|
319
|
+
@conn.delete('go')
|
320
|
+
assert_requested @stubbed_login
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should get input path at base url with cookies" do
|
324
|
+
@conn.delete('go')
|
325
|
+
assert_requested @stubbed_get
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should close connection" do
|
329
|
+
@conn.delete('go', {})
|
330
|
+
assert_requested @stubbed_logout
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe '#post_custom_connection' do
|
335
|
+
before do
|
336
|
+
setup_configured_connection
|
337
|
+
stub_connection_round_trip(@conn)
|
338
|
+
@post_params = {'a' => 'b'}
|
339
|
+
@stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should not open connection" do
|
343
|
+
@conn.post_custom_connection('go', @post_params)
|
344
|
+
assert_not_requested @stubbed_login
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should post to input path at base url with params and cookies" do
|
348
|
+
@conn.post_custom_connection('go', @post_params)
|
349
|
+
assert_requested @stubbed_post
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should not close connection" do
|
353
|
+
@conn.post_custom_connection('go', @post_params)
|
354
|
+
assert_not_requested @stubbed_logout
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe '#post' do
|
359
|
+
before do
|
360
|
+
setup_configured_connection
|
361
|
+
stub_connection_round_trip(@conn)
|
362
|
+
@post_params = {'a' => 'b'}
|
363
|
+
@stubbed_post = stub_request(:post, "#{@base_url}/go").with(:body => @post_params).to_return(:status => 200, :headers => {'Cookie' => to_cookie(@cookies)})
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should open connection" do
|
367
|
+
@conn.post('go', @post_params)
|
368
|
+
assert_requested @stubbed_login
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should post to input path at base url with params and cookies" do
|
372
|
+
@conn.post('go', @post_params)
|
373
|
+
assert_requested @stubbed_post
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should close connection" do
|
377
|
+
@conn.post('go', @post_params)
|
378
|
+
assert_requested @stubbed_logout
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
describe '#execute' do
|
383
|
+
before do
|
384
|
+
setup_configured_connection
|
385
|
+
stub_connection_round_trip(@conn)
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should establish connection" do
|
389
|
+
@conn.execute { "something to do" }
|
390
|
+
assert_requested @stubbed_login
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should close connection when successful" do
|
394
|
+
@conn.execute { "something to do" }
|
395
|
+
assert_requested @stubbed_logout
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should yield the block" do
|
399
|
+
result = @conn.execute { "something to do" }
|
400
|
+
result.must_equal 'something to do'
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe NolijWeb::Handler do
|
4
|
+
before do
|
5
|
+
@base_url = 'http://example.reed.edu/NolijWeb'
|
6
|
+
@handler = NolijWeb::Handler.new({:username => 'test_user', :password => 'test_password', :base_url => @base_url})
|
7
|
+
# stub auth
|
8
|
+
stub_request(:post, "#{@base_url}/j_spring_security_check").
|
9
|
+
with(:body => {"j_password"=>"test_password", "j_username"=>"test_user"}).to_return(:status => 200)
|
10
|
+
stub_request(:get, "http://example.reed.edu/NolijWeb/j_spring_security_logout").to_return(:status => 200)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "initialize" do
|
14
|
+
it "should respond to connection" do
|
15
|
+
@handler.respond_to?(:connection)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set a connection" do
|
19
|
+
@handler.instance_variable_get(:@connection).wont_be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set a config" do
|
23
|
+
@handler.instance_variable_get(:@config).wont_be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with valid folder request" do
|
28
|
+
before do
|
29
|
+
@folder_id = '1_2'
|
30
|
+
response = File.new(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'folder_info.xml'))
|
31
|
+
@stubbed_request = stub_request(:get, /\/handler\/api\/docs\/#{@folder_id}/).to_return(:status => 200, :body => response)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#folder_info" do
|
35
|
+
it "should raise missing attribute if no id is supplied" do
|
36
|
+
err = lambda{@handler.folder_info}.must_raise(NolijWeb::AttributeMissingError)
|
37
|
+
err.to_s.must_match /Folder ID is required/
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should get stubbed url" do
|
41
|
+
folder_info = @handler.folder_info(:folder_id => @folder_id)
|
42
|
+
assert_requested @stubbed_request
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return nokogiri xml document" do
|
46
|
+
folder_info = @handler.folder_info(:folder_id => @folder_id)
|
47
|
+
folder_info.must_be_kind_of(Nokogiri::XML::Document)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#folder_contents" do
|
52
|
+
it "should get stubbed url" do
|
53
|
+
folder_info = @handler.folder_contents(:folder_id => @folder_id)
|
54
|
+
assert_requested @stubbed_request
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return an array" do
|
58
|
+
folder_contents = @handler.folder_contents(:folder_id => @folder_id)
|
59
|
+
folder_contents.must_be_kind_of(Array)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#submit_document" do
|
65
|
+
it "should raise missing attribute if no folder id is supplied" do
|
66
|
+
err = lambda{@handler.submit_document('test_file.txt', {:folder_id => nil})}.must_raise(NolijWeb::AttributeMissingError)
|
67
|
+
err.to_s.must_match /Folder ID is required/
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should raise missing attribute if folder id is supplied but no file" do
|
71
|
+
err = lambda{@handler.submit_document(nil, {:folder_id => '234_324'})}.must_raise(NolijWeb::AttributeMissingError)
|
72
|
+
err.to_s.must_match /path is required/
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'with valid folder and file path' do
|
76
|
+
before do
|
77
|
+
@file_path = File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'text_file.txt')
|
78
|
+
@folder_id = '1_2'
|
79
|
+
response = File.new(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'document_submitted_success.xml'))
|
80
|
+
@stubbed_request = stub_request(:post, /\/handler\/api\/docs\/#{@folder_id}/).to_return(:status => 200, :body => response)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should post to connection url" do
|
84
|
+
file_upload = @handler.submit_document(@file_path, :folder_id => @folder_id)
|
85
|
+
assert_requested @stubbed_request
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return a file id" do
|
89
|
+
#96855 is set in test_stubs/file_posted.xml
|
90
|
+
file_upload = @handler.submit_document(@file_path, :folder_id => @folder_id)
|
91
|
+
file_upload.must_equal '96855'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#print_document' do
|
97
|
+
before do
|
98
|
+
@document_ids = ['12345', '54326']
|
99
|
+
@folder_id = '111_2'
|
100
|
+
@stubbed_request = stub_request(:get, /\/handler\/api\/docs\/print/).to_return(:status => 200)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should raise missing attribute if no document ids supplied" do
|
104
|
+
err = lambda{@handler.print_document}.must_raise(NolijWeb::AttributeMissingError)
|
105
|
+
err.to_s.must_match /document ID is required/i
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should get print document" do
|
109
|
+
@handler.print_document(:document_id => @document_ids)
|
110
|
+
assert_requested @stubbed_request
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#viewer_url' do
|
115
|
+
it "should raise missing attribute if no document id supplied" do
|
116
|
+
err = lambda{@handler.viewer_url}.must_raise(NolijWeb::AttributeMissingError)
|
117
|
+
err.to_s.must_match /document ID is required/i
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return a full url if full url is true" do
|
121
|
+
@handler.viewer_url(:document_id => '1234', :full_url => true).must_match /^#{@base_url}/
|
122
|
+
end
|
123
|
+
|
124
|
+
it "return a path if full url is empty" do
|
125
|
+
@handler.viewer_url(:document_id => '1234').wont_match /^#{@base_url}/
|
126
|
+
end
|
127
|
+
|
128
|
+
it "return a path if full url is false" do
|
129
|
+
@handler.viewer_url(:document_id => '1234', :full_url => false).wont_match /^#{@base_url}/
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return a string" do
|
133
|
+
@handler.viewer_url(:document_id => '1234').must_be_kind_of(String)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#login_check' do
|
138
|
+
it "should raise missing attribute if no redirect_to_path is supplied" do
|
139
|
+
err = lambda{@handler.login_check}.must_raise(NolijWeb::AttributeMissingError)
|
140
|
+
err.to_s.must_match /redirect path is required/i
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should raise missing attribute if redirect_to_path is empty" do
|
144
|
+
err = lambda{@handler.login_check(:redir => '')}.must_raise(NolijWeb::AttributeMissingError)
|
145
|
+
err.to_s.must_match /redirect path is required/i
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should return a full url if full url is true" do
|
149
|
+
@handler.login_check(:redir => '/document_path', :full_url => true).must_match /^#{@base_url}/
|
150
|
+
end
|
151
|
+
|
152
|
+
it "return a path if full url is empty" do
|
153
|
+
@handler.login_check(:redir => '/document_path').wont_match /^#{@base_url}/
|
154
|
+
end
|
155
|
+
|
156
|
+
it "return a path if full url is false" do
|
157
|
+
@handler.login_check(:redir => '/document_path', :full_url => false).wont_match /^#{@base_url}/
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should return a string" do
|
161
|
+
@handler.login_check(:redir => '/document_path').must_be_kind_of(String)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#work_complete' do
|
166
|
+
before do
|
167
|
+
@folder_id = '12334'
|
168
|
+
@folder_name = "Schmoe, Joe"
|
169
|
+
@wfma_code = '12344'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should raise missing attribute if no wfma code supplied" do
|
173
|
+
err = lambda{@handler.work_complete(:folder_name => @folder_name, :folder_id => @folder_id)}.must_raise(NolijWeb::AttributeMissingError)
|
174
|
+
err.to_s.must_match /workflow master code is required/i
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should raise missing attribute if no folder name supplied" do
|
178
|
+
err = lambda{@handler.work_complete(:wfma_code => '1234', :folder_id => @folder_id)}.must_raise(NolijWeb::AttributeMissingError)
|
179
|
+
err.to_s.must_match /folder name is required/i
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should raise missing attribute if no folder id supplied" do
|
183
|
+
err = lambda{@handler.work_complete(:wfma_code => '1234', :folder_name => @folder_name)}.must_raise(NolijWeb::AttributeMissingError)
|
184
|
+
err.to_s.must_match /folder id is required/i
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should post to work complete" do
|
188
|
+
stubbed_request = stub_request(:post, /\/handler\/api\/workflow\/workcomplete\/#{@folder_id}/).with(:query => hash_including({:wfmacode => @wfma_code, :foldername => @folder_name.to_s})).to_return(:status => 200)
|
189
|
+
@handler.work_complete(:folder_id => @folder_id, :wfma_code => @wfma_code, :folder_name => @folder_name)
|
190
|
+
assert_requested stubbed_request
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#version" do
|
195
|
+
before do
|
196
|
+
response = File.new(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'version_info.xml'))
|
197
|
+
@stubbed_request = stub_request(:get, /\/handler\/api\/version/).to_return(:status => 200, :body => response)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should get stubbed url" do
|
201
|
+
@handler.version
|
202
|
+
assert_requested @stubbed_request
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should return an hash" do
|
206
|
+
@handler.version.must_be_kind_of(Hash)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<folderobjects folderid="209" count="3">
|
3
|
+
<folderobject
|
4
|
+
docname="Image096550.tif"
|
5
|
+
displayname="Application for Withdrawal.tif"
|
6
|
+
datecreated="2010-01-05 13:39:58.0 EST"
|
7
|
+
filesize="877492"
|
8
|
+
documentid="96550"
|
9
|
+
filetype="tif"
|
10
|
+
pagecount="1"/>
|
11
|
+
<folderobject
|
12
|
+
docname="Image096551.tif"
|
13
|
+
displayname="Change of Academic Program.tif"
|
14
|
+
datecreated="2010-01-05 13:39:58.0 EST"
|
15
|
+
filesize="9268980"
|
16
|
+
documentid="96551"
|
17
|
+
filetype="tif"
|
18
|
+
pagecount="2" />
|
19
|
+
<folderobject
|
20
|
+
docname="Image096552.tif"
|
21
|
+
displayname="Change of Grade.tif"
|
22
|
+
datecreated="2010-01-05 13:39:59.0 EST"
|
23
|
+
filesize="2661944"
|
24
|
+
filetype="tif"
|
25
|
+
documentid="96552"
|
26
|
+
pagecount="1" />
|
27
|
+
</folderobjects>
|
@@ -0,0 +1 @@
|
|
1
|
+
some text
|