peddler 2.1.0 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of peddler might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +43 -41
- data/lib/mws.rb +2 -1
- data/lib/mws/easy_ship.rb +3 -0
- data/lib/mws/easy_ship/client.rb +93 -0
- data/lib/mws/fulfillment_inbound_shipment/client.rb +2 -2
- data/lib/mws/fulfillment_outbound_shipment/client.rb +1 -1
- data/lib/mws/orders/client.rb +7 -9
- data/lib/mws/reports/client.rb +9 -0
- data/lib/mws/shipment_invoicing.rb +3 -0
- data/lib/mws/shipment_invoicing/client.rb +74 -0
- data/lib/peddler/client.rb +18 -15
- data/lib/peddler/errors/builder.rb +7 -2
- data/lib/peddler/errors/class_generator.rb +7 -2
- data/lib/peddler/errors/error.rb +6 -2
- data/lib/peddler/errors/parser.rb +1 -1
- data/lib/peddler/flat_file_parser.rb +6 -4
- data/lib/peddler/headers.rb +53 -1
- data/lib/peddler/marketplace.rb +24 -22
- data/lib/peddler/operation.rb +17 -11
- data/lib/peddler/parser.rb +1 -1
- data/lib/peddler/structured_list.rb +1 -1
- data/lib/peddler/vcr_matcher.rb +7 -7
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler/xml_parser.rb +1 -1
- data/lib/peddler/xml_response_parser.rb +3 -2
- metadata +15 -150
- data/lib/mws/off_amazon_payments/client.rb +0 -362
- data/lib/mws/reports/parser.rb +0 -35
- data/test/credentials.rb +0 -23
- data/test/helper.rb +0 -15
- data/test/integration/test_errors.rb +0 -25
- data/test/integration/test_feeds.rb +0 -37
- data/test/integration/test_fulfillment_inbound_shipment.rb +0 -35
- data/test/integration/test_fulfillment_inventory.rb +0 -20
- data/test/integration/test_fulfillment_outbound_shipment.rb +0 -13
- data/test/integration/test_merchant_fulfillment.rb +0 -69
- data/test/integration/test_multibyte_queries.rb +0 -17
- data/test/integration/test_mws_headers.rb +0 -16
- data/test/integration/test_off_amazon_payments.rb +0 -13
- data/test/integration/test_orders.rb +0 -30
- data/test/integration/test_products.rb +0 -97
- data/test/integration/test_recommendations.rb +0 -20
- data/test/integration/test_reports.rb +0 -51
- data/test/integration/test_sellers.rb +0 -13
- data/test/integration/test_subscriptions.rb +0 -27
- data/test/integration_helper.rb +0 -53
- data/test/mws.yml +0 -36
- data/test/mws.yml.example +0 -32
- data/test/null_client.rb +0 -25
- data/test/recorder.rb +0 -39
- data/test/unit/mws/test_feeds_client.rb +0 -103
- data/test/unit/mws/test_finances_client.rb +0 -74
- data/test/unit/mws/test_fulfillment_inbound_shipment_client.rb +0 -426
- data/test/unit/mws/test_fulfillment_inventory_client.rb +0 -48
- data/test/unit/mws/test_fulfillment_outbound_shipment_client.rb +0 -202
- data/test/unit/mws/test_merchant_fulfillment_client.rb +0 -109
- data/test/unit/mws/test_off_amazon_payments_client.rb +0 -286
- data/test/unit/mws/test_orders_client.rb +0 -111
- data/test/unit/mws/test_products_client.rb +0 -248
- data/test/unit/mws/test_recommendations_client.rb +0 -62
- data/test/unit/mws/test_reports_client.rb +0 -209
- data/test/unit/mws/test_sellers_client.rb +0 -47
- data/test/unit/mws/test_subscriptions_client.rb +0 -182
- data/test/unit/peddler/errors/test_builder.rb +0 -65
- data/test/unit/peddler/errors/test_class_generator.rb +0 -18
- data/test/unit/peddler/errors/test_error.rb +0 -33
- data/test/unit/peddler/errors/test_parser.rb +0 -44
- data/test/unit/peddler/test_client.rb +0 -203
- data/test/unit/peddler/test_flat_file_parser.rb +0 -102
- data/test/unit/peddler/test_headers.rb +0 -55
- data/test/unit/peddler/test_marketplace.rb +0 -47
- data/test/unit/peddler/test_operation.rb +0 -87
- data/test/unit/peddler/test_parser.rb +0 -36
- data/test/unit/peddler/test_structured_list.rb +0 -39
- data/test/unit/peddler/test_vcr_matcher.rb +0 -55
- data/test/unit/peddler/test_xml_parser.rb +0 -37
- data/test/unit/peddler/test_xml_response_parser.rb +0 -39
- data/test/unit/test_mws.rb +0 -11
- data/test/vcr_cassettes/CartInformation.yml +0 -433
- data/test/vcr_cassettes/CustomerInformation.yml +0 -433
- data/test/vcr_cassettes/Errors.yml +0 -885
- data/test/vcr_cassettes/Feeds.yml +0 -9957
- data/test/vcr_cassettes/FulfillmentInboundShipment.yml +0 -6166
- data/test/vcr_cassettes/FulfillmentInventory.yml +0 -850
- data/test/vcr_cassettes/FulfillmentOutboundShipment.yml +0 -433
- data/test/vcr_cassettes/MWSHeaders.yml +0 -2964
- data/test/vcr_cassettes/MerchantFulfillment.yml +0 -753
- data/test/vcr_cassettes/MultibyteQueries.yml +0 -437
- data/test/vcr_cassettes/OffAmazonPayments.yml +0 -433
- data/test/vcr_cassettes/Orders.yml +0 -4740
- data/test/vcr_cassettes/PeddlerVCRMatcher.yml +0 -41
- data/test/vcr_cassettes/Products.yml +0 -7139
- data/test/vcr_cassettes/Recommendations.yml +0 -3145
- data/test/vcr_cassettes/Reports.yml +0 -5549
- data/test/vcr_cassettes/Sellers.yml +0 -433
- data/test/vcr_cassettes/Subscriptions.yml +0 -1529
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'mws/sellers/client'
|
5
|
-
|
6
|
-
class TestMWSSellersClient < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@client = MWS::Sellers::Client.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_listing_marketplace_participations
|
12
|
-
operation = {
|
13
|
-
'Action' => 'ListMarketplaceParticipations'
|
14
|
-
}
|
15
|
-
|
16
|
-
@client.stub(:run, nil) do
|
17
|
-
@client.list_marketplace_participations
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_equal operation, @client.operation
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_listing_marketplace_participations_by_next_token
|
24
|
-
operation = {
|
25
|
-
'Action' => 'ListMarketplaceParticipationsByNextToken',
|
26
|
-
'NextToken' => '1'
|
27
|
-
}
|
28
|
-
|
29
|
-
@client.stub(:run, nil) do
|
30
|
-
@client.list_marketplace_participations_by_next_token('1')
|
31
|
-
end
|
32
|
-
|
33
|
-
assert_equal operation, @client.operation
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_getting_service_status
|
37
|
-
operation = {
|
38
|
-
'Action' => 'GetServiceStatus'
|
39
|
-
}
|
40
|
-
|
41
|
-
@client.stub(:run, nil) do
|
42
|
-
@client.get_service_status
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_equal operation, @client.operation
|
46
|
-
end
|
47
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'mws/subscriptions/client'
|
5
|
-
|
6
|
-
class TestMWSSubscriptionsClient < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@client = MWS::Subscriptions::Client.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_registering_destination
|
12
|
-
operation = {
|
13
|
-
'Action' => 'RegisterDestination',
|
14
|
-
'MarketplaceId' => '321',
|
15
|
-
'Destination.DeliveryChannel' => 'SQS',
|
16
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
17
|
-
'Destination.AttributeList.member.1.Value' => 'foo'
|
18
|
-
}
|
19
|
-
|
20
|
-
@client.stub(:run, nil) do
|
21
|
-
@client.register_destination('foo', '321')
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal operation, @client.operation
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_deregistering_destination
|
28
|
-
operation = {
|
29
|
-
'Action' => 'DeregisterDestination',
|
30
|
-
'MarketplaceId' => '123',
|
31
|
-
'Destination.DeliveryChannel' => 'SQS',
|
32
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
33
|
-
'Destination.AttributeList.member.1.Value' => 'foo'
|
34
|
-
}
|
35
|
-
|
36
|
-
@client.stub(:run, nil) do
|
37
|
-
@client.deregister_destination('foo', '123')
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_equal operation, @client.operation
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_deregistering_destination_with_alternate_marketplace
|
44
|
-
operation = {
|
45
|
-
'Action' => 'DeregisterDestination',
|
46
|
-
'MarketplaceId' => '321',
|
47
|
-
'Destination.DeliveryChannel' => 'SQS',
|
48
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
49
|
-
'Destination.AttributeList.member.1.Value' => 'foo'
|
50
|
-
}
|
51
|
-
|
52
|
-
@client.stub(:run, nil) do
|
53
|
-
@client.deregister_destination('foo', '321')
|
54
|
-
end
|
55
|
-
|
56
|
-
assert_equal operation, @client.operation
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_listing_registered_destinations
|
60
|
-
operation = {
|
61
|
-
'Action' => 'ListRegisteredDestinations',
|
62
|
-
'MarketplaceId' => '321'
|
63
|
-
}
|
64
|
-
|
65
|
-
@client.stub(:run, nil) do
|
66
|
-
@client.list_registered_destinations('321')
|
67
|
-
end
|
68
|
-
|
69
|
-
assert_equal operation, @client.operation
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_sending_test_notification_to_destination
|
73
|
-
operation = {
|
74
|
-
'Action' => 'SendTestNotificationToDestination',
|
75
|
-
'MarketplaceId' => '321',
|
76
|
-
'Destination.DeliveryChannel' => 'SQS',
|
77
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
78
|
-
'Destination.AttributeList.member.1.Value' => 'foo'
|
79
|
-
}
|
80
|
-
|
81
|
-
@client.stub(:run, nil) do
|
82
|
-
@client.send_test_notification_to_destination('foo', '321')
|
83
|
-
end
|
84
|
-
|
85
|
-
assert_equal operation, @client.operation
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_creating_subscription
|
89
|
-
operation = {
|
90
|
-
'Action' => 'CreateSubscription',
|
91
|
-
'MarketplaceId' => '321',
|
92
|
-
'Subscription.IsEnabled' => true,
|
93
|
-
'Subscription.NotificationType' => 'foo',
|
94
|
-
'Subscription.Destination.DeliveryChannel' => 'SQS',
|
95
|
-
'Subscription.Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
96
|
-
'Subscription.Destination.AttributeList.member.1.Value' => 'bar'
|
97
|
-
}
|
98
|
-
|
99
|
-
@client.stub(:run, nil) do
|
100
|
-
@client.create_subscription('foo', 'bar', '321')
|
101
|
-
end
|
102
|
-
|
103
|
-
assert_equal operation, @client.operation
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_getting_subscription
|
107
|
-
operation = {
|
108
|
-
'Action' => 'GetSubscription',
|
109
|
-
'MarketplaceId' => '321',
|
110
|
-
'NotificationType' => 'foo',
|
111
|
-
'Destination.DeliveryChannel' => 'SQS',
|
112
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
113
|
-
'Destination.AttributeList.member.1.Value' => 'bar'
|
114
|
-
}
|
115
|
-
|
116
|
-
@client.stub(:run, nil) do
|
117
|
-
@client.get_subscription('foo', 'bar', '321')
|
118
|
-
end
|
119
|
-
|
120
|
-
assert_equal operation, @client.operation
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_deleting_subscription
|
124
|
-
operation = {
|
125
|
-
'Action' => 'DeleteSubscription',
|
126
|
-
'MarketplaceId' => '321',
|
127
|
-
'NotificationType' => 'foo',
|
128
|
-
'Destination.DeliveryChannel' => 'SQS',
|
129
|
-
'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
130
|
-
'Destination.AttributeList.member.1.Value' => 'bar'
|
131
|
-
}
|
132
|
-
|
133
|
-
@client.stub(:run, nil) do
|
134
|
-
@client.delete_subscription('foo', 'bar', '321')
|
135
|
-
end
|
136
|
-
|
137
|
-
assert_equal operation, @client.operation
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_listing_subscriptions
|
141
|
-
operation = {
|
142
|
-
'Action' => 'ListSubscriptions',
|
143
|
-
'MarketplaceId' => '321'
|
144
|
-
}
|
145
|
-
|
146
|
-
@client.stub(:run, nil) do
|
147
|
-
@client.list_subscriptions('321')
|
148
|
-
end
|
149
|
-
|
150
|
-
assert_equal operation, @client.operation
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_updating_subscription
|
154
|
-
operation = {
|
155
|
-
'Action' => 'UpdateSubscription',
|
156
|
-
'MarketplaceId' => '321',
|
157
|
-
'Subscription.IsEnabled' => true,
|
158
|
-
'Subscription.NotificationType' => 'foo',
|
159
|
-
'Subscription.Destination.DeliveryChannel' => 'SQS',
|
160
|
-
'Subscription.Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
|
161
|
-
'Subscription.Destination.AttributeList.member.1.Value' => 'bar'
|
162
|
-
}
|
163
|
-
|
164
|
-
@client.stub(:run, nil) do
|
165
|
-
@client.update_subscription('foo', 'bar', true, '321')
|
166
|
-
end
|
167
|
-
|
168
|
-
assert_equal operation, @client.operation
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_getting_service_status
|
172
|
-
operation = {
|
173
|
-
'Action' => 'GetServiceStatus'
|
174
|
-
}
|
175
|
-
|
176
|
-
@client.stub(:run, nil) do
|
177
|
-
@client.get_service_status
|
178
|
-
end
|
179
|
-
|
180
|
-
assert_equal operation, @client.operation
|
181
|
-
end
|
182
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/errors/builder'
|
5
|
-
|
6
|
-
class TestPeddlerErrorsBuilder < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@error = Peddler::Errors::Builder.call(@cause)
|
9
|
-
end
|
10
|
-
|
11
|
-
class CausedByHTTPStatusError < TestPeddlerErrorsBuilder
|
12
|
-
def setup
|
13
|
-
@code = 'FeedProcessingResultNotReady'
|
14
|
-
@message = 'Feed Submission Result is not ready for Feed 123'
|
15
|
-
body = <<-XML
|
16
|
-
<ErrorResponse>
|
17
|
-
<Error>
|
18
|
-
<Code>#{@code}</Code>
|
19
|
-
<Message>#{@message}</Message>
|
20
|
-
</Error>
|
21
|
-
</ErrorResponse>
|
22
|
-
XML
|
23
|
-
@cause = Excon::Error::NotFound.new(
|
24
|
-
'Expected(200) <=> Actual(404 Not Found)',
|
25
|
-
nil,
|
26
|
-
OpenStruct.new(body: body)
|
27
|
-
)
|
28
|
-
super
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_custom_error
|
32
|
-
assert_includes @error.class.name, @code
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_message
|
36
|
-
assert_equal @message, @error.message
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_cause
|
40
|
-
assert_equal @cause, @error.cause
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class CausedByInternalServerError < TestPeddlerErrorsBuilder
|
45
|
-
def setup
|
46
|
-
body = <<-XML
|
47
|
-
<ErrorResponse>
|
48
|
-
<Error>
|
49
|
-
<Code>500</Code>
|
50
|
-
</Error>
|
51
|
-
</ErrorResponse>
|
52
|
-
XML
|
53
|
-
@cause = Excon::Error::InternalServerError.new(
|
54
|
-
nil,
|
55
|
-
nil,
|
56
|
-
OpenStruct.new(body: body)
|
57
|
-
)
|
58
|
-
super
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_that_it_returns_nothing
|
62
|
-
assert_nil @error
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/errors/class_generator'
|
5
|
-
|
6
|
-
class TestPeddlerErrorsClassGenerator < MiniTest::Test
|
7
|
-
def test_building_an_error_class
|
8
|
-
Peddler::Errors::ClassGenerator.call('Foo')
|
9
|
-
assert Peddler::Errors::Foo
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_thread_safety
|
13
|
-
Peddler::Errors::ClassGenerator.call('Foo')
|
14
|
-
assert_output '', '' do
|
15
|
-
Peddler::Errors::ClassGenerator.call('Foo')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/errors/error'
|
5
|
-
|
6
|
-
class TestPeddlerErrorsError < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@cause = OpenStruct.new(response: 'response')
|
9
|
-
@error = Peddler::Errors::Error.new('message', @cause)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_message
|
13
|
-
assert_equal 'message', @error.message
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_cause
|
17
|
-
assert_equal @cause, @error.cause
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_that_it_defines_common_errors
|
21
|
-
Peddler::Errors::CODES.each do |name|
|
22
|
-
assert ::Peddler::Errors.const_defined?(name)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_that_it_allows_nil_arguments
|
27
|
-
Peddler::Errors::Error.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_that_it_delegates_response_to_cause
|
31
|
-
assert_equal @cause.response, @error.response
|
32
|
-
end
|
33
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/errors/parser'
|
5
|
-
|
6
|
-
class TestPeddlerErrorsParser < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
body = <<-XML
|
9
|
-
<ErrorResponse>
|
10
|
-
<Error>
|
11
|
-
<Type>Foo</Type>
|
12
|
-
<Code>Bar</Code>
|
13
|
-
<Message>Baz</Message>
|
14
|
-
</Error>
|
15
|
-
<RequestID>123</RequestID>
|
16
|
-
</ErrorResponse>
|
17
|
-
XML
|
18
|
-
res = OpenStruct.new(
|
19
|
-
body: body,
|
20
|
-
headers: {
|
21
|
-
'Content-Type' => 'text/xml',
|
22
|
-
'Content-Length' => body.size.to_s
|
23
|
-
}
|
24
|
-
)
|
25
|
-
|
26
|
-
@parser = Peddler::Errors::Parser.new(res)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_parsing_data
|
30
|
-
assert @parser.parse
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_message
|
34
|
-
assert @parser.message
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_code
|
38
|
-
assert @parser.code
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_type
|
42
|
-
assert @parser.type
|
43
|
-
end
|
44
|
-
end
|
@@ -1,203 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'null_client'
|
5
|
-
|
6
|
-
class TestPeddlerClient < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
Excon.defaults[:mock] = true
|
9
|
-
@klass = Class.new(Null::Client)
|
10
|
-
@client = @klass.new
|
11
|
-
@client.configure_with_mock_data!
|
12
|
-
@client.operation('Foo')
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
Excon.stubs.clear
|
17
|
-
Excon.defaults.delete(:mock)
|
18
|
-
end
|
19
|
-
|
20
|
-
class HappyPath < TestPeddlerClient
|
21
|
-
def setup
|
22
|
-
@response_body = 'foo'
|
23
|
-
Excon.stub({}, body: @response_body, status: 200)
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_user_agent
|
28
|
-
assert @client.connection.data[:headers].key?('User-Agent')
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_inheritance_of_parents_params
|
32
|
-
assert_equal Peddler::Client.params, @klass.params
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_that_params_include_seller_id
|
36
|
-
assert @klass.params.key?('SellerId')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_that_params_include_auth_token
|
40
|
-
@klass.params.key?('MWSAuthToken')
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_inheritance_of_parents_parser
|
44
|
-
assert_equal @klass.parser, Class.new(@klass).parser
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_setting_marketplace
|
48
|
-
marketplace = Peddler::Marketplace.find('US')
|
49
|
-
@client.marketplace = 'US'
|
50
|
-
assert_equal marketplace, @client.marketplace
|
51
|
-
@client.marketplace = marketplace
|
52
|
-
assert_equal marketplace, @client.marketplace
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_configuring_when_initialising
|
56
|
-
client = @klass.new(aws_access_key_id: '123')
|
57
|
-
assert_equal '123', client.aws_access_key_id
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_setting_content_type_header_for_latin_flat_file
|
61
|
-
@client.body = 'foo'
|
62
|
-
content_type = @client.headers.fetch('Content-Type')
|
63
|
-
|
64
|
-
assert_equal 'text/tab-separated-values; charset=CP1252', content_type
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_setting_content_type_header_for_chinese_flat_file
|
68
|
-
@client.marketplace = 'CN'
|
69
|
-
@client.body = 'foo'
|
70
|
-
content_type = @client.headers.fetch('Content-Type')
|
71
|
-
|
72
|
-
assert_equal 'text/tab-separated-values; charset=UTF-16', content_type
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_setting_content_type_header_for_japanese_flat_file
|
76
|
-
@client.marketplace = 'JP'
|
77
|
-
@client.body = 'foo'
|
78
|
-
content_type = @client.headers.fetch('Content-Type')
|
79
|
-
|
80
|
-
assert_equal 'text/tab-separated-values; charset=Windows-31J', content_type
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_setting_content_type_header_for_xml
|
84
|
-
@client.body = '<?xml version="1.0"?><Foo></Foo>'
|
85
|
-
content_type = @client.headers.fetch('Content-Type')
|
86
|
-
|
87
|
-
assert_equal 'text/xml', content_type
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_encoding_body_for_latin_flat_file
|
91
|
-
@client.body = 'foo'
|
92
|
-
assert_equal 'Windows-1252', @client.body.encoding.to_s
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_encoding_body_for_chinese_flat_file
|
96
|
-
@client.marketplace = 'CN'
|
97
|
-
@client.body = 'foo'
|
98
|
-
assert_equal 'UTF-16', @client.body.encoding.to_s
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_encoding_body_for_japanese_flat_file
|
102
|
-
@client.marketplace = 'JP'
|
103
|
-
@client.body = 'foo'
|
104
|
-
assert_equal 'Windows-31J', @client.body.encoding.to_s
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_running_a_request
|
108
|
-
res = @client.run
|
109
|
-
assert_equal @response_body, res.body
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_clearing_body_when_run_succeeds
|
113
|
-
@client.body = 'foo'
|
114
|
-
@client.run
|
115
|
-
assert_nil @client.body
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_streaming_response
|
119
|
-
chunks = ''
|
120
|
-
streamer = ->(chunk, _, _) { chunks += chunk }
|
121
|
-
@client.run(&streamer)
|
122
|
-
|
123
|
-
assert_equal @response_body, chunks
|
124
|
-
end
|
125
|
-
|
126
|
-
class Instrumentor
|
127
|
-
class << self
|
128
|
-
attr_accessor :events
|
129
|
-
|
130
|
-
def instrument(name, params = {})
|
131
|
-
events.update(name => params)
|
132
|
-
yield if block_given?
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
@events = {}
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_that_request_preserves_user_agent
|
140
|
-
@client.defaults.update(instrumentor: Instrumentor)
|
141
|
-
@client.run
|
142
|
-
headers = Instrumentor.events['excon.request'][:headers]
|
143
|
-
|
144
|
-
assert headers.key?('User-Agent')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
class MWSErrorPath < TestPeddlerClient
|
149
|
-
def setup
|
150
|
-
body = <<-XML
|
151
|
-
<ErrorResponse>
|
152
|
-
<Error>
|
153
|
-
<Code>RequestThrottled</Code>
|
154
|
-
</Error>
|
155
|
-
</ErrorResponse>
|
156
|
-
XML
|
157
|
-
Excon.stub({}, body: body, status: 503)
|
158
|
-
super
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_default_error_handling
|
162
|
-
assert_raises Peddler::Errors::RequestThrottled do
|
163
|
-
@client.run
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_it_does_not_clear_body_when_run_fails
|
168
|
-
@client.body = 'foo'
|
169
|
-
assert_raises Peddler::Errors::RequestThrottled do
|
170
|
-
@client.run
|
171
|
-
end
|
172
|
-
refute_nil @client.body
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class OtherHTTPStatusErrorPath < TestPeddlerClient
|
177
|
-
def setup
|
178
|
-
body = <<-XML
|
179
|
-
<ErrorResponse>
|
180
|
-
<Error>
|
181
|
-
<Code>500</Code>
|
182
|
-
</Error>
|
183
|
-
</ErrorResponse>
|
184
|
-
XML
|
185
|
-
Excon.stub({}, body: body, status: 500)
|
186
|
-
super
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_error_handling
|
190
|
-
assert_raises Excon::Error::InternalServerError do
|
191
|
-
@client.run
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_it_does_not_clear_body_when_run_fails
|
196
|
-
@client.body = 'foo'
|
197
|
-
assert_raises Excon::Error::InternalServerError do
|
198
|
-
@client.run
|
199
|
-
end
|
200
|
-
refute_nil @client.body
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|