ruby-aaws 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,214 @@
1
+ # $Id: tc_shopping_cart.rb,v 1.5 2008/07/05 14:18:03 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require './setup'
6
+ require 'amazon/aws/shoppingcart'
7
+
8
+ include Amazon::AWS::ShoppingCart
9
+
10
+ class TestShoppingCart < AWSTest
11
+
12
+ def test_shopping_cart1
13
+ cart = Cart.new
14
+ cart.locale = 'uk'
15
+
16
+ # Check that initial quantities are zero.
17
+ #
18
+ items = cart.items
19
+ sfl_items = cart.saved_for_later_items
20
+ assert_equal( 0, items.size )
21
+ assert_equal( 0, sfl_items.size )
22
+
23
+ # Create a cart with three items. The last two are given as multiple
24
+ # single-element hashes. MergeCart is false.
25
+ #
26
+ cart.cart_create( :ASIN, 'B00151HZA6', 3, false,
27
+ { 'B000WC4AH0' => 2 },
28
+ { 'B0006L16N8' => 1 } )
29
+ items = cart.items
30
+
31
+ # Check that the quantities match what we expect.
32
+ #
33
+ assert_equal( 3, items.size )
34
+ item = items.find { |item| item.asin == 'B00151HZA6' }
35
+ assert_equal( '3', item.quantity[0] )
36
+ item = items.find { |item| item.asin == 'B000WC4AH0' }
37
+ assert_equal( '2', item.quantity[0] )
38
+ item = items.find { |item| item.asin == 'B0006L16N8' }
39
+ assert_equal( '1', item.quantity[0] )
40
+
41
+ # Check purchase URL.
42
+ #
43
+
44
+ # Check for correct Cart Id.
45
+ #
46
+ assert_match( /cart-id=#{cart.cart_id}/,
47
+ cart.purchase_url,
48
+ 'Cart Id incorrect' )
49
+
50
+ # Check for correct value of MergeCart.
51
+ #
52
+ assert_match( /MergeCart=False/,
53
+ cart.purchase_url,
54
+ 'MergeCart is not False' )
55
+
56
+ # Clear cart.
57
+ #
58
+ cart.cart_clear
59
+
60
+ # Ensure that clearing the cart actually empties it.
61
+ #
62
+ assert_equal( 0, cart.cart_items.size )
63
+ end
64
+
65
+ def test_shopping_cart2
66
+ cart = Cart.new
67
+ cart.locale = 'uk'
68
+
69
+ # Create a cart with three items. The last two are given in a single
70
+ # hash. MergeCart is true. Cart#create is used as an alias of
71
+ # Cart#cart_create.
72
+ #
73
+ cart.create( :ASIN, 'B00151HZA6', 1, true,
74
+ { 'B000WC4AH0' => 2,
75
+ 'B0006L16N8' => 3 } )
76
+ items = cart.items
77
+
78
+ # Check that the quantities match what we expect.
79
+ #
80
+ assert_equal( 3, items.size )
81
+ item = items.find { |item| item.asin == 'B00151HZA6' }
82
+ assert_equal( '1', item.quantity[0] )
83
+ item = items.find { |item| item.asin == 'B000WC4AH0' }
84
+ assert_equal( '2', item.quantity[0] )
85
+ item = items.find { |item| item.asin == 'B0006L16N8' }
86
+ assert_equal( '3', item.quantity[0] )
87
+
88
+ # Check purchase URL.
89
+ #
90
+
91
+ # Check for correct Cart Id.
92
+ #
93
+ assert_match( /cart-id=#{cart.cart_id}/,
94
+ cart.purchase_url,
95
+ 'Cart Id incorrect' )
96
+
97
+ # Check for correct value of MergeCart.
98
+ #
99
+ assert_match( /MergeCart=True/,
100
+ cart.purchase_url,
101
+ 'MergeCart is not True' )
102
+
103
+ # Add some items.
104
+ #
105
+ cart.cart_add( :ASIN, 'B0014C2BL4', 1,
106
+ { 'B00006BCKL' => 1,
107
+ 'B0001XLXYI' => 4 },
108
+ { 'B0013F2M52' => 3,
109
+ 'B000HCPSR6' => 2 } )
110
+
111
+ # Check that the quantities match what we expect.
112
+ #
113
+ items = cart.items
114
+ assert_equal( 8, items.size )
115
+ item = items.find { |item| item.asin == 'B0014C2BL4' }
116
+ assert_equal( '1', item.quantity[0] )
117
+ item = items.find { |item| item.asin == 'B00006BCKL' }
118
+ assert_equal( '1', item.quantity[0] )
119
+ item = items.find { |item| item.asin == 'B0001XLXYI' }
120
+ assert_equal( '4', item.quantity[0] )
121
+ item = items.find { |item| item.asin == 'B0013F2M52' }
122
+ assert_equal( '3', item.quantity[0] )
123
+ item = items.find { |item| item.asin == 'B000HCPSR6' }
124
+ assert_equal( '2', item.quantity[0] )
125
+
126
+ # Modify an item quantity.
127
+ #
128
+ cart.cart_modify( :ASIN, 'B00151HZA6', 2 )
129
+ items = cart.items
130
+ assert_equal( 8, items.size )
131
+ item = items.find { |item| item.asin == 'B00151HZA6' }
132
+ assert_equal( '2', item.quantity[0] )
133
+
134
+ # Move item to 'Save For Later' area.
135
+ #
136
+ cart.cart_modify( :ASIN, 'B0014C2BL4', 1, true )
137
+ sfl_items = cart.saved_for_later_items
138
+ assert_equal( 1, sfl_items.size )
139
+ item = sfl_items.find { |item| item.asin == 'B0014C2BL4' }
140
+ assert_equal( '1', item.quantity[0] )
141
+ items = cart.items
142
+ assert_equal( 7, items.size )
143
+ assert( ! cart.active?( :ASIN, 'B0014C2BL4' ) )
144
+
145
+ # Move item back to 'Active' area.
146
+ #
147
+ cart.cart_modify( :ASIN, 'B0014C2BL4', 1, false )
148
+ items = cart.items
149
+ assert_equal( 8, items.size )
150
+ item = items.find { |item| item.asin == 'B0014C2BL4' }
151
+ assert_equal( '1', item.quantity[0] )
152
+ sfl_items = cart.saved_for_later_items
153
+ assert_equal( 0, sfl_items.size )
154
+ assert( ! cart.saved_for_later?( :ASIN, 'B0014C2BL4' ) )
155
+
156
+ # Remove an item.
157
+ #
158
+ cart.cart_modify( :ASIN, 'B0014C2BL4', 0 )
159
+
160
+ # Check that the number of items in the cart has been reduced by one.
161
+ #
162
+ items = cart.items
163
+ assert_equal( 7, items.size )
164
+
165
+ # Check that the item is no longer in the cart.
166
+ #
167
+ assert( ! cart.include?( :ASIN, 'B0014C2BL4' ) )
168
+
169
+ # Check that modifying non-existent item raises exception.
170
+ #
171
+ assert_raise( Amazon::AWS::ShoppingCart::CartError ) do
172
+ cart.cart_modify( :ASIN, 'B0014C2BL4', 1 )
173
+ end
174
+
175
+ # Move another item to the 'Save For Later' area.
176
+ #
177
+ cart.cart_modify( :ASIN, 'B00151HZA6', 2, true )
178
+ items = cart.items
179
+ assert_equal( 6, items.size )
180
+ sfl_items = cart.saved_for_later_items
181
+ assert_equal( 1, sfl_items.size )
182
+
183
+ # Now remove that item while it's still in the 'Save For Later' area.
184
+ #
185
+ cart.cart_modify( :ASIN, 'B00151HZA6', 0 )
186
+ items = cart.items
187
+ assert_equal( 6, items.size )
188
+ sfl_items = cart.saved_for_later_items
189
+ assert_equal( 0, sfl_items.size )
190
+
191
+ # Ensure that the item is no longer in either area of the cart.
192
+ #
193
+ assert( ! cart.include?( :ASIN, 'B0014C2BL4' ) )
194
+ assert( ! cart.active?( :ASIN, 'B0014C2BL4' ) )
195
+ assert( ! cart.saved_for_later?( :ASIN, 'B0014C2BL4' ) )
196
+
197
+ # Check that modifying non-existent item raises exception.
198
+ #
199
+ assert_raise( Amazon::AWS::ShoppingCart::CartError ) do
200
+ cart.cart_modify( :ASIN, 'B00151HZA6', 1 )
201
+ end
202
+
203
+ # Check that retrieving the cart at a later time works properly.
204
+ #
205
+ old_cart = cart
206
+ cart = Cart.new
207
+ cart.locale = 'uk'
208
+ cart.cart_get( old_cart.cart_id, old_cart.hmac )
209
+ assert_equal( old_cart.cart_id, cart.cart_id )
210
+ assert_equal( old_cart.hmac, cart.hmac )
211
+ assert_equal( old_cart.items, cart.items )
212
+ end
213
+
214
+ end
data/test/ts_aws.rb ADDED
@@ -0,0 +1,12 @@
1
+ # $Id: ts_aws.rb,v 1.4 2008/06/16 20:07:19 ianmacd Exp $
2
+ #
3
+
4
+ require 'test/unit'
5
+ require 'tc_amazon'
6
+ require 'tc_aws'
7
+ require 'tc_serialisation'
8
+ require 'tc_operation_request'
9
+ require 'tc_item_search'
10
+ require 'tc_multiple_operation'
11
+
12
+ require 'tc_shopping_cart'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: ruby-aaws
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.4.1
7
+ date: 2008-08-18 00:00:00 +02:00
8
+ summary: Ruby interface to Amazon Associates Web Services
9
+ require_paths:
10
+ - lib
11
+ email: ian@caliban.org
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: amazon/aws/search
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.6
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ian Macdonald
31
+ files:
32
+ - example/customer_content_lookup1
33
+ - example/browse_node_lookup1
34
+ - example/item_lookup1
35
+ - example/example1
36
+ - example/customer_content_search1
37
+ - example/help1
38
+ - example/multiple_operation1
39
+ - example/item_lookup2
40
+ - example/item_search1
41
+ - example/item_search2
42
+ - example/item_search3
43
+ - example/list_lookup1
44
+ - example/list_search1
45
+ - example/seller_listing_lookup1
46
+ - example/seller_listing_search1
47
+ - example/seller_lookup1
48
+ - example/shopping_cart1
49
+ - example/similarity_lookup1
50
+ - example/tag_lookup1
51
+ - example/transaction_lookup1
52
+ - lib/amazon.rb
53
+ - lib/amazon/aws/search.rb
54
+ - lib/amazon/aws/cache.rb
55
+ - lib/amazon/aws/shoppingcart.rb
56
+ - lib/amazon/locale.rb
57
+ - lib/amazon/aws.rb
58
+ - test/tc_amazon.rb
59
+ - test/setup.rb
60
+ - test/tc_item_search.rb
61
+ - test/tc_aws.rb
62
+ - test/tc_multiple_operation.rb
63
+ - test/tc_operation_request.rb
64
+ - test/tc_shopping_cart.rb
65
+ - test/ts_aws.rb
66
+ - test/tc_serialisation.rb
67
+ - COPYING
68
+ - NEWS
69
+ - README
70
+ - README.rdoc
71
+ test_files:
72
+ - test/tc_amazon.rb
73
+ - test/setup.rb
74
+ - test/tc_item_search.rb
75
+ - test/tc_aws.rb
76
+ - test/tc_multiple_operation.rb
77
+ - test/tc_operation_request.rb
78
+ - test/tc_shopping_cart.rb
79
+ - test/ts_aws.rb
80
+ - test/tc_serialisation.rb
81
+ rdoc_options: []
82
+
83
+ extra_rdoc_files:
84
+ - COPYING
85
+ - NEWS
86
+ - README
87
+ - README.rdoc
88
+ executables: []
89
+
90
+ extensions: []
91
+
92
+ requirements: []
93
+
94
+ dependencies: []
95
+