kernow-ruby-aaws 0.5.4
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/COPYING +340 -0
- data/INSTALL +259 -0
- data/NEWS +382 -0
- data/README +566 -0
- data/README.rdoc +129 -0
- data/Rakefile +54 -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 +87 -0
- data/example/help1 +25 -0
- data/example/item_lookup1 +55 -0
- data/example/item_lookup2 +55 -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 +30 -0
- data/example/multiple_operation1 +67 -0
- data/example/seller_listing_lookup1 +30 -0
- data/example/seller_listing_search1 +28 -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 +26 -0
- data/lib/amazon/aws/cache.rb +141 -0
- data/lib/amazon/aws/search.rb +334 -0
- data/lib/amazon/aws/shoppingcart.rb +504 -0
- data/lib/amazon/aws.rb +1176 -0
- data/lib/amazon/locale.rb +102 -0
- data/lib/amazon.rb +139 -0
- data/ruby-aws.gemspec +57 -0
- data/ruby-aws.spec +177 -0
- data/setup.rb +1306 -0
- data/test/setup.rb +31 -0
- data/test/tc_amazon.rb +20 -0
- data/test/tc_aws.rb +151 -0
- data/test/tc_item_search.rb +21 -0
- data/test/tc_multiple_operation.rb +58 -0
- data/test/tc_operation_request.rb +58 -0
- data/test/tc_serialisation.rb +103 -0
- data/test/tc_shopping_cart.rb +214 -0
- data/test/ts_aws.rb +12 -0
- metadata +99 -0
data/test/setup.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# $Id: setup.rb,v 1.3 2008/06/22 11:50:23 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
# Attempt to load Ruby/AWS using RubyGems.
|
5
|
+
#
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'ruby-aws'
|
9
|
+
rescue LoadError
|
10
|
+
# Either we don't have RubyGems or we don't have a gem of Ruby/AWS.
|
11
|
+
end
|
12
|
+
|
13
|
+
# Require the essential library, be it via RubyGems or the default way.
|
14
|
+
#
|
15
|
+
require 'amazon/aws/search'
|
16
|
+
|
17
|
+
include Amazon::AWS
|
18
|
+
include Amazon::AWS::Search
|
19
|
+
|
20
|
+
class AWSTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@rg = ResponseGroup.new( :Small )
|
24
|
+
@req = Request.new
|
25
|
+
@req.locale = 'uk'
|
26
|
+
@req.cache = false
|
27
|
+
end
|
28
|
+
|
29
|
+
undef_method :default_test
|
30
|
+
|
31
|
+
end
|
data/test/tc_amazon.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# $Id: tc_amazon.rb,v 1.1 2008/05/19 10:17:26 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestAmazonBasics < AWSTest
|
8
|
+
|
9
|
+
def test_uncamelise
|
10
|
+
str = 'ALongStringWithACRONYM'
|
11
|
+
uncamel_str = 'a_long_string_with_acronym'
|
12
|
+
|
13
|
+
# Ensure uncamelisation of strings occurs properly.
|
14
|
+
#
|
15
|
+
assert_equal( uncamel_str, Amazon::uncamelise( str ) )
|
16
|
+
assert_equal( 'asin', Amazon::uncamelise( 'ASIN' ) )
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/tc_aws.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
# $Id: tc_aws.rb,v 1.11 2008/10/02 21:33:58 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'tmpdir'
|
8
|
+
require 'amazon/locale'
|
9
|
+
|
10
|
+
class TestAWSBasics < AWSTest
|
11
|
+
|
12
|
+
CACHE_DIR = Amazon::AWS::Cache::DEFAULT_CACHE_DIR
|
13
|
+
CACHE_PATH = File.join( Dir.tmpdir, 'aws_cache' )
|
14
|
+
|
15
|
+
def test_version
|
16
|
+
v = '1.8.6'
|
17
|
+
assert( RUBY_VERSION >= v, "Ruby version is lower than #{v}." )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cache
|
21
|
+
|
22
|
+
# Assure we can create a cache with a non-default path.
|
23
|
+
#
|
24
|
+
c = Cache.new( CACHE_PATH )
|
25
|
+
assert( CACHE_PATH, c.path )
|
26
|
+
assert( File.directory?( c.path ) )
|
27
|
+
FileUtils.rmdir( c.path )
|
28
|
+
|
29
|
+
c = Cache.new
|
30
|
+
|
31
|
+
# Ensure that default cache path has been chosen.
|
32
|
+
#
|
33
|
+
assert( CACHE_DIR, c.path )
|
34
|
+
|
35
|
+
# Ensure that cache directory has been created.
|
36
|
+
#
|
37
|
+
assert( File.directory?( c.path ) )
|
38
|
+
|
39
|
+
f = File.join( c.path, 'foobar' )
|
40
|
+
|
41
|
+
# Just over a day ago.
|
42
|
+
#
|
43
|
+
t = Time.now - 86460
|
44
|
+
|
45
|
+
FileUtils.touch f, { :mtime => t }
|
46
|
+
assert( File.exist?( f ) )
|
47
|
+
|
48
|
+
# Ensure expired file is properly flushed.
|
49
|
+
#
|
50
|
+
c.flush_expired
|
51
|
+
assert( ! File.exist?( f ) )
|
52
|
+
|
53
|
+
FileUtils.touch f
|
54
|
+
assert( File.exist?( f ) )
|
55
|
+
|
56
|
+
# Ensure unexpired file is properly retained.
|
57
|
+
#
|
58
|
+
c.flush_expired
|
59
|
+
assert( File.exist?( f ) )
|
60
|
+
|
61
|
+
# Ensure file is properly flushed.
|
62
|
+
#
|
63
|
+
c.flush_all
|
64
|
+
assert( ! File.exist?( f ) )
|
65
|
+
|
66
|
+
h = Help.new( :ResponseGroup, :Large )
|
67
|
+
h_rg = ResponseGroup.new( :Help )
|
68
|
+
|
69
|
+
# Ensure that file is not cached when no cache is desired.
|
70
|
+
#
|
71
|
+
@req.cache = false
|
72
|
+
resp = @req.search( h, h_rg )
|
73
|
+
assert_equal( 0, Dir.glob( File.join( c.path, '*' ) ).size )
|
74
|
+
|
75
|
+
# Ensure that file is cached when cache is desired.
|
76
|
+
#
|
77
|
+
@req.cache = c
|
78
|
+
resp = @req.search( h, h_rg )
|
79
|
+
assert_equal( 1, Dir.glob( File.join( c.path, '*' ) ).size )
|
80
|
+
|
81
|
+
# Flush it away.
|
82
|
+
#
|
83
|
+
c.flush_all
|
84
|
+
assert_equal( 0, Dir.glob( File.join( c.path, '*' ) ).size )
|
85
|
+
|
86
|
+
FileUtils.rmdir( c.path )
|
87
|
+
|
88
|
+
# Turn off caching for future tests. This happens in the setup method,
|
89
|
+
# anyway, but it can't hurt to tidy up after ourselves.
|
90
|
+
#
|
91
|
+
@req.cache = false
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_config
|
96
|
+
# Test bad quoting.
|
97
|
+
#
|
98
|
+
assert_raise( Amazon::Config::ConfigError ) do
|
99
|
+
cf = Amazon::Config.new( <<' EOF' )
|
100
|
+
bad_syntax = 'bad quotes"
|
101
|
+
EOF
|
102
|
+
end
|
103
|
+
|
104
|
+
# Test good quoting.
|
105
|
+
#
|
106
|
+
assert_nothing_raised do
|
107
|
+
cf = Amazon::Config.new( <<' EOF' )
|
108
|
+
good_syntax = 'good quotes'
|
109
|
+
EOF
|
110
|
+
end
|
111
|
+
|
112
|
+
# Test that config files are properly read from $AMAZONRC.
|
113
|
+
#
|
114
|
+
Dir.mktmpdir do |td|
|
115
|
+
ENV['AMAZONRCDIR'] = td
|
116
|
+
ENV['AMAZONRCFILE'] = '.user_defined_name'
|
117
|
+
File.open( File.join( td, '.user_defined_name' ), 'w' ) do |tf|
|
118
|
+
tf.puts( 'foo = bar' )
|
119
|
+
end
|
120
|
+
|
121
|
+
cf = Amazon::Config.new
|
122
|
+
assert_equal( 'bar', cf['foo'] )
|
123
|
+
ENV['AMAZONRCDIR'] = nil
|
124
|
+
ENV['AMAZONRCFILE'] = nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_exceptions
|
129
|
+
assert_raise( Amazon::AWS::HTTPError ) { raise Amazon::AWS::HTTPError }
|
130
|
+
end
|
131
|
+
|
132
|
+
include Amazon
|
133
|
+
|
134
|
+
def test_geo
|
135
|
+
|
136
|
+
require 'net/geoip'
|
137
|
+
|
138
|
+
assert_equal( 'de', Locale.get_locale_by_name( 'www.marxer.org' ) )
|
139
|
+
assert_equal( 'jp', Locale.get_locale_by_name( 'ruby-lang.org' ) )
|
140
|
+
assert_equal( 'uk', Locale.get_locale_by_name( 'xs1.xs4all.nl' ) )
|
141
|
+
assert_equal( 'uk', Locale.get_locale_by_name( 'caliban.org' ) )
|
142
|
+
assert_equal( 'us', Locale.get_locale_by_name( 'google.com' ) )
|
143
|
+
|
144
|
+
# Ensure non-existent hostname causes an Amazon::Locale::GeoError.
|
145
|
+
#
|
146
|
+
assert_raise( Amazon::Locale::GeoError ) do
|
147
|
+
Locale.get_locale_by_name( 'marxer.org' )
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# $Id: tc_item_search.rb,v 1.1 2008/05/19 10:17:26 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestItemSearch < AWSTest
|
8
|
+
|
9
|
+
def test_item_search
|
10
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
11
|
+
response = @req.search( is, @rg )
|
12
|
+
|
13
|
+
results = response.kernel
|
14
|
+
|
15
|
+
# Ensure we got some actual results back.
|
16
|
+
#
|
17
|
+
assert( results.size > 0 )
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# $Id: tc_multiple_operation.rb,v 1.1 2008/05/19 10:17:26 ianmacd Exp $
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require './setup'
|
6
|
+
|
7
|
+
class TestMultipleOperation < AWSTest
|
8
|
+
|
9
|
+
def test_item_search
|
10
|
+
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B000AE4QEC',
|
11
|
+
'MerchantId' => 'Amazon' },
|
12
|
+
{ 'ItemId' => 'B000051WBE',
|
13
|
+
'MerchantId' => 'Amazon' } )
|
14
|
+
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
|
15
|
+
|
16
|
+
mo = MultipleOperation.new( is, il )
|
17
|
+
|
18
|
+
response = @req.search( mo, @rg )
|
19
|
+
|
20
|
+
mor = response.multi_operation_response[0]
|
21
|
+
|
22
|
+
# Ensure we received a MultiOperationResponse.
|
23
|
+
#
|
24
|
+
assert_instance_of( Amazon::AWS::AWSObject::MultiOperationResponse, mor )
|
25
|
+
|
26
|
+
# Ensure response contains an ItemSearchResponse.
|
27
|
+
#
|
28
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemSearchResponse,
|
29
|
+
mor.item_search_response[0] )
|
30
|
+
|
31
|
+
# Ensure response also contains an ItemLookupResponse.
|
32
|
+
#
|
33
|
+
assert_instance_of( Amazon::AWS::AWSObject::ItemLookupResponse,
|
34
|
+
mor.item_lookup_response[0] )
|
35
|
+
|
36
|
+
is_set = response.multi_operation_response.item_search_response[0].items
|
37
|
+
il_set = response.multi_operation_response.item_lookup_response[0].items
|
38
|
+
is_arr = is_set.item
|
39
|
+
il_arr1 = il_set[0].item
|
40
|
+
il_arr2 = il_set[1].item
|
41
|
+
|
42
|
+
# Ensure that there's one <ItemSet> for the ItemSearch.
|
43
|
+
#
|
44
|
+
assert_equal( 1, is_set.size )
|
45
|
+
|
46
|
+
# Ensure that there are two <ItemSet>s for the ItemLookup, because it was
|
47
|
+
# a batched operation.
|
48
|
+
#
|
49
|
+
assert_equal( 2, il_set.size )
|
50
|
+
|
51
|
+
# Assure that all item sets have some results.
|
52
|
+
#
|
53
|
+
assert( is_arr.size > 0 )
|
54
|
+
assert( il_arr1.size > 0 )
|
55
|
+
assert( il_arr2.size > 0 )
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# $Id: tc_operation_request.rb,v 1.1 2008/05/19 10:17:26 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
|
+
response = @req.search( is, ResponseGroup.new( 'Request' ) )
|
12
|
+
|
13
|
+
# Same again with Symbols.
|
14
|
+
#
|
15
|
+
is = ItemSearch.new( :Books, { :Title => 'Ruby' } )
|
16
|
+
response = @req.search( is, ResponseGroup.new( :Request ) )
|
17
|
+
|
18
|
+
# Make sure undocumented AWSObject#results provides an accurate shortcut
|
19
|
+
# to the most interesting part of the data returned by AWS.
|
20
|
+
#
|
21
|
+
assert_equal( response.item_search_response[0].items[0].item,
|
22
|
+
response.kernel )
|
23
|
+
|
24
|
+
# Ensure response is an Amazon::AWS::AWSObject.
|
25
|
+
#
|
26
|
+
assert_instance_of( Amazon::AWS::AWSObject, response )
|
27
|
+
|
28
|
+
# Ensure non-existent instance variables return nil.
|
29
|
+
#
|
30
|
+
assert_nil( response.foo_bar_baz )
|
31
|
+
|
32
|
+
# Ensure top level of response is an Amazon::AWS::AWSArray.
|
33
|
+
#
|
34
|
+
assert_instance_of( Amazon::AWS::AWSArray, response.item_search_response )
|
35
|
+
|
36
|
+
# Ensure delegation of method from AWSArray to single element.
|
37
|
+
#
|
38
|
+
assert_equal( response.item_search_response[0].operation_request,
|
39
|
+
response.item_search_response.operation_request )
|
40
|
+
|
41
|
+
# Test for correct user-agent in response.
|
42
|
+
#
|
43
|
+
assert_equal( Amazon::AWS::USER_AGENT,
|
44
|
+
response.item_search_response[0].operation_request[0].
|
45
|
+
http_headers[0].header[0].attrib['value'] )
|
46
|
+
|
47
|
+
# Ensure that the correct version of the AWS API was requested.
|
48
|
+
#
|
49
|
+
response.item_search_response[0].operation_request[0].arguments[0].
|
50
|
+
argument.each do |arg|
|
51
|
+
next unless arg.attrib['name'] == 'Version'
|
52
|
+
assert_equal( Amazon::AWS::SERVICE['Version'], arg.attrib['value'] )
|
53
|
+
break
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# $Id: tc_serialisation.rb,v 1.2 2008/06/22 21:18:50 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
|
+
response = @req.search( is, @rg )
|
19
|
+
results = response.kernel
|
20
|
+
|
21
|
+
YAML.dump( results, results_file )
|
22
|
+
results = nil
|
23
|
+
|
24
|
+
# Remove knowledge of Amazon::AWS::AWSObject, so that YAML.load knows
|
25
|
+
# nothing of its subclasses.
|
26
|
+
#
|
27
|
+
Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
|
28
|
+
|
29
|
+
# Silence warnings about redefined constants.
|
30
|
+
#
|
31
|
+
v = $VERBOSE
|
32
|
+
$VERBOSE = nil
|
33
|
+
|
34
|
+
# Reload Amazon::AWS and friends.
|
35
|
+
#
|
36
|
+
load 'amazon/aws.rb'
|
37
|
+
|
38
|
+
# Reset warning status.
|
39
|
+
#
|
40
|
+
$VERBOSE = v
|
41
|
+
|
42
|
+
# Demonstrate that normal YAML.load can't cope with instantiating objects
|
43
|
+
# from classes it knows nothing about.
|
44
|
+
#
|
45
|
+
results_file.open
|
46
|
+
results = YAML.load( results_file )
|
47
|
+
assert_instance_of( YAML::Object, results[0] )
|
48
|
+
|
49
|
+
# Ensure that AWSObject.yaml_load does the right thing.
|
50
|
+
#
|
51
|
+
results_file.open
|
52
|
+
results = Amazon::AWS::AWSObject.yaml_load( results_file )
|
53
|
+
assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_marshal_load
|
58
|
+
|
59
|
+
results_file = Tempfile.new( 'ruby_aws' )
|
60
|
+
|
61
|
+
# Serialise some results.
|
62
|
+
#
|
63
|
+
is = ItemSearch.new( 'Music', { 'Artist' => 'Voice Of The Beehive' } )
|
64
|
+
response = @req.search( is, @rg )
|
65
|
+
results = response.kernel
|
66
|
+
|
67
|
+
results_file.puts Marshal.dump( results )
|
68
|
+
results = nil
|
69
|
+
|
70
|
+
# Remove knowledge of Amazon::AWS::AWSObject, so that Marshal.load knows
|
71
|
+
# nothing of its subclasses.
|
72
|
+
#
|
73
|
+
Amazon::AWS.module_eval( %Q( remove_const :AWSObject ) )
|
74
|
+
|
75
|
+
# Silence warnings about redefined constants.
|
76
|
+
#
|
77
|
+
v = $VERBOSE
|
78
|
+
$VERBOSE = nil
|
79
|
+
|
80
|
+
# Reload Amazon::AWS and friends.
|
81
|
+
#
|
82
|
+
load 'amazon/aws.rb'
|
83
|
+
|
84
|
+
# Reset warning status.
|
85
|
+
#
|
86
|
+
$VERBOSE = v
|
87
|
+
|
88
|
+
# Demonstrate that normal Marshal.load can't cope with instantiating
|
89
|
+
# objects from classes it knows nothing about.
|
90
|
+
#
|
91
|
+
results_file.open
|
92
|
+
|
93
|
+
assert_raise ArgumentError do
|
94
|
+
Marshal.load( results_file )
|
95
|
+
end
|
96
|
+
|
97
|
+
# Ensure that Amazon::AWS::AWSObject.load does the right thing.
|
98
|
+
#
|
99
|
+
results_file.open
|
100
|
+
results = Amazon::AWS::AWSObject.load( results_file )
|
101
|
+
assert_instance_of( Amazon::AWS::AWSObject::Item, results[0] )
|
102
|
+
end
|
103
|
+
end
|
@@ -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'
|