rews 0.2.12 → 0.5.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/README.rdoc +12 -7
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/lib/rews.rb +18 -0
- data/lib/rews/client.rb +175 -7
- data/lib/rews/folder.rb +0 -63
- data/lib/rews/item.rb +46 -1
- data/lib/rews/update.rb +46 -0
- data/lib/rews/util.rb +12 -2
- data/spec/request_proxy.rb +25 -1
- data/spec/rews/client_spec.rb +304 -0
- data/spec/rews/folder_spec.rb +2 -150
- data/spec/rews/item_spec.rb +120 -42
- data/spec/rews/update_spec.rb +20 -0
- data/spec/rews/util_spec.rb +11 -2
- data/spec/rews_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- metadata +34 -13
data/lib/rews/util.rb
CHANGED
@@ -63,6 +63,16 @@ module Rews
|
|
63
63
|
Hash[h.map{|k,v| [camelize(k.to_s), v]}]
|
64
64
|
end
|
65
65
|
|
66
|
+
# convert rsxml to xml, transforming tags to CamelCase and prefixing with
|
67
|
+
# the t: namespace prefix
|
68
|
+
def rsxml_to_xml(sexp)
|
69
|
+
Rsxml.to_xml(sexp) do |tag, attrs|
|
70
|
+
ttag = "t:#{camelize(tag.to_s)}"
|
71
|
+
tattrs = Hash[attrs.map{|k,v| [camelize(k.to_s), v]}]
|
72
|
+
[ttag, tattrs]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
66
76
|
# check the response codes of an Exchange Web Services request.
|
67
77
|
# the supplied block makes a SOAP request, and the response is parsed
|
68
78
|
# out and checked
|
@@ -82,7 +92,7 @@ module Rews
|
|
82
92
|
|
83
93
|
errors = all_statuses.map{|s| single_error_check(client, s)}.compact
|
84
94
|
rescue Exception=>e
|
85
|
-
|
95
|
+
Rews.log{|logger| logger.warn(e)}
|
86
96
|
tag_exception(e, :savon_response=>response)
|
87
97
|
raise e
|
88
98
|
end
|
@@ -102,7 +112,7 @@ module Rews
|
|
102
112
|
if status[:response_class] == "Error"
|
103
113
|
return "#{status[:response_code]} - #{status[:message_text]}"
|
104
114
|
elsif status[:response_class] == "Warning"
|
105
|
-
|
115
|
+
Rews.log{|logger| logger.warn("#{status[:response_code]} - #{status[:message_text]}")}
|
106
116
|
end
|
107
117
|
end
|
108
118
|
end
|
data/spec/request_proxy.rb
CHANGED
@@ -4,7 +4,8 @@ class RequestProxy
|
|
4
4
|
attr_accessor :soap
|
5
5
|
attr_accessor :http
|
6
6
|
def initialize
|
7
|
-
|
7
|
+
soap_struct = Struct.new(:body)
|
8
|
+
@soap = soap_struct.new
|
8
9
|
@http=Object.new
|
9
10
|
end
|
10
11
|
|
@@ -16,5 +17,28 @@ class RequestProxy
|
|
16
17
|
def method_missing(method, *args, &block)
|
17
18
|
@self_before_instance_eval.send method, *args, &block
|
18
19
|
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
# mocks a request to the savon client, and validates that the body xml generated
|
23
|
+
# is correct
|
24
|
+
def mock_request(example, client, action, attrs, response, &validate_block)
|
25
|
+
# deal with different call arity
|
26
|
+
example.mock(client).savon_client.mock!.request(*[:wsdl, action, attrs].compact) do |*args|
|
27
|
+
block = args.last # block is the last arg
|
28
|
+
|
29
|
+
ctx = RequestProxy.new()
|
30
|
+
example.mock(ctx.http).headers.mock!["SOAPAction"]="\"#{Rews::SCHEMA_MESSAGES}/#{action}\""
|
31
|
+
ns = Object.new
|
32
|
+
example.mock(ctx.soap).namespaces{ns}
|
33
|
+
example.mock(ns)["xmlns:t"]=Rews::SCHEMA_TYPES
|
34
|
+
# mock(ctx.soap).body=(anything)
|
35
|
+
|
36
|
+
ctx.eval_with_delegation(&block)
|
37
|
+
|
38
|
+
validate_block.call(ctx.soap.body) if validate_block
|
39
|
+
response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
19
43
|
end
|
20
44
|
|
data/spec/rews/client_spec.rb
CHANGED
@@ -17,5 +17,309 @@ module Rews
|
|
17
17
|
|
18
18
|
client.distinguished_folder_id('inbox')
|
19
19
|
end
|
20
|
+
|
21
|
+
describe "create_item" do
|
22
|
+
def test_create_item(client, items, &validate_block)
|
23
|
+
response = Object.new
|
24
|
+
mock(response).to_hash{{:create_item_response=>{:response_messages=>{:create_item_response_message=>{:response_class=>"Success"}}}}}
|
25
|
+
|
26
|
+
RequestProxy.mock_request(self,
|
27
|
+
client,
|
28
|
+
"CreateItem",
|
29
|
+
{},
|
30
|
+
response,
|
31
|
+
&validate_block)
|
32
|
+
client.create_item(:items=>items)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create a CreateItem request and render the Items to the body" do
|
36
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
37
|
+
test_create_item(client, [[:suppress_read_receipt, [:reference_item_id, {:id=>"abc", :change_key=>"def"}]]]) do |body|
|
38
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
39
|
+
rsxml.should == ["wsdl:Items",{"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types"},
|
40
|
+
["t:SuppressReadReceipt",
|
41
|
+
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]]]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "suppress_read_receipt" do
|
47
|
+
def test_suppress_read_receipt(client, item_or_item_ids, &validate_block)
|
48
|
+
response = Object.new
|
49
|
+
mock(response).to_hash{{:create_item_response=>{:response_messages=>{:create_item_response_message=>{:response_class=>"Success"}}}}}
|
50
|
+
|
51
|
+
RequestProxy.mock_request(self,
|
52
|
+
client,
|
53
|
+
"CreateItem",
|
54
|
+
{},
|
55
|
+
response,
|
56
|
+
&validate_block)
|
57
|
+
client.suppress_read_receipt(item_or_item_ids)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should send a CreateItemRequest with SuppressReadReceipt items for each ItemId" do
|
61
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
62
|
+
test_suppress_read_receipt(client, [Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}),
|
63
|
+
Item::ItemId.new(client, {:id=>"ghi", :change_key=>"jkl"})]) do |body|
|
64
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
65
|
+
rsxml.should == ["wsdl:Items", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types"},
|
66
|
+
["t:SuppressReadReceipt",
|
67
|
+
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]],
|
68
|
+
["t:SuppressReadReceipt",
|
69
|
+
["t:ReferenceItemId", {"Id"=>"ghi", "ChangeKey"=>"jkl"}]]]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should send a CreateItemRequest with SuppressReadReceipt items for each Item" do
|
74
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
75
|
+
test_suppress_read_receipt(client, [Item::Item.new(client, 'Message', {:item_id=>{:id=>'abc', :change_key=>'def'}}),
|
76
|
+
Item::Item.new(client, 'Message', {:item_id=>{:id=>'ghi', :change_key=>'jkl'}})]) do |body|
|
77
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
78
|
+
rsxml.should == ["wsdl:Items", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types"},
|
79
|
+
["t:SuppressReadReceipt",
|
80
|
+
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]],
|
81
|
+
["t:SuppressReadReceipt",
|
82
|
+
["t:ReferenceItemId", {"Id"=>"ghi", "ChangeKey"=>"jkl"}]]]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should filter Items with IsRead=true or IsReadReceiptRequested=false before making request" do
|
87
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
88
|
+
test_suppress_read_receipt(client, [Item::Item.new(client,
|
89
|
+
'Message',
|
90
|
+
{:item_id=>{:id=>'abc', :change_key=>'def'},
|
91
|
+
:is_read=>true}),
|
92
|
+
Item::Item.new(client, 'Message', {:item_id=>{:id=>'ghi', :change_key=>'jkl'}}),
|
93
|
+
Item::Item.new(client,
|
94
|
+
'Message',
|
95
|
+
{:item_id=>{:id=>'mno', :change_key=>'pqr'},
|
96
|
+
:is_read_receipt_requested=>false})]) do |body|
|
97
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
98
|
+
rsxml.should == ["wsdl:Items", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types"},
|
99
|
+
["t:SuppressReadReceipt",
|
100
|
+
["t:ReferenceItemId", {"Id"=>"ghi", "ChangeKey"=>"jkl"}]]]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "get_item" do
|
106
|
+
def test_get_item(client, item_shape, ignore_change_keys, message_ids, result)
|
107
|
+
shape = Object.new
|
108
|
+
mock(Shape::ItemShape).new(item_shape||{}){shape}
|
109
|
+
mock(shape).to_xml{""}
|
110
|
+
|
111
|
+
message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
|
112
|
+
message_ids.each do |mid|
|
113
|
+
if mid.is_a?(Item::Item)
|
114
|
+
mock(mid.item_id).to_xml(ignore_change_keys){""}
|
115
|
+
else
|
116
|
+
mock(mid).to_xml(ignore_change_keys){""}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
response = Object.new
|
121
|
+
mock(response).to_hash{{:get_item_response=>{:response_messages=>{:get_item_response_message=>{:response_class=>"Success", :items=>result}}}}}
|
122
|
+
|
123
|
+
RequestProxy.mock_request(self, client, "GetItem", nil, response)
|
124
|
+
|
125
|
+
opts = {}
|
126
|
+
opts[:item_shape]=item_shape if item_shape
|
127
|
+
opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
|
128
|
+
client.get_item(message_ids, opts)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should generate xml including all provided ItemIds and parse response" do
|
132
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
133
|
+
items = test_get_item(client,
|
134
|
+
{:base_shape=>:IdOnly},
|
135
|
+
nil,
|
136
|
+
[Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})],
|
137
|
+
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
138
|
+
items.size.should == 1
|
139
|
+
msg=items.first
|
140
|
+
msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should generate xml ignoring change keys if requested and parsing a response with multiple items" do
|
144
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
145
|
+
items = test_get_item(client,
|
146
|
+
{:base_shape=>:Default},
|
147
|
+
true,
|
148
|
+
[Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}),
|
149
|
+
Item::ItemId.new(client, {:id=>"ghi", :change_key=>"jkl"})],
|
150
|
+
{:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
|
151
|
+
{:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]})
|
152
|
+
items.size.should == 2
|
153
|
+
items.first.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
|
154
|
+
items[1].item_id.should == Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should extract ItemIds from Items if items are provided as identifiers" do
|
158
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
159
|
+
items = test_get_item(client,
|
160
|
+
{:base_shape=>:Default},
|
161
|
+
true,
|
162
|
+
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
163
|
+
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})],
|
164
|
+
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should extract results from a FindResult if a FindResult is provided for identifiers" do
|
168
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
169
|
+
items = test_get_item(client,
|
170
|
+
{:base_shape=>:Default},
|
171
|
+
true,
|
172
|
+
Folder::FindResult.new({}) {
|
173
|
+
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
174
|
+
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]},
|
175
|
+
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
describe "update_item" do
|
182
|
+
def test_update_item(client,
|
183
|
+
conflict_resolution,
|
184
|
+
message_disposition,
|
185
|
+
ignore_change_keys,
|
186
|
+
updates,
|
187
|
+
message_ids,
|
188
|
+
&validate_block)
|
189
|
+
|
190
|
+
message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
|
191
|
+
message_ids.each do |mid|
|
192
|
+
if mid.is_a?(Item::Item)
|
193
|
+
proy(mid.item_id).to_xml(ignore_change_keys)
|
194
|
+
else
|
195
|
+
proxy(mid).to_xml(ignore_change_keys)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
response = Object.new
|
200
|
+
mock(response).to_hash{{:update_item_response=>{:response_messages=>{:update_item_response_message=>{:response_class=>"Success"}}}}}
|
201
|
+
|
202
|
+
RequestProxy.mock_request(self, client, "UpdateItem",
|
203
|
+
{ :ConflictResolution=>conflict_resolution || "AutoResolve",
|
204
|
+
:MessageDisposition=>message_disposition || "SaveOnly"},
|
205
|
+
response,
|
206
|
+
&validate_block)
|
207
|
+
|
208
|
+
opts = {}
|
209
|
+
opts[:conflict_resolution]=conflict_resolution if conflict_resolution
|
210
|
+
opts[:message_disposition]=message_disposition if message_disposition
|
211
|
+
opts[:ignore_change_keys]=ignore_change_keys if !ignore_change_keys.nil?
|
212
|
+
opts[:updates]=updates
|
213
|
+
client.update_item(message_ids, opts)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should generate body xml and parse response for a single update" do
|
217
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
218
|
+
test_update_item(client, nil, nil, nil,
|
219
|
+
SetItemField.new("message:IsRead", [:message, [:is_read, "true"]]),
|
220
|
+
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def")]) do |body|
|
221
|
+
|
222
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
|
223
|
+
Rsxml.compare(rsxml, ["wsdl:ItemChanges", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types", "xmlns"=>"ews_wsdl"},
|
224
|
+
["t:ItemChange",
|
225
|
+
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
226
|
+
["t:Updates",
|
227
|
+
["t:SetItemField",
|
228
|
+
["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
|
229
|
+
["t:Message", ["t:IsRead", "true"]]]]]]).should == true
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should generate body xml and parse response for a multiple updates of multiple items" do
|
234
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
235
|
+
test_update_item(client, nil, nil, nil,
|
236
|
+
[SetItemField.new("message:IsRead", [:message, [:is_read, "true"]]),
|
237
|
+
SetItemField.new("item:Blah", [:item, [:blah, "blah"]])],
|
238
|
+
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def"),
|
239
|
+
Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")]) do |body|
|
240
|
+
|
241
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
|
242
|
+
Rsxml.compare(rsxml, ["wsdl:ItemChanges", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types", "xmlns"=>"ews_wsdl"},
|
243
|
+
["t:ItemChange",
|
244
|
+
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
245
|
+
["t:Updates",
|
246
|
+
["t:SetItemField",
|
247
|
+
["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
|
248
|
+
["t:Message", ["t:IsRead", "true"]]],
|
249
|
+
["t:SetItemField",
|
250
|
+
["t:FieldURI", {"FieldURI"=>"item:Blah"}],
|
251
|
+
["t:Item", ["t:Blah", "blah"]]]]],
|
252
|
+
["t:ItemChange",
|
253
|
+
["t:ItemId", {"Id"=>"ghi", "ChangeKey"=>"jkl"}],
|
254
|
+
["t:Updates",
|
255
|
+
["t:SetItemField",
|
256
|
+
["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
|
257
|
+
["t:Message", ["t:IsRead", "true"]]],
|
258
|
+
["t:SetItemField",
|
259
|
+
["t:FieldURI", {"FieldURI"=>"item:Blah"}],
|
260
|
+
["t:Item", ["t:Blah", "blah"]]]]]]).should == true
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
describe "delete_item" do
|
269
|
+
def test_delete_item(client, delete_type, ignore_change_keys, message_ids)
|
270
|
+
message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
|
271
|
+
message_ids.each do |mid|
|
272
|
+
if mid.is_a?(Item::Item)
|
273
|
+
mock(mid.item_id).to_xml(ignore_change_keys){""}
|
274
|
+
else
|
275
|
+
mock(mid).to_xml(ignore_change_keys){""}
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
response = Object.new
|
280
|
+
mock(response).to_hash{{:delete_item_response=>{:response_messages=>{:delete_item_response_message=>{:response_class=>"Success"}}}}}
|
281
|
+
|
282
|
+
RequestProxy.mock_request(self, client, "DeleteItem", {:DeleteType=>delete_type}, response)
|
283
|
+
|
284
|
+
opts = {}
|
285
|
+
opts[:delete_type]=delete_type if delete_type
|
286
|
+
opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
|
287
|
+
client.delete_item(message_ids, opts)
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should generate xml including a single ItemId" do
|
291
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
292
|
+
test_delete_item(client, :HardDelete, nil, [Item::ItemId.new(client, :id=>"abc", :change_key=>"def")])
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should generate xml ignoring change keys and including multiple ItemIds" do
|
296
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
297
|
+
test_delete_item(client,
|
298
|
+
:HardDelete,
|
299
|
+
true,
|
300
|
+
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def"),
|
301
|
+
Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")])
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should extract ItemIds from Items if Items are provided as identifiers" do
|
305
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
306
|
+
test_delete_item(client,
|
307
|
+
:HardDelete,
|
308
|
+
true,
|
309
|
+
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
310
|
+
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})])
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should extract ItemIds from a FindResult if a FindResult is provided as identifiers" do
|
314
|
+
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
315
|
+
test_delete_item(client,
|
316
|
+
:HardDelete,
|
317
|
+
true,
|
318
|
+
Folder::FindResult.new({}) {[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
319
|
+
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]})
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
|
20
324
|
end
|
21
325
|
end
|
data/spec/rews/folder_spec.rb
CHANGED
@@ -88,23 +88,6 @@ module Rews
|
|
88
88
|
end
|
89
89
|
|
90
90
|
describe Folder::BaseFolderId do
|
91
|
-
def mock_request(client, action, attrs, response)
|
92
|
-
# deal with different call arity
|
93
|
-
mock(client).savon_client.mock!.request(*[:wsdl, action, attrs].compact) do |*args|
|
94
|
-
block = args.last # block is the last arg
|
95
|
-
|
96
|
-
ctx = RequestProxy.new()
|
97
|
-
mock(ctx.http).headers.mock!["SOAPAction"]="\"#{SCHEMA_MESSAGES}/#{action}\""
|
98
|
-
ns = Object.new
|
99
|
-
mock(ctx.soap).namespaces{ns}
|
100
|
-
mock(ns)["xmlns:t"]=Rews::SCHEMA_TYPES
|
101
|
-
mock(ctx.soap).body=(anything)
|
102
|
-
|
103
|
-
ctx.eval_with_delegation(&block)
|
104
|
-
response
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
91
|
describe "find_folder" do
|
109
92
|
def test_find_folder(client, folder_shape, indexed_page_folder_view, restriction, result)
|
110
93
|
shape = Object.new
|
@@ -129,7 +112,7 @@ module Rews
|
|
129
112
|
response = Object.new
|
130
113
|
mock(response).to_hash{{:find_folder_response=>{:response_messages=>{:find_folder_response_message=>{:response_class=>"Success", :root_folder=>result}}}}}
|
131
114
|
|
132
|
-
mock_request(client, "FindFolder", {"Traversal"=>"Shallow"}, response)
|
115
|
+
RequestProxy.mock_request(self, client, "FindFolder", {"Traversal"=>"Shallow"}, response)
|
133
116
|
|
134
117
|
opts = {}
|
135
118
|
opts[:folder_shape] = folder_shape if folder_shape
|
@@ -227,7 +210,7 @@ module Rews
|
|
227
210
|
response = Object.new
|
228
211
|
mock(response).to_hash{{:find_item_response=>{:response_messages=>{:find_item_response_message=>{:response_class=>"Success", :root_folder=>result}}}}}
|
229
212
|
|
230
|
-
mock_request(client, "FindItem", {"Traversal"=>"Shallow"}, response)
|
213
|
+
RequestProxy.mock_request(self, client, "FindItem", {"Traversal"=>"Shallow"}, response)
|
231
214
|
|
232
215
|
opts = {}
|
233
216
|
opts[:item_shape] = item_shape if item_shape
|
@@ -314,139 +297,8 @@ module Rews
|
|
314
297
|
end
|
315
298
|
end
|
316
299
|
|
317
|
-
describe "get_item" do
|
318
|
-
def test_get_item(client, item_shape, ignore_change_keys, message_ids, result)
|
319
|
-
shape = Object.new
|
320
|
-
mock(Shape::ItemShape).new(item_shape||{}){shape}
|
321
|
-
mock(shape).to_xml{""}
|
322
|
-
|
323
|
-
fid = Folder::DistinguishedFolderId.new(client, 'blah')
|
324
|
-
|
325
|
-
message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
|
326
|
-
message_ids.each do |mid|
|
327
|
-
if mid.is_a?(Item::Item)
|
328
|
-
mock(mid.item_id).to_xml(ignore_change_keys){""}
|
329
|
-
else
|
330
|
-
mock(mid).to_xml(ignore_change_keys){""}
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
response = Object.new
|
335
|
-
mock(response).to_hash{{:get_item_response=>{:response_messages=>{:get_item_response_message=>{:response_class=>"Success", :items=>result}}}}}
|
336
|
-
|
337
|
-
mock_request(client, "GetItem", nil, response)
|
338
|
-
|
339
|
-
opts = {}
|
340
|
-
opts[:item_shape]=item_shape if item_shape
|
341
|
-
opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
|
342
|
-
fid.get_item(message_ids, opts)
|
343
|
-
end
|
344
|
-
|
345
|
-
it "should generate xml including all provided ItemIds and parse response" do
|
346
|
-
client = Object.new
|
347
|
-
items = test_get_item(client,
|
348
|
-
{:base_shape=>:IdOnly},
|
349
|
-
nil,
|
350
|
-
[Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})],
|
351
|
-
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
352
|
-
items.size.should == 1
|
353
|
-
msg=items.first
|
354
|
-
msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
|
355
|
-
end
|
356
|
-
|
357
|
-
it "should generate xml ignoring change keys if requested and parsing a response with multiple items" do
|
358
|
-
client = Object.new
|
359
|
-
items = test_get_item(client,
|
360
|
-
{:base_shape=>:Default},
|
361
|
-
true,
|
362
|
-
[Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}),
|
363
|
-
Item::ItemId.new(client, {:id=>"ghi", :change_key=>"jkl"})],
|
364
|
-
{:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
|
365
|
-
{:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]})
|
366
|
-
items.size.should == 2
|
367
|
-
items.first.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
|
368
|
-
items[1].item_id.should == Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")
|
369
|
-
end
|
370
|
-
|
371
|
-
it "should extract ItemIds from Items if items are provided as identifiers" do
|
372
|
-
client = Object.new
|
373
|
-
items = test_get_item(client,
|
374
|
-
{:base_shape=>:Default},
|
375
|
-
true,
|
376
|
-
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
377
|
-
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})],
|
378
|
-
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should extract results from a FindResult if a FindResult is provided for identifiers" do
|
382
|
-
client = Object.new
|
383
|
-
items = test_get_item(client,
|
384
|
-
{:base_shape=>:Default},
|
385
|
-
true,
|
386
|
-
Folder::FindResult.new({}) {
|
387
|
-
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
388
|
-
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]},
|
389
|
-
{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
describe "delete_item" do
|
394
|
-
def test_delete_item(client, delete_type, ignore_change_keys, message_ids)
|
395
|
-
|
396
|
-
fid = Folder::DistinguishedFolderId.new(client, 'blah')
|
397
|
-
|
398
|
-
message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
|
399
|
-
message_ids.each do |mid|
|
400
|
-
if mid.is_a?(Item::Item)
|
401
|
-
mock(mid.item_id).to_xml(ignore_change_keys){""}
|
402
|
-
else
|
403
|
-
mock(mid).to_xml(ignore_change_keys){""}
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
response = Object.new
|
408
|
-
mock(response).to_hash{{:delete_item_response=>{:response_messages=>{:delete_item_response_message=>{:response_class=>"Success"}}}}}
|
409
|
-
|
410
|
-
mock_request(client, "DeleteItem", {:DeleteType=>delete_type}, response)
|
411
|
-
|
412
|
-
opts = {}
|
413
|
-
opts[:delete_type]=delete_type if delete_type
|
414
|
-
opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
|
415
|
-
fid.delete_item(message_ids, opts)
|
416
|
-
end
|
417
|
-
|
418
|
-
it "should generate xml including a single ItemId" do
|
419
|
-
client = Object.new
|
420
|
-
test_delete_item(client, :HardDelete, nil, [Item::ItemId.new(client, :id=>"abc", :change_key=>"def")])
|
421
|
-
end
|
422
|
-
|
423
|
-
it "should generate xml ignoring change keys and including multiple ItemIds" do
|
424
|
-
client = Object.new
|
425
|
-
test_delete_item(client,
|
426
|
-
:HardDelete,
|
427
|
-
true,
|
428
|
-
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def"),
|
429
|
-
Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")])
|
430
|
-
end
|
431
300
|
|
432
|
-
it "should extract ItemIds from Items if Items are provided as identifiers" do
|
433
|
-
client = Object.new
|
434
|
-
test_delete_item(client,
|
435
|
-
:HardDelete,
|
436
|
-
true,
|
437
|
-
[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
438
|
-
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})])
|
439
|
-
end
|
440
301
|
|
441
|
-
it "should extract ItemIds from a FindResult if a FindResult is provided as identifiers" do
|
442
|
-
client = Object.new
|
443
|
-
test_delete_item(client,
|
444
|
-
:HardDelete,
|
445
|
-
true,
|
446
|
-
Folder::FindResult.new({}) {[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
|
447
|
-
Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]})
|
448
|
-
end
|
449
|
-
end
|
450
302
|
end
|
451
303
|
end
|
452
304
|
end
|