ruby-paa 0.0.1
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/example/batch_operation +28 -0
- data/example/browse_node_lookup1 +46 -0
- data/example/customer_content_lookup1 +27 -0
- data/example/customer_content_search1 +21 -0
- data/example/example1 +78 -0
- data/example/help1 +24 -0
- data/example/item_lookup1 +54 -0
- data/example/item_lookup2 +56 -0
- data/example/item_search1 +30 -0
- data/example/item_search2 +37 -0
- data/example/item_search3 +23 -0
- data/example/list_lookup1 +29 -0
- data/example/list_search1 +31 -0
- data/example/multiple_operation1 +69 -0
- data/example/seller_listing_lookup1 +30 -0
- data/example/seller_listing_search1 +29 -0
- data/example/seller_lookup1 +45 -0
- data/example/shopping_cart1 +42 -0
- data/example/similarity_lookup1 +48 -0
- data/example/tag_lookup1 +34 -0
- data/example/transaction_lookup1 +25 -0
- data/example/vehicle_search +22 -0
- data/lib/ruby-paa.rb +165 -0
- data/lib/ruby-paa/aws.rb +1489 -0
- data/lib/ruby-paa/aws/cache.rb +141 -0
- data/lib/ruby-paa/aws/search.rb +463 -0
- data/lib/ruby-paa/aws/shoppingcart.rb +536 -0
- data/lib/ruby-paa/locale.rb +102 -0
- data/test/setup.rb +56 -0
- data/test/tc_amazon.rb +20 -0
- data/test/tc_aws.rb +160 -0
- data/test/tc_browse_node_lookup.rb +49 -0
- data/test/tc_customer_content_lookup.rb +49 -0
- data/test/tc_help.rb +44 -0
- data/test/tc_item_lookup.rb +47 -0
- data/test/tc_item_search.rb +105 -0
- data/test/tc_list_lookup.rb +60 -0
- data/test/tc_list_search.rb +44 -0
- data/test/tc_multiple_operation.rb +375 -0
- data/test/tc_operation_request.rb +64 -0
- data/test/tc_seller_listing_lookup.rb +47 -0
- data/test/tc_seller_listing_search.rb +55 -0
- data/test/tc_seller_lookup.rb +44 -0
- data/test/tc_serialisation.rb +107 -0
- data/test/tc_shopping_cart.rb +214 -0
- data/test/tc_similarity_lookup.rb +48 -0
- data/test/tc_tag_lookup.rb +24 -0
- data/test/tc_transaction_lookup.rb +24 -0
- data/test/tc_vehicle_operations.rb +118 -0
- data/test/ts_aws.rb +24 -0
- metadata +132 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
# $Id: tc_operation_request.rb,v 1.2 2010/02/20 17:15:18 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestOperationRequest < AWSTest
|
8
|
+
|
9
|
+
def test_operation_request
|
10
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
11
|
+
is_rg = ResponseGroup.new( 'Request' )
|
12
|
+
is.response_group = is_rg
|
13
|
+
|
14
|
+
response = @req.search( is )
|
15
|
+
|
16
|
+
# Same again with Symbols.
|
17
|
+
#
|
18
|
+
is = ItemSearch.new( :Books, { :Title => 'Ruby' } )
|
19
|
+
is_rg = ResponseGroup.new( :Request )
|
20
|
+
is.response_group = is_rg
|
21
|
+
|
22
|
+
response = @req.search( is )
|
23
|
+
|
24
|
+
# Make sure undocumented AWSObject#results provides an accurate shortcut
|
25
|
+
# to the most interesting part of the data returned by AWS.
|
26
|
+
#
|
27
|
+
assert_equal( response.item_search_response[0].items[0].item,
|
28
|
+
response.kernel )
|
29
|
+
|
30
|
+
# Ensure response is an Amazon::AWS::AWSObject.
|
31
|
+
#
|
32
|
+
assert_instance_of( Amazon::AWS::AWSObject, response )
|
33
|
+
|
34
|
+
# Ensure non-existent instance variables return nil.
|
35
|
+
#
|
36
|
+
assert_nil( response.foo_bar_baz )
|
37
|
+
|
38
|
+
# Ensure top level of response is an Amazon::AWS::AWSArray.
|
39
|
+
#
|
40
|
+
assert_instance_of( Amazon::AWS::AWSArray, response.item_search_response )
|
41
|
+
|
42
|
+
# Ensure delegation of method from AWSArray to single element.
|
43
|
+
#
|
44
|
+
assert_equal( response.item_search_response[0].operation_request,
|
45
|
+
response.item_search_response.operation_request )
|
46
|
+
|
47
|
+
# Test for correct user-agent in response.
|
48
|
+
#
|
49
|
+
assert_equal( Amazon::AWS::USER_AGENT,
|
50
|
+
response.item_search_response[0].operation_request[0].
|
51
|
+
http_headers[0].header[0].attrib['value'] )
|
52
|
+
|
53
|
+
# Ensure that the correct version of the AWS API was requested.
|
54
|
+
#
|
55
|
+
response.item_search_response[0].operation_request[0].arguments[0].
|
56
|
+
argument.each do |arg|
|
57
|
+
next unless arg.attrib['name'] == 'Version'
|
58
|
+
assert_equal( Amazon::AWS::SERVICE['Version'], arg.attrib['value'] )
|
59
|
+
break
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# $Id: tc_seller_listing_lookup.rb,v 1.2 2010/02/20 17:15:18 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestSellerListingLookup < AWSTest
|
8
|
+
|
9
|
+
def test_seller_listing_lookup
|
10
|
+
|
11
|
+
sll = SellerListingLookup.new( 'AP8U6Y3PYQ9VO', :ASIN,
|
12
|
+
{ :Id => 'B0009RRRC8' } )
|
13
|
+
sll_rg = ResponseGroup.new( 'SellerListing' )
|
14
|
+
sll.response_group = sll_rg
|
15
|
+
|
16
|
+
response = @req.search( sll )
|
17
|
+
|
18
|
+
item = response.kernel
|
19
|
+
|
20
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_seller_listing_lookup_class_method
|
25
|
+
|
26
|
+
response = Amazon::AWS.seller_listing_lookup( 'AP8U6Y3PYQ9VO', :ASIN,
|
27
|
+
{ :Id => 'B0009RRRC8' } )
|
28
|
+
|
29
|
+
item = response.kernel
|
30
|
+
|
31
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_seller_listing_lookup_class_method_block
|
36
|
+
|
37
|
+
Amazon::AWS.seller_listing_lookup( 'AP8U6Y3PYQ9VO', :ASIN,
|
38
|
+
{ :Id => 'B0009RRRC8' } ) do |r|
|
39
|
+
|
40
|
+
item = r.kernel
|
41
|
+
|
42
|
+
assert_equal( 'actionrecords', item.seller.nickname )
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# $Id: tc_seller_listing_search.rb,v 1.2 2010/02/20 17:15:18 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestSellerListingSearch < AWSTest
|
8
|
+
|
9
|
+
def test_seller_listing_search
|
10
|
+
|
11
|
+
sl = SellerListingSearch.new( 'AP8U6Y3PYQ9VO',
|
12
|
+
{ 'Keywords' => 'Killing Joke' } )
|
13
|
+
sl_rg = ResponseGroup.new( 'SellerListing' )
|
14
|
+
sl.response_group = sl_rg
|
15
|
+
|
16
|
+
response = @req.search( sl )
|
17
|
+
|
18
|
+
items = response.seller_listing_search_response[0].seller_listings[0].
|
19
|
+
seller_listing
|
20
|
+
|
21
|
+
# Ensure we got some actual items back.
|
22
|
+
#
|
23
|
+
assert( items.size > 0 )
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_seller_listing_search_class_method
|
28
|
+
|
29
|
+
response = Amazon::AWS.seller_listing_search( 'AP8U6Y3PYQ9VO',
|
30
|
+
{ 'Keywords' => 'Killing Joke' } )
|
31
|
+
|
32
|
+
items = response.seller_listing_search_response[0].seller_listings[0].
|
33
|
+
seller_listing
|
34
|
+
|
35
|
+
# Ensure we got some actual items back.
|
36
|
+
#
|
37
|
+
assert( items.size > 0 )
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_seller_listing_search_class_method_block
|
42
|
+
|
43
|
+
Amazon::AWS.seller_listing_search( 'AP8U6Y3PYQ9VO',
|
44
|
+
{ 'Keywords' => 'Killing Joke' } ) do |r|
|
45
|
+
|
46
|
+
items = r.seller_listing_search_response[0].seller_listings[0].
|
47
|
+
seller_listing
|
48
|
+
|
49
|
+
# Ensure we got some actual items back.
|
50
|
+
#
|
51
|
+
assert( items.size > 0 )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# $Id: tc_seller_lookup.rb,v 1.2 2010/02/20 17:15:18 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestSellerLookup < AWSTest
|
8
|
+
|
9
|
+
def test_seller_lookup
|
10
|
+
|
11
|
+
sl = SellerLookup.new( 'A3QFR0K2KCB7EG' )
|
12
|
+
sl_rg = ResponseGroup.new( 'Seller' )
|
13
|
+
sl.response_group = sl_rg
|
14
|
+
|
15
|
+
response = @req.search( sl )
|
16
|
+
|
17
|
+
seller = response.kernel
|
18
|
+
|
19
|
+
assert_equal( 'wherehouse', seller.nickname )
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_seller_lookup_class_method
|
24
|
+
|
25
|
+
response = Amazon::AWS.seller_lookup( 'A3QFR0K2KCB7EG' )
|
26
|
+
|
27
|
+
seller = response.kernel
|
28
|
+
|
29
|
+
assert_equal( 'wherehouse', seller.nickname )
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_seller_lookup_class_method_block
|
34
|
+
|
35
|
+
Amazon::AWS.seller_lookup( 'A3QFR0K2KCB7EG' ) do |r|
|
36
|
+
|
37
|
+
seller = r.kernel
|
38
|
+
|
39
|
+
assert_equal( 'wherehouse', seller.nickname )
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# $Id: tc_serialisation.rb,v 1.3 2010/02/20 17:15:18 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
require 'yaml'
|
7
|
+
require 'tempfile'
|
8
|
+
|
9
|
+
class AWSSerialisationTest < AWSTest
|
10
|
+
|
11
|
+
def test_yaml_load
|
12
|
+
|
13
|
+
results_file = Tempfile.new( 'ruby_aws' )
|
14
|
+
|
15
|
+
# Serialise some results.
|
16
|
+
#
|
17
|
+
is = ItemSearch.new( 'Music', { 'Artist' => 'Voice Of The Beehive' } )
|
18
|
+
is.response_group = @rg
|
19
|
+
|
20
|
+
response = @req.search( is )
|
21
|
+
results = response.kernel
|
22
|
+
|
23
|
+
YAML.dump( results, results_file )
|
24
|
+
results = nil
|
25
|
+
|
26
|
+
# Remove knowledge of Amazon::AWS::AWSObject, so that YAML.load knows
|
27
|
+
# nothing of its subclasses.
|
28
|
+
#
|
29
|
+
Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
|
30
|
+
|
31
|
+
# Silence warnings about redefined constants.
|
32
|
+
#
|
33
|
+
v = $VERBOSE
|
34
|
+
$VERBOSE = nil
|
35
|
+
|
36
|
+
# Reload Amazon::AWS and friends.
|
37
|
+
#
|
38
|
+
load 'amazon/aws.rb'
|
39
|
+
|
40
|
+
# Reset warning status.
|
41
|
+
#
|
42
|
+
$VERBOSE = v
|
43
|
+
|
44
|
+
# Demonstrate that normal YAML.load can't cope with instantiating objects
|
45
|
+
# from classes it knows nothing about.
|
46
|
+
#
|
47
|
+
results_file.open
|
48
|
+
results = YAML.load( results_file )
|
49
|
+
assert_instance_of( YAML::Object, results[0] )
|
50
|
+
|
51
|
+
# Ensure that AWSObject.yaml_load does the right thing.
|
52
|
+
#
|
53
|
+
results_file.open
|
54
|
+
results = Amazon::AWS::AWSObject.yaml_load( results_file )
|
55
|
+
assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_marshal_load
|
60
|
+
|
61
|
+
results_file = Tempfile.new( 'ruby_aws' )
|
62
|
+
|
63
|
+
# Serialise some results.
|
64
|
+
#
|
65
|
+
is = ItemSearch.new( 'Music', { 'Artist' => 'Voice Of The Beehive' } )
|
66
|
+
is.response_group = @rg
|
67
|
+
|
68
|
+
response = @req.search( is )
|
69
|
+
results = response.kernel
|
70
|
+
|
71
|
+
results_file.puts Marshal.dump( results )
|
72
|
+
results = nil
|
73
|
+
|
74
|
+
# Remove knowledge of Amazon::AWS::AWSObject, so that Marshal.load knows
|
75
|
+
# nothing of its subclasses.
|
76
|
+
#
|
77
|
+
Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
|
78
|
+
|
79
|
+
# Silence warnings about redefined constants.
|
80
|
+
#
|
81
|
+
v = $VERBOSE
|
82
|
+
$VERBOSE = nil
|
83
|
+
|
84
|
+
# Reload Amazon::AWS and friends.
|
85
|
+
#
|
86
|
+
load 'amazon/aws.rb'
|
87
|
+
|
88
|
+
# Reset warning status.
|
89
|
+
#
|
90
|
+
$VERBOSE = v
|
91
|
+
|
92
|
+
# Demonstrate that normal Marshal.load can't cope with instantiating
|
93
|
+
# objects from classes it knows nothing about.
|
94
|
+
#
|
95
|
+
results_file.open
|
96
|
+
|
97
|
+
assert_raise ArgumentError do
|
98
|
+
Marshal.load( results_file )
|
99
|
+
end
|
100
|
+
|
101
|
+
# Ensure that Amazon::AWS::AWSObject.load does the right thing.
|
102
|
+
#
|
103
|
+
results_file.open
|
104
|
+
results = Amazon::AWS::AWSObject.load( results_file )
|
105
|
+
assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# $Id: tc_shopping_cart.rb,v 1.7 2009/10/29 13:37:56 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, 'B001CB0UJC', 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 == 'B001CB0UJC' }
|
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, 'B001CB0UJC', 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 == 'B001CB0UJC' }
|
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
|
+
{ 'B0007LYSAU' => 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 == 'B0007LYSAU' }
|
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, 'B001CB0UJC', 2 )
|
129
|
+
items = cart.items
|
130
|
+
assert_equal( 8, items.size )
|
131
|
+
item = items.find { |item| item.asin == 'B001CB0UJC' }
|
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, 'B001CB0UJC', 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, 'B001CB0UJC', 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
|