ECS 0.1.5 → 0.1.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.
@@ -0,0 +1,78 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require "#{File.expand_path( File.dirname( __FILE__ ) )}/../unit_test_setup"
5
+
6
+
7
+ class ECSHelpResponseGroupTest < Test::Unit::TestCase
8
+ def setup
9
+ end
10
+ def teardown
11
+ end
12
+
13
+
14
+ def test_exists
15
+ assert_nothing_raised do
16
+ ECS::HelpResponseGroup
17
+ end
18
+ end
19
+
20
+
21
+ def test_simple
22
+ a = ECS.request_response_group
23
+
24
+ assert_equal 'RequestResponseGroup', a.response_group_name
25
+ assert a.valid_operations.size > 0
26
+
27
+ assert !ECS::ResponseGroups[a.response_group_name].nil?, "#{a.response_group_name} not included in #{ECS::ResponseGroups.keys.join( ', ' )}"
28
+ end
29
+
30
+
31
+ def test_valid_operations
32
+ assert_equal Array, ECS::HelpResponseGroup.valid_operations.class
33
+ assert_equal [ :Help ], ECS::HelpResponseGroup.valid_operations.map{ |p| p.to_s }.sort.map{ |p| p.to_sym }
34
+ assert_equal Array, ECS::HelpResponseGroup.valid_operations( true ).class
35
+ end
36
+
37
+ def test_elements
38
+ assert_equal Array, ECS::HelpResponseGroup.elements.class
39
+ assert ECS::HelpResponseGroup.elements.size > 0
40
+ ECS::HelpResponseGroup.elements.each do |e|
41
+ assert_equal Proc, e.class
42
+ end
43
+ assert_equal Array, ECS::HelpResponseGroup.elements( true ).class
44
+ end
45
+
46
+
47
+ def test_help_xml
48
+ a = ECS.request_response_group
49
+ assert_equal XML::Document, a.help_xml.class
50
+ assert a.help_xml.to_s.length > 0
51
+ end
52
+
53
+ def test_response_group_name
54
+ string_to_eval = "class ECS::CrazyResponseGroup < ECS::HelpResponseGroup ; @@response_group_name=nil ; ECS::ResponseGroups['CrazyResponseGroup'] = self ; end ; ECS::CrazyResponseGroup"
55
+ assert_nothing_raised do
56
+ eval( string_to_eval, binding, __FILE__, __LINE__ )
57
+ end
58
+
59
+ klass = ECS::ResponseGroups['CrazyResponseGroup']
60
+
61
+ assert_match /.+::CrazyResponseGroup$/, klass.name
62
+ assert_equal 'CrazyResponseGroup', klass.response_group_name
63
+ end
64
+
65
+ def test_aws_response_group_name
66
+ string_to_eval = "class ECS::CrazyResponseGroup < ECS::HelpResponseGroup ; @@response_group_name=nil ; ECS::ResponseGroups['CrazyResponseGroup'] = self ; end ; ECS::CrazyResponseGroup"
67
+ assert_nothing_raised do
68
+ eval( string_to_eval, binding, __FILE__, __LINE__ )
69
+ end
70
+
71
+ klass = ECS::ResponseGroups['CrazyResponseGroup']
72
+
73
+ assert_match /.+::CrazyResponseGroup$/, klass.name
74
+ assert_equal 'Crazy', klass.aws_response_group_name
75
+ end
76
+ end
77
+
78
+
@@ -0,0 +1,696 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require "#{File.expand_path( File.dirname( __FILE__ ) )}/../unit_test_setup"
5
+
6
+ class ECSBrowseNodeLookupTest < Test::Unit::TestCase
7
+ def setup
8
+ ECS.default_locale = :us
9
+ end
10
+ def teardown
11
+ ECS.clear_cache
12
+ end
13
+
14
+
15
+ def test_exists
16
+ assert_nothing_raised do
17
+ ECS::Help
18
+ end
19
+ assert( ECS::Operations.o_include?( :Help ), "#{ECS::Operations.keys.join(', ')} (no ECS::Help)" )
20
+ end
21
+
22
+ def test_required_parameters
23
+ assert_equal Array, ECS::Help.required_parameters.class
24
+ assert_equal [ :About, :HelpType ], ECS::Help.required_parameters.map{ |p| p.to_s }.sort.map{ |p| p.to_sym }
25
+ assert_equal Array, ECS::Help.required_parameters( true ).class
26
+ end
27
+
28
+ def test_missing_required_parameters
29
+ x = nil
30
+ x = ECS.customer_content_search( :Name => 'wzph' )
31
+ assert_nothing_raised do
32
+ #The help for CustomerContentSearch has no RequiredParameters
33
+ x.class.required_parameters
34
+ end
35
+ assert x.xml.to_s !~ /<RequiredParameters>/
36
+ end
37
+
38
+ def test_cached_content
39
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
40
+
41
+ assert_equal nil, h.cached_content
42
+
43
+ assert_nothing_raised do
44
+ h.xml.to_s
45
+ end
46
+
47
+ assert h.xml.to_s, h.cached_content.to_s
48
+ assert h.cached_content.to_s.length > 0
49
+ end
50
+
51
+ def test_cached?
52
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
53
+
54
+ assert !h.cached?
55
+
56
+ assert_nothing_raised do
57
+ h.xml
58
+ end
59
+
60
+ assert h.cached?
61
+ end
62
+ def test_parameters_for_xml
63
+ p = { :HelpType => 'Operation', :About => 'BrowseNodeLookup' }
64
+
65
+ h = ECS.help( p )
66
+
67
+ assert_equal p.merge( :Operation => 'Help' ), h.parameters_for_xml
68
+ end
69
+
70
+
71
+ def test_available_parameters
72
+ assert_equal Array, ECS::Help.available_parameters.class
73
+ assert_equal [ :AssociateTag, :ContentType, :Marketplace, :MarketplaceDomain, :Style, :Validate, :Version, :XMLEscaping ], ECS::Help.available_parameters.map{ |p| p.to_s }.sort.map{ |p| p.to_sym }
74
+ assert_equal Array, ECS::Help.available_parameters( true ).class
75
+ end
76
+
77
+ def test_optional_parameters
78
+ assert_equal ECS::Help.available_parameters, ECS::Help.optional_parameters
79
+ end
80
+
81
+ def test_default_response_groups
82
+ assert_equal Array, ECS::Help.default_response_groups.class
83
+ assert_equal [ :HelpResponseGroup, :RequestResponseGroup ], ECS::Help.default_response_groups.map{ |p| p.response_group_name.to_s }.sort.map{ |p| p.to_sym }
84
+ assert_equal Array, ECS::Help.default_response_groups( true ).class
85
+ end
86
+
87
+ def test_available_response_groups
88
+ assert_equal Array, ECS::Help.available_response_groups.class
89
+ assert_equal [ :HelpResponseGroup, :RequestResponseGroup ], ECS::Help.available_response_groups.map{ |p| p.response_group_name.to_s }.sort.map{ |p| p.to_sym }
90
+ assert_equal Array, ECS::Help.available_response_groups( true ).class
91
+ end
92
+
93
+
94
+ def test_operation_name
95
+ assert_equal 'Help', ECS::Help.operation_name
96
+ b = ECS.browse_node_lookup( :BrowseNodeId => 23 )
97
+
98
+ assert_equal 'BrowseNodeLookup', b.class.operation_name
99
+
100
+ end
101
+
102
+ def test_subclass
103
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
104
+ b = ECS.browse_node_lookup( :BrowseNodeId => 23 )
105
+ assert_not_equal h.class.help_xml.to_s, b.class.help_xml.to_s
106
+ end
107
+
108
+ def test_simple
109
+ h = nil
110
+
111
+ assert_nothing_raised do
112
+ h = ECS.help( :About => 'BrowseNodeLookup', :HelpType => 'Operation' )
113
+ h.xml
114
+ end
115
+
116
+ assert_match /::Help$/, h.class.name
117
+ assert_equal Array, h.class.required_parameters.class
118
+ assert_equal Array, h.class.available_parameters.class
119
+ assert_equal Array, h.class.default_response_groups.class
120
+ assert_equal Array, h.class.available_response_groups.class
121
+ end
122
+
123
+ def test_help_xml
124
+ assert_equal XML::Document, ECS::Help.help_xml.class
125
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
126
+ assert_equal XML::Document, h.help_xml.class
127
+
128
+ assert_equal ECS::Help.help_xml.to_s, h.help_xml.to_s
129
+
130
+ assert_equal XML::Document, ECS::Help.help_xml( true ).class
131
+ end
132
+
133
+ def test_xml
134
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
135
+ assert_nothing_raised do
136
+ h.xml
137
+ end
138
+
139
+ assert_equal XML::Document, h.xml.class
140
+ assert_equal XML::Document, h.xml( true ).class
141
+
142
+
143
+ h = ECS.help( :HelpType => 'Operation' )
144
+ assert_raises ArgumentError do
145
+ h.xml
146
+ end
147
+ end
148
+
149
+ def test_potential_elements
150
+ h = ECS.browse_node_lookup( :BrowseNodeId => 22 )
151
+ assert_equal Array, h.potential_elements.class
152
+ assert h.potential_elements.size > 0
153
+ h.response_groups.each do |response_group|
154
+ response_group.elements.each do |element|
155
+ assert h.potential_elements.include?( element )
156
+ assert_nothing_raised do
157
+ element.call( h )
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ def test_method_missing
164
+ h = ECS.browse_node_lookup( :BrowseNodeId => 22 )
165
+ assert !h.respond_to?( :IsValid )
166
+ assert_nothing_raised do
167
+ h.IsValid
168
+ end
169
+ assert h.respond_to?( :IsValid )
170
+
171
+ assert_nothing_raised do
172
+ h.IsValid( true )
173
+ end
174
+
175
+ assert_equal XML::Node, h.IsValid.class
176
+ assert_equal 'True', h.IsValid.content
177
+
178
+ assert_equal XML::Node::Set, h.Argument.class
179
+ assert h.Argument.size > 3
180
+
181
+ assert_equal XML::Node, h.Arguments.class
182
+
183
+
184
+ h = ECS.something_silly
185
+ assert !h.respond_to?( :IsValid )
186
+ assert_nothing_raised do
187
+ h.IsValid
188
+ end
189
+ assert h.respond_to?( :IsValid )
190
+
191
+ assert_equal XML::Node::Set, h.IsValid.class
192
+ assert_equal 0, h.IsValid.size
193
+ end
194
+
195
+ def test_method_missing_each
196
+ h = ECS.browse_node_lookup( :BrowseNodeId => 22 )
197
+ assert !h.respond_to?( :each_IsValid )
198
+ assert_nothing_raised do
199
+ h.each_IsValid # no block
200
+ end
201
+ assert h.respond_to?( :each_IsValid )
202
+
203
+ x = 1
204
+ h.each_IsValid { |i| x += 1 }
205
+ assert_equal 1, x
206
+
207
+ h = ECS.browse_node_lookup( :BrowseNodeId => 22 )
208
+ assert !h.respond_to?( :each_IsValid )
209
+ assert_equal 1, x
210
+ assert_nothing_raised do
211
+ h.each_IsValid { |i| x += 1 }
212
+ end
213
+ assert_equal 2, x
214
+ assert !h.respond_to?( :each_IsValid )
215
+
216
+
217
+ h.each_Argument { |argument| assert_equal XML::Node, argument.class }
218
+
219
+
220
+ h = ECS.something_else_crazy( :BrowseNodeId => 22 )
221
+ assert !h.respond_to?( :each_IsValid )
222
+ assert_nothing_raised do
223
+ h.each_IsValid # no block
224
+ end
225
+ assert h.respond_to?( :each_IsValid )
226
+
227
+
228
+ book_response = ECS.item_lookup( :ItemId => '0812970802' )
229
+ i = 0
230
+ book_response.each_Author do |author|
231
+ i += 1
232
+ assert_equal 'Lauren F. Winner', author.content
233
+ end
234
+
235
+ assert_equal 1, i
236
+ end
237
+
238
+
239
+ def test_method_missing_count
240
+ book_response = ECS.item_lookup( :ItemId => '0812970802' )
241
+ assert_equal 6, book_response.Argument_count
242
+ assert_equal 1, book_response.Author_count
243
+ assert_equal 0, book_response.Nothing_count
244
+ end
245
+
246
+ # def test_response_groups
247
+ # h1 = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup', :ResponseGroup => ['Request', 'Help'] )
248
+ # assert_equal Array, h1.response_groups.class
249
+ # assert_equal 2, h1.response_groups.size
250
+ # h1.response_groups.each do |rg|
251
+ # assert rg.ancestors.include?( ECS::HelpResponseGroup )
252
+ # end
253
+ #
254
+ # assert_nothing_raised do
255
+ # h1.response_groups( true )
256
+ # end
257
+ #
258
+ # h2 = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
259
+ # assert_equal Array, h2.response_groups.class
260
+ # assert_equal 2, h2.response_groups.size
261
+ # h2.response_groups.each do |rg|
262
+ # assert rg.ancestors.include?( ECS::HelpResponseGroup )
263
+ # end
264
+ # assert_equal h2.class.default_response_groups, h2.response_groups
265
+ # assert_equal h1.response_groups, h2.response_groups
266
+ #
267
+ # h3 = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup', :ResponseGroup => 'Request' )
268
+ # assert_equal Array, h3.response_groups.class
269
+ # assert_equal 1, h3.response_groups.size
270
+ # h3.response_groups.each do |rg|
271
+ # assert rg.ancestors.include?( ECS::HelpResponseGroup )
272
+ # end
273
+ # assert_not_equal h1.response_groups, h3.response_groups
274
+ # end
275
+
276
+
277
+
278
+
279
+ def test_valid?
280
+ h = ECS.something_ridiculous
281
+ assert !h.valid?
282
+
283
+ h = ECS.help( :HelpType => 'Operation', :About => 'NOTHING' )
284
+ assert !h.valid?
285
+
286
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
287
+ assert h.valid?
288
+ end
289
+
290
+ def test_errors_from_aws
291
+ x = XML::Parser.new
292
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
293
+ <ItemLookupResponse>
294
+ <OperationRequest>
295
+ <HTTPHeaders>
296
+ <Header Name="UserAgent"/>
297
+ </HTTPHeaders>
298
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
299
+ <Arguments>
300
+ <Argument Name="Service" Value="AWSECommerceService"/>
301
+ </Arguments>
302
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
303
+ </OperationRequest>
304
+ <Items>
305
+ <Request>
306
+ <IsValid>False</IsValid>
307
+ <Errors>
308
+ <Error>
309
+ <Code>AWS.MissingParameters</Code>
310
+ <Message>Your request is missing required parameters. Required parameters include ItemId.</Message>
311
+ </Error>
312
+ </Errors>
313
+ </Request>
314
+ </Items>
315
+ </ItemLookupResponse>'
316
+ d = x.parse
317
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
318
+ assert_equal 1, ECS::Help.errors_from_aws( d ).size
319
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d ).first.message
320
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
321
+ assert_equal 1, ECS::Help.errors_from_aws( d.to_s ).size
322
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d.to_s ).first.message
323
+
324
+
325
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
326
+ <ItemLookupResponse>
327
+ <OperationRequest>
328
+ <HTTPHeaders>
329
+ <Header Name="UserAgent"/>
330
+ </HTTPHeaders>
331
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
332
+ <Arguments>
333
+ <Argument Name="Service" Value="AWSECommerceService"/>
334
+ </Arguments>
335
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
336
+ </OperationRequest>
337
+ <Items>
338
+ <Request>
339
+ <IsValid>True</IsValid>
340
+ <Errors>
341
+ <Error>
342
+ <Code>AWS.MissingParameters</Code>
343
+ <Message>Your request is missing required parameters. Required parameters include ItemId.</Message>
344
+ </Error>
345
+ </Errors>
346
+ </Request>
347
+ </Items>
348
+ </ItemLookupResponse>'
349
+ d = x.parse
350
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
351
+ assert_equal 1, ECS::Help.errors_from_aws( d ).size
352
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d ).first.message
353
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
354
+ assert_equal 1, ECS::Help.errors_from_aws( d.to_s ).size
355
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d.to_s ).first.message
356
+
357
+
358
+
359
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Error>Bad Error!</Error></Errors>'
360
+ d = x.parse
361
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
362
+ assert_equal 0, ECS::Help.errors_from_aws( d ).size
363
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
364
+ assert_equal 0, ECS::Help.errors_from_aws( d.to_s ).size
365
+
366
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Error><Code>Good Error</Code><Message>This is a good error</Message></Error></Errors>'
367
+ d = x.parse
368
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
369
+ assert_equal 1, ECS::Help.errors_from_aws( d ).size
370
+ assert_match /^This is a good error/, ECS::Help.errors_from_aws( d ).first.message
371
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
372
+ assert_equal 1, ECS::Help.errors_from_aws( d.to_s ).size
373
+ assert_match /^This is a good error/, ECS::Help.errors_from_aws( d.to_s ).first.message
374
+
375
+
376
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
377
+ <BrowseNodeLookupResponse>
378
+ <OperationRequest>
379
+ <HTTPHeaders>
380
+ <Header Name="UserAgent"/>
381
+ </HTTPHeaders>
382
+ <RequestId>10931PRERC228G0J80WW</RequestId>
383
+ <Arguments>
384
+ <Argument Name="Service" Value="AWSECommerceService"/>
385
+ <Argument Name="Operation" Value="BrowseNodeLookup"/>
386
+ <Argument Name="HelpType" Value="Operation"/>
387
+ <Argument Name="AWSAccessKeyId" Value=""/>
388
+ <Argument Name="About" Value="BrowseNodeLookup"/>
389
+ </Arguments>
390
+ <RequestProcessingTime>0.0036160945892334</RequestProcessingTime>
391
+ </OperationRequest>
392
+ <BrowseNodes>
393
+ <Request>
394
+ <IsValid>False</IsValid>
395
+ <Errors>
396
+ <Error>
397
+ <Code>AWS.MissingParameters</Code>
398
+ <Message>Your request is missing required parameters. Required parameters include BrowseNodeId.</Message>
399
+ </Error>
400
+ </Errors>
401
+ </Request>
402
+ </BrowseNodes>
403
+ </BrowseNodeLookupResponse>'
404
+ d = x.parse
405
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
406
+ assert_equal 1, ECS::Help.errors_from_aws( d ).size
407
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d ).first.message
408
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
409
+ assert_equal 1, ECS::Help.errors_from_aws( d.to_s ).size
410
+ assert_match /^Your request is missing required parameters/, ECS::Help.errors_from_aws( d.to_s ).first.message
411
+
412
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
413
+ <ItemLookupResponse>
414
+ <OperationRequest>
415
+ <HTTPHeaders>
416
+ <Header Name="UserAgent"/>
417
+ </HTTPHeaders>
418
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
419
+ <Arguments>
420
+ <Argument Name="Service" Value="AWSECommerceService"/>
421
+ </Arguments>
422
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
423
+ </OperationRequest>
424
+ <Items>
425
+ <Request>
426
+ <IsValid>True</IsValid>
427
+ </Request>
428
+ </Items>
429
+ </ItemLookupResponse>'
430
+ d = x.parse
431
+ assert_equal Array, ECS::Help.errors_from_aws( d ).class
432
+ assert_equal 0, ECS::Help.errors_from_aws( d ).size
433
+ assert_equal Array, ECS::Help.errors_from_aws( d.to_s ).class
434
+ assert_equal 0, ECS::Help.errors_from_aws( d.to_s ).size
435
+ end
436
+
437
+ def test_valid_aws_response?
438
+ x = XML::Parser.new
439
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
440
+ <ItemLookupResponse>
441
+ <OperationRequest>
442
+ <HTTPHeaders>
443
+ <Header Name="UserAgent"/>
444
+ </HTTPHeaders>
445
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
446
+ <Arguments>
447
+ <Argument Name="Service" Value="AWSECommerceService"/>
448
+ </Arguments>
449
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
450
+ </OperationRequest>
451
+ <Items>
452
+ <Request>
453
+ <IsValid>False</IsValid>
454
+ <Errors>
455
+ <Error>
456
+ <Code>AWS.MissingParameters</Code>
457
+ <Message>Your request is missing required parameters. Required parameters include ItemId.</Message>
458
+ </Error>
459
+ </Errors>
460
+ </Request>
461
+ </Items>
462
+ </ItemLookupResponse>'
463
+ d = x.parse
464
+ assert !ECS::Help.valid_aws_response?( d )
465
+ assert !ECS::Help.valid_aws_response?( d.to_s )
466
+
467
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
468
+ <ItemLookupResponse>
469
+ <OperationRequest>
470
+ <HTTPHeaders>
471
+ <Header Name="UserAgent"/>
472
+ </HTTPHeaders>
473
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
474
+ <Arguments>
475
+ <Argument Name="Service" Value="AWSECommerceService"/>
476
+ </Arguments>
477
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
478
+ </OperationRequest>
479
+ <Items>
480
+ <Request>
481
+ <IsValid>True</IsValid>
482
+ <Errors>
483
+ <Error>
484
+ <Code>AWS.MissingParameters</Code>
485
+ <Message>Your request is missing required parameters. Required parameters include ItemId.</Message>
486
+ </Error>
487
+ </Errors>
488
+ </Request>
489
+ </Items>
490
+ </ItemLookupResponse>'
491
+ d = x.parse
492
+ assert !ECS::Help.valid_aws_response?( d )
493
+ assert !ECS::Help.valid_aws_response?( d.to_s )
494
+
495
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Error>Nutty!</Error></Errors>'
496
+ d = x.parse
497
+ assert ECS::Help.valid_aws_response?( d )
498
+ assert ECS::Help.valid_aws_response?( d.to_s )
499
+
500
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Request><IsValid>False</IsValid></Request><Error>Nutty!</Error></Errors>'
501
+ d = x.parse
502
+ assert !ECS::Help.valid_aws_response?( d )
503
+ assert !ECS::Help.valid_aws_response?( d.to_s )
504
+
505
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Request><IsValid>false</IsValid></Request><Error>Nutty!</Error></Errors>'
506
+ d = x.parse
507
+ assert !ECS::Help.valid_aws_response?( d )
508
+ assert !ECS::Help.valid_aws_response?( d.to_s )
509
+
510
+ x.string = '<?xml version="1.0" encoding="UTF-8"?><Errors><Error><Code>Good Error</Code><Message>This is a good error</Message></Error></Errors>'
511
+ d = x.parse
512
+ assert !ECS::Help.valid_aws_response?( d )
513
+ assert !ECS::Help.valid_aws_response?( d.to_s )
514
+
515
+
516
+
517
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
518
+ <BrowseNodeLookupResponse>
519
+ <OperationRequest>
520
+ <HTTPHeaders>
521
+ <Header Name="UserAgent"/>
522
+ </HTTPHeaders>
523
+ <RequestId>10931PRERC228G0J80WW</RequestId>
524
+ <Arguments>
525
+ <Argument Name="Service" Value="AWSECommerceService"/>
526
+ <Argument Name="Operation" Value="BrowseNodeLookup"/>
527
+ <Argument Name="HelpType" Value="Operation"/>
528
+ <Argument Name="AWSAccessKeyId" Value=""/>
529
+ <Argument Name="About" Value="BrowseNodeLookup"/>
530
+ </Arguments>
531
+ <RequestProcessingTime>0.0036160945892334</RequestProcessingTime>
532
+ </OperationRequest>
533
+ <BrowseNodes>
534
+ <Request>
535
+ <IsValid>False</IsValid>
536
+ <Errors>
537
+ <Error>
538
+ <Code>AWS.MissingParameters</Code>
539
+ <Message>Your request is missing required parameters. Required parameters include BrowseNodeId.</Message>
540
+ </Error>
541
+ </Errors>
542
+ </Request>
543
+ </BrowseNodes>
544
+ </BrowseNodeLookupResponse>'
545
+ d = x.parse
546
+ assert !ECS::Help.valid_aws_response?( d )
547
+ assert !ECS::Help.valid_aws_response?( d.to_s )
548
+
549
+ x.string = '<?xml version="1.0" encoding="UTF-8"?>
550
+ <ItemLookupResponse>
551
+ <OperationRequest>
552
+ <HTTPHeaders>
553
+ <Header Name="UserAgent"/>
554
+ </HTTPHeaders>
555
+ <RequestId>073636SFEVZ21RFTY5N7</RequestId>
556
+ <Arguments>
557
+ <Argument Name="Service" Value="AWSECommerceService"/>
558
+ </Arguments>
559
+ <RequestProcessingTime>0.00560617446899414</RequestProcessingTime>
560
+ </OperationRequest>
561
+ <Items>
562
+ <Request>
563
+ <IsValid>True</IsValid>
564
+ </Request>
565
+ </Items>
566
+ </ItemLookupResponse>'
567
+ d = x.parse
568
+ assert ECS::Help.valid_aws_response?( d )
569
+ assert ECS::Help.valid_aws_response?( d.to_s )
570
+ end
571
+
572
+
573
+
574
+ def test_errors
575
+ h = ECS.something_ridiculous
576
+ assert_equal 1, h.errors.size
577
+ assert_equal RuntimeError, h.errors.first.class
578
+ assert_match /^The Operation parameter is invalid\. Please modify the Operation parameter and retry\. Valid values for the Operation parameter/, h.errors.first.message
579
+
580
+ h = ECS.help( :HelpType => 'Operation' )
581
+ assert_raises ArgumentError do
582
+ h.errors
583
+ end
584
+
585
+ h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
586
+ assert_equal 0, h.errors.size
587
+ end
588
+
589
+
590
+
591
+ def test_headers
592
+ h = ECS.help( :About => 'BrowseNodeInfo', :HelpType => 'ResponseGroup' )
593
+ assert_equal Hash, h.headers.class
594
+ assert_equal 1, h.headers.size
595
+ assert defined?( h.headers[:UserAgent] )
596
+ assert_equal '', h.headers[:UserAgent]
597
+
598
+ assert_nothing_raised do
599
+ h.headers( true )
600
+ end
601
+
602
+ h = ECS.something_silly
603
+ assert_equal Hash, h.headers.class
604
+ assert_equal 0, h.headers.size
605
+ end
606
+
607
+
608
+ def test_headers
609
+ h = ECS.help( :About => 'BrowseNodeInfo', :HelpType => 'ResponseGroup' )
610
+ assert_equal String, h.request_id.class
611
+ assert h.request_id.length
612
+
613
+ assert_nothing_raised do
614
+ h.request_id( true )
615
+ end
616
+
617
+ h = ECS.something_silly
618
+ assert_equal 'Could not determine request_id', h.request_id
619
+ end
620
+
621
+
622
+ def test_arguments
623
+ h = ECS.help( :About => 'BrowseNodeInfo', :HelpType => 'ResponseGroup' )
624
+ assert_equal Hash, h.arguments.class
625
+ assert_equal 7, h.arguments.size
626
+ args = h.arguments
627
+ args.delete( :AWSAccessKeyId )
628
+ assert_equal( {
629
+ :About=>"BrowseNodeInfo",
630
+ :Operation=>"Help",
631
+ :HelpType=>"ResponseGroup",
632
+ :Service=>"AWSECommerceService",
633
+ :Version=>"2007-02-22",
634
+ :AssociateTag=>ECS.associate_id
635
+ }, args )
636
+
637
+ assert_nothing_raised do
638
+ h.arguments( true )
639
+ end
640
+
641
+ h = ECS.something_silly
642
+ assert_equal Hash, h.arguments.class
643
+ assert_equal 0, h.arguments.size
644
+ end
645
+
646
+ def test_processing_time
647
+ h = ECS.help( :About => 'BrowseNodeInfo', :HelpType => 'ResponseGroup' )
648
+ assert_equal Float, h.request_processing_time.class
649
+ assert h.request_processing_time > 0.0
650
+
651
+ assert_nothing_raised do
652
+ h.request_processing_time( true )
653
+ end
654
+
655
+ h = ECS.something_silly
656
+ assert_in_delta -1.0, h.request_processing_time, 0.00001
657
+ end
658
+
659
+
660
+ def test_miscellaneous
661
+ book = ECS.item_lookup( :ItemId => '0974514055', :ResponseGroup => [ 'Large', 'Offers' ] )
662
+ assert_nothing_raised do
663
+ book.ItemAttributes.Title.content
664
+ end
665
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", ( book.ItemAttributes.Title.content =~ /^(.*?),\s+(the)$/i ? "#{$2} #{$1}" : book.ItemAttributes.Title.content )
666
+ end
667
+
668
+ def test_to_yaml
669
+ help = ECS.help( :HelpType => 'Operation', :About => 'Help' )
670
+ help_yaml = ''
671
+ assert_nothing_raised do
672
+ help_yaml = help.to_yaml
673
+ end
674
+
675
+ restored_help = YAML::load( help_yaml )
676
+ assert_equal help.operation_name, restored_help.operation_name
677
+
678
+ book = ECS.item_lookup( :ItemId => '0974514055', :ResponseGroup => [ 'Large', 'Offers' ] )
679
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", ( book.ItemAttributes.Title.content =~ /^(.*?),\s+(the)$/i ? "#{$2} #{$1}" : book.ItemAttributes.Title.content )
680
+
681
+ book_yaml = ''
682
+ assert_nothing_raised do
683
+ book_yaml = book.to_yaml
684
+ end
685
+
686
+ restored_book = YAML::load( book_yaml )
687
+ assert_equal restored_book.class, book.class
688
+
689
+ assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", ( restored_book.ItemAttributes.Title.content =~ /^(.*?),\s+(the)$/i ? "#{$2} #{$1}" : restored_book.ItemAttributes.Title.content )
690
+
691
+ unknown_yaml = "--- !ecs.rubyforge.org,2007/help:#<Class:0x6b2520>::SimilarityLookup \nparameters: \n :ItemId: 0974514055\noperation_name: similarity_lookup\n"
692
+ restored_similarity_lookup = YAML::load( unknown_yaml )
693
+ assert_equal 'SimilarityLookup', restored_similarity_lookup.operation_name
694
+ end
695
+
696
+ end