ECS 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require "#{File.expand_path( File.dirname( __FILE__ ) )}/unit_test_setup"
5
+
6
+ require 'benchmark'
7
+
8
+ class LibxmlTest < Test::Unit::TestCase
9
+ def setup
10
+ @document = XML::Parser.new
11
+ @document.string = ('<?xml version="1.0" encoding="ISO-8859-1"?>
12
+ <book>
13
+ <title>When Bad Code Happens To Good Programmers</title>
14
+ <author>Don Knuth</author>
15
+ <price>$3.16<currency>USD</currency></price>
16
+ <pages>316</pages>
17
+ </book>
18
+ ')
19
+ @document = @document.parse
20
+ end
21
+ def teardown
22
+ end
23
+
24
+
25
+
26
+ def test_method_missing
27
+ assert_nothing_raised do
28
+ @document.book
29
+ @document.book.author
30
+ end
31
+ assert_equal XML::Node, @document.book.class
32
+ assert_equal XML::Node, @document.book.class
33
+ assert_equal XML::Node, @document.book.author.class
34
+ assert_equal 'Don Knuth', @document.book.author.content
35
+ assert_raises NoMethodError do
36
+ assert_equal 'Don Knuth', @document.author.content
37
+ end
38
+ end
39
+
40
+ def test_text_and_node_inside_node
41
+ assert_equal 'USD', @document.book.price.currency.content
42
+ assert_equal 'USD', @document.book.price.currency.content.to_s
43
+ end
44
+
45
+ def test_amazon_wsdl
46
+ wsdl = XML::Document.file( File.join( File.dirname( __FILE__ ), 'AWSECommerceService.wsdl' ) )
47
+ assert_equal XML::Document, wsdl.class
48
+ assert_equal XML::Node, wsdl.definitions.class
49
+ assert_equal XML::Node, wsdl.definitions.types.class
50
+ assert_equal Array, wsdl.definitions.message.class
51
+ wsdl.definitions.message.each do |m|
52
+ assert_equal XML::Node, m.class
53
+ end
54
+ end
55
+
56
+ def test_name_collision
57
+ # Make sure that the method gets created
58
+ b = @document.book
59
+ assert !b.respond_to?( :author )
60
+ b.author
61
+ assert_respond_to b, :author
62
+
63
+ # Make sure we can call *_in_the_xml to avoid collisions with existing methods
64
+ assert !b.respond_to?( :author_in_the_xml )
65
+ b.author_in_the_xml
66
+ assert_respond_to b, :author_in_the_xml
67
+
68
+ # Make sure * and *_in_the_xml are the same
69
+ assert_equal b.author, b.author_in_the_xml
70
+
71
+ # Make sure that the created instance method is actually called with the variable is nil
72
+ b.instance_variable_set( '@author_var', nil )
73
+ assert_equal nil, b.instance_variable_get( '@author_var' )
74
+ b.author
75
+ assert_equal 'Don Knuth', b.instance_variable_get( '@author_var' ).content
76
+ end
77
+
78
+
79
+ def test_trigger_no_method_error_in_node
80
+ a = @document.book.author
81
+ assert_nothing_raised do
82
+ a.funky_town
83
+ end
84
+
85
+ assert_equal [], a.funky_town
86
+ end
87
+
88
+ def test_trigger_no_method_error_in_document
89
+ assert_raises NoMethodError do
90
+ @document.funky_town
91
+ end
92
+ end
93
+
94
+ def test_broken_find
95
+ x = XML::Parser.new
96
+ x.string ='<?xml version="1.0" encoding="UTF-8"?>
97
+ <HelpResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
98
+ <OperationRequest>
99
+ <RequestId>0F29BV61VZR2BZ7TZ6QS</RequestId>
100
+ </OperationRequest>
101
+ </HelpResponse>'
102
+ d = x.parse
103
+ assert_equal XML::Node::Set, d.find( '//RequestId' ).class
104
+ assert_equal 0, d.find( '//RequestId' ).size, "It looks like your XML::Document.find() is working with the namespace coming from Amazon. You *might* want to think about setting ECS.strip_namespace = false"
105
+
106
+
107
+ #Note the only difference is the missing namespace
108
+ x.string ='<?xml version="1.0" encoding="UTF-8"?>
109
+ <HelpResponse>
110
+ <OperationRequest>
111
+ <RequestId>0F29BV61VZR2BZ7TZ6QS</RequestId>
112
+ </OperationRequest>
113
+ </HelpResponse>'
114
+ d = x.parse
115
+
116
+ assert_equal XML::Node::Set, d.find( '//RequestId' ).class
117
+ assert_equal 1, d.find( '//RequestId' ).size
118
+ assert_equal '0F29BV61VZR2BZ7TZ6QS', d.find('//RequestId').first.content
119
+ end
120
+ end
121
+
@@ -0,0 +1,27 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require "#{File.expand_path( File.dirname( __FILE__ ) )}/unit_test_setup"
5
+
6
+ class StringTest < Test::Unit::TestCase
7
+ def setup
8
+ end
9
+ def teardown
10
+ end
11
+
12
+ def test_camel_case
13
+ assert_equal 'ThisIsCamelCase', 'this is camel CASE'.camel_case
14
+ assert_equal 'ThisIsCamelCase', 'ThisIsCamelCase'.camel_case
15
+ assert_equal 'ThisIsCamelCase', 'this_is_camel_case'.camel_case
16
+ assert_equal 'AbcDeFghI', 'abc_de_fgh_i'.camel_case
17
+ end
18
+
19
+ def test_underscore
20
+ assert_equal 'this_is_under_score', 'this is underSCORE'.underscore
21
+ assert_equal 'this_is_underscore', 'this_is_underscore'.underscore
22
+ assert_equal 'this_is_underscore', 'ThisIsUnderscore'.underscore
23
+ assert_equal 'abc_de_fgh_i', 'AbcDeFghI'.underscore
24
+ assert_equal 'abc_de_fgh_i', 'AbcDEFghI'.underscore
25
+ end
26
+ end
27
+
@@ -0,0 +1,40 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ dir = File.expand_path( File::dirname( __FILE__ ) )
4
+ require "#{dir}/../../lib/ecs.rb"
5
+
6
+ #############################
7
+ # Change these parameters
8
+ class ECStest
9
+ def self.access_key_id ; 'Replace this with your access key id' ; end
10
+ def self.default_test_cache_directory ; 'Replace this with the path to your cache directory' ; end
11
+ def self.time_management_file ; 'Replace this with the path to your time management file' ; end
12
+ end
13
+ # End change these parameters
14
+ #############################
15
+
16
+ ECS.cache = true
17
+
18
+ good = Hash.new
19
+ good[:access_key_id] = ECStest.access_key_id != 'Replace this with your access key id'
20
+ good[:cache_directory] = ECStest.default_test_cache_directory != 'Replace this with the path to your cache directory'
21
+ good[:time_management_file] = ECStest.time_management_file != 'Replace this with the path to your time management file'
22
+
23
+ message = good.reject{ |k,v| v }.keys.collect{ |k| k.to_s.gsub( /_/, ' ' ) }.join(", ")
24
+
25
+ unless message.to_s.empty?
26
+ puts "\nWHOOPS: In order to run these tests, please change the #{ message.index(',') ? 'values' : 'value' } of #{message} in #{File.expand_path( __FILE__ )}\n\n"
27
+ exit
28
+ end
29
+
30
+ ECS.access_key_id = ECStest.access_key_id
31
+ ECS.cache_directory = ECStest.default_test_cache_directory
32
+ ECS::TimeManagement.time_file = ECStest.time_management_file
33
+
34
+
35
+
36
+ class Symbol
37
+ def <=>( other )
38
+ return self.to_s <=> other.to_s
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: ECS
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-03-08 00:00:00 -08:00
8
+ summary: A Ruby interface to Amazon's E-Commerce Service.
9
+ require_paths:
10
+ - lib
11
+ email: z@wzph.com
12
+ homepage:
13
+ rubyforge_project: ECS
14
+ description: ECS is a Ruby interface to Amazon's E-Commerce Service. ECS uses the Query API, exposing all the published API calls, plus a few more. For more information on ECS, see http://www.amazonaws.com
15
+ autorequire: ecs
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Zachary Holt
31
+ files:
32
+ - lib/ecs.rb
33
+ - lib/libxml_additions.rb
34
+ - lib/string_additions.rb
35
+ - lib/ecs/help.rb
36
+ - lib/ecs/help_response_group.rb
37
+ - lib/ecs/operations.rb
38
+ - lib/ecs/response_groups.rb
39
+ - lib/ecs/time_management.rb
40
+ - test/all_tests.rb
41
+ - test/unit/ecs_test.rb
42
+ - test/unit/libxml_additions_test.rb
43
+ - test/unit/string_additions_test.rb
44
+ - test/unit/unit_test_setup.rb
45
+ - README
46
+ - MIT-LICENSE
47
+ - CHANGELOG
48
+ test_files:
49
+ - test/all_tests.rb
50
+ - test/unit/ecs_test.rb
51
+ - test/unit/libxml_additions_test.rb
52
+ - test/unit/string_additions_test.rb
53
+ - test/unit/unit_test_setup.rb
54
+ rdoc_options: []
55
+
56
+ extra_rdoc_files:
57
+ - README
58
+ - MIT-LICENSE
59
+ - CHANGELOG
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ requirements: []
65
+
66
+ dependencies: []
67
+