vacuum 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -138
- data/lib/vacuum.rb +3 -2
- data/lib/vacuum/locale.rb +53 -0
- data/lib/vacuum/matcher.rb +40 -0
- data/lib/vacuum/request.rb +171 -106
- data/lib/vacuum/response.rb +10 -21
- data/lib/vacuum/version.rb +1 -1
- data/test/cassettes/vacuum.yml +1217 -659
- data/test/integration_helper.rb +53 -0
- data/test/locales.rb +23 -0
- data/test/locales.yml +28 -0
- data/test/locales.yml.example +20 -0
- data/test/vacuum/test_locale.rb +35 -0
- data/test/vacuum/test_request.rb +44 -0
- data/test/vacuum/test_response.rb +22 -0
- metadata +31 -19
- data/test/test_integration.rb +0 -69
- data/test/test_unit.rb +0 -106
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'vcr'
|
5
|
+
|
6
|
+
require 'locales'
|
7
|
+
require 'vacuum'
|
8
|
+
require 'vacuum/matcher'
|
9
|
+
|
10
|
+
VCR.configure do |c|
|
11
|
+
c.hook_into :webmock
|
12
|
+
c.cassette_library_dir = 'test/cassettes'
|
13
|
+
c.default_cassette_options = {
|
14
|
+
match_requests_on: [Vacuum::Matcher],
|
15
|
+
record: ENV['RECORD'] ? :new_episodes : :none
|
16
|
+
}
|
17
|
+
c.before_record do |interaction|
|
18
|
+
interaction.ignore! if interaction.response.status.code != 200
|
19
|
+
end
|
20
|
+
|
21
|
+
Locales.each do |record|
|
22
|
+
record.each do |key, val|
|
23
|
+
next if key == :marketplace
|
24
|
+
|
25
|
+
c.filter_sensitive_data(key.upcase) { val }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
HTTPI.log = false
|
31
|
+
|
32
|
+
module Vacuum
|
33
|
+
class IntegrationTest < Minitest::Test
|
34
|
+
def setup
|
35
|
+
if ENV['LIVE']
|
36
|
+
VCR.turn_off!
|
37
|
+
WebMock.allow_net_connect!
|
38
|
+
else
|
39
|
+
VCR.insert_cassette('vacuum')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
VCR.eject_cassette if VCR.turned_on?
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def requests
|
50
|
+
Locales.map { |credentials| Vacuum.new(credentials) }.shuffle
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/test/locales.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Locales
|
7
|
+
class << self
|
8
|
+
extend Forwardable
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
attr_reader :all
|
12
|
+
|
13
|
+
def_delegators :all, :each
|
14
|
+
end
|
15
|
+
|
16
|
+
%w[locales.yml locales.yml.example].each do |filename|
|
17
|
+
path = File.expand_path(filename, __dir__)
|
18
|
+
if File.exist?(path)
|
19
|
+
@all = YAML.load_file(path)
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/locales.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
- :marketplace: CA
|
2
|
+
:access_key: AKIAIWQTVHVWCQA5THXQ
|
3
|
+
:secret_key: VOhSIqIY1wF5selhhJYJGVnIET9k5q0J8QjTX38i
|
4
|
+
:partner_tag: adabo00-20
|
5
|
+
- :marketplace: DE
|
6
|
+
:access_key: AKIAIRMMTDVD7JUI65HA
|
7
|
+
:secret_key: jYLxHKjNSnh+t+5kgr2Lx7TZIVNKFwO59MrQDAXC
|
8
|
+
:partner_tag: partly0e-21
|
9
|
+
- :marketplace: ES
|
10
|
+
:access_key: AKIAIRMMTDVD7JUI65HA
|
11
|
+
:secret_key: jYLxHKjNSnh+t+5kgr2Lx7TZIVNKFwO59MrQDAXC
|
12
|
+
:partner_tag: partly01-21
|
13
|
+
# - :marketplace: FR
|
14
|
+
# :access_key: AKIAJDNYBNMN23YBFK3A
|
15
|
+
# :secret_key: hMet2Z4I5tgT6M8mHlGBGUajGyAZN/h2DPFb9z3j
|
16
|
+
# :partner_tag: adabo-21
|
17
|
+
# - :marketplace: IT
|
18
|
+
# :access_key: AKIAIIJY6LYBYWTHITZQ
|
19
|
+
# :secret_key: Ri4VzNWOf6PK+OcWQ0sMWICOB4taInVkZJ+NkrDK
|
20
|
+
# :partner_tag: adabo0c-21
|
21
|
+
- :marketplace: GB
|
22
|
+
:access_key: AKIAJPAXMP45DOQJPHJQ
|
23
|
+
:secret_key: feZKxFjRGLtmEO3JXpmCGdDaCPA7AHiVFBhQ/fkf
|
24
|
+
:partner_tag: adabo21-21
|
25
|
+
- :marketplace: US
|
26
|
+
:access_key: AKIAIWQTVHVWCQA5THXQ
|
27
|
+
:secret_key: VOhSIqIY1wF5selhhJYJGVnIET9k5q0J8QjTX38i
|
28
|
+
:partner_tag: adabo-20
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- :marketplace: CA
|
2
|
+
:access_key: access_key
|
3
|
+
:secret_key: secret_key
|
4
|
+
:partner_tag: partner_tag
|
5
|
+
- :marketplace: ES
|
6
|
+
:access_key: access_key
|
7
|
+
:secret_key: secret_key
|
8
|
+
:partner_tag: partner_tag
|
9
|
+
- :marketplace: DE
|
10
|
+
:access_key: access_key
|
11
|
+
:secret_key: secret_key
|
12
|
+
:partner_tag: partner_tag
|
13
|
+
- :marketplace: GB
|
14
|
+
:access_key: access_key
|
15
|
+
:secret_key: secret_key
|
16
|
+
:partner_tag: partner_tag
|
17
|
+
- :marketplace: US
|
18
|
+
:access_key: access_key
|
19
|
+
:secret_key: secret_key
|
20
|
+
:partner_tag: partner_tag
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'vacuum/locale'
|
5
|
+
|
6
|
+
module Vacuum
|
7
|
+
class TestLocale < Minitest::Test
|
8
|
+
def test_find
|
9
|
+
assert_kind_of Locale, Locale.find(:us)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_find_uppercase_string
|
13
|
+
assert_kind_of Locale, Locale.find('US')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_find_uk
|
17
|
+
assert_equal :gb, Locale.find('UK').code
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_raise_if_not_found
|
21
|
+
assert_raises Locale::NotFound do
|
22
|
+
Locale.find('foo')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_build_url
|
27
|
+
assert_equal 'https://webservices.amazon.com/paapi5/foo',
|
28
|
+
Locale.find('US').build_url('Foo')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_marketplace
|
32
|
+
assert_equal 'www.amazon.com', Locale.find('US').marketplace
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'integration_helper'
|
4
|
+
|
5
|
+
module Vacuum
|
6
|
+
class RequestTest < IntegrationTest
|
7
|
+
def test_get_browse_nodes
|
8
|
+
requests.each do |request|
|
9
|
+
response = request.get_browse_nodes(browse_node_ids: ['3045'])
|
10
|
+
refute response.error?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_items
|
15
|
+
requests.each do |request|
|
16
|
+
response = request.get_items(item_ids: ['B07212L4G2'])
|
17
|
+
refute response.error?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_get_items_with_options
|
22
|
+
requests.each do |request|
|
23
|
+
response = request.get_items(item_ids: 'B07212L4G2',
|
24
|
+
resources: ['BrowseNodeInfo.BrowseNodes'])
|
25
|
+
item = response.dig('ItemsResult', 'Items').first
|
26
|
+
assert item.key?('BrowseNodeInfo')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_variations
|
31
|
+
requests.each do |request|
|
32
|
+
response = request.get_variations(asin: 'B07212L4G2')
|
33
|
+
refute response.error?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_search_items
|
38
|
+
requests.each do |request|
|
39
|
+
response = request.search_items(keywords: 'Harry Potter')
|
40
|
+
refute response.error?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'vacuum/response'
|
5
|
+
|
6
|
+
module Vacuum
|
7
|
+
class TestResponse < Minitest::Test
|
8
|
+
def setup
|
9
|
+
mock = Minitest::Mock.new
|
10
|
+
mock.expect(:body, %({"ItemsResult":{"Items":[{"ASIN":"B07212L4G2"}]}}))
|
11
|
+
@response = Response.new(mock)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_cast_to_hash
|
15
|
+
assert_kind_of Hash, @response.to_h
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_dig
|
19
|
+
assert @response.dig('ItemsResult', 'Items')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vacuum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sigv4
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: httpi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: vcr
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: webmock
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: yard
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -132,12 +132,19 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- lib/vacuum.rb
|
135
|
+
- lib/vacuum/locale.rb
|
136
|
+
- lib/vacuum/matcher.rb
|
135
137
|
- lib/vacuum/request.rb
|
136
138
|
- lib/vacuum/response.rb
|
137
139
|
- lib/vacuum/version.rb
|
138
140
|
- test/cassettes/vacuum.yml
|
139
|
-
- test/
|
140
|
-
- test/
|
141
|
+
- test/integration_helper.rb
|
142
|
+
- test/locales.rb
|
143
|
+
- test/locales.yml
|
144
|
+
- test/locales.yml.example
|
145
|
+
- test/vacuum/test_locale.rb
|
146
|
+
- test/vacuum/test_request.rb
|
147
|
+
- test/vacuum/test_response.rb
|
141
148
|
homepage: https://github.com/hakanensari/vacuum
|
142
149
|
licenses:
|
143
150
|
- MIT
|
@@ -150,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
157
|
requirements:
|
151
158
|
- - ">="
|
152
159
|
- !ruby/object:Gem::Version
|
153
|
-
version: '2.
|
160
|
+
version: '2.4'
|
154
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
162
|
requirements:
|
156
163
|
- - ">="
|
@@ -162,6 +169,11 @@ signing_key:
|
|
162
169
|
specification_version: 4
|
163
170
|
summary: Amazon Product Advertising in Ruby
|
164
171
|
test_files:
|
165
|
-
- test/
|
172
|
+
- test/vacuum/test_request.rb
|
173
|
+
- test/vacuum/test_response.rb
|
174
|
+
- test/vacuum/test_locale.rb
|
166
175
|
- test/cassettes/vacuum.yml
|
167
|
-
- test/
|
176
|
+
- test/integration_helper.rb
|
177
|
+
- test/locales.rb
|
178
|
+
- test/locales.yml
|
179
|
+
- test/locales.yml.example
|
data/test/test_integration.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'vcr'
|
5
|
-
require_relative '../lib/vacuum'
|
6
|
-
|
7
|
-
ENV['AWS_ACCESS_KEY_ID'] ||= 'key'
|
8
|
-
ENV['AWS_SECRET_ACCESS_KEY'] ||= 'secret'
|
9
|
-
|
10
|
-
VCR.configure do |c|
|
11
|
-
c.hook_into :excon
|
12
|
-
c.cassette_library_dir = 'test/cassettes'
|
13
|
-
c.default_cassette_options = {
|
14
|
-
match_requests_on: [VCR.request_matchers.uri_without_param(
|
15
|
-
'AWSAccessKeyId', 'AssociateTag', 'Signature', 'Timestamp', 'Version'
|
16
|
-
)],
|
17
|
-
record: :new_episodes
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
class TestIntegration < Minitest::Test
|
22
|
-
include Vacuum
|
23
|
-
|
24
|
-
def setup
|
25
|
-
VCR.insert_cassette('vacuum')
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
VCR.eject_cassette
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_happy_path
|
33
|
-
req = Vacuum.new
|
34
|
-
req.associate_tag = 'foo'
|
35
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'vacuum' }
|
36
|
-
res = req.item_search(query: params)
|
37
|
-
assert res.dig('ItemSearchResponse', 'Items', 'Item')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_encoding_issues
|
41
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'google' }
|
42
|
-
titles = locales.flat_map do |locale|
|
43
|
-
req = Vacuum.new(locale)
|
44
|
-
req.associate_tag = 'foo'
|
45
|
-
res = req.item_search(query: params)
|
46
|
-
items = res.dig('ItemSearchResponse', 'Items', 'Item') || []
|
47
|
-
items.map { |item| item['ItemAttributes']['Title'] }
|
48
|
-
end
|
49
|
-
encodings = titles.map { |t| t.encoding.name }.uniq
|
50
|
-
|
51
|
-
# Newer JRuby now appears to return both US-ASCII and UTF-8, depending on
|
52
|
-
# whether the string has non-ASCII characters. MRI will only return latter.
|
53
|
-
assert(encodings.any? { |encoding| encoding == 'UTF-8' })
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_unauthorized_errors
|
57
|
-
req = Vacuum.new
|
58
|
-
req.associate_tag = 'foo'
|
59
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'amazon' }
|
60
|
-
res = req.item_search(query: params)
|
61
|
-
assert_equal 'InvalidClientTokenId', res.dig('ItemSearchErrorResponse', 'Error', 'Code')
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def locales
|
67
|
-
Request::HOSTS.keys
|
68
|
-
end
|
69
|
-
end
|
data/test/test_unit.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require_relative '../lib/vacuum'
|
5
|
-
|
6
|
-
class TestVacuum < Minitest::Test
|
7
|
-
include Vacuum
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@req = Request.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
Excon.stubs.clear
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_requires_valid_locale
|
18
|
-
assert_raises(Request::BadLocale) { Request.new('foo') }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_defaults_to_us_endpoint
|
22
|
-
assert_equal 'http://webservices.amazon.com/onca/xml', @req.aws_endpoint
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_defaults_to_latest_api_version
|
26
|
-
assert_equal Request::LATEST_VERSION, @req.version
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_accepts_uk_as_locale
|
30
|
-
Request.new('UK')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_accepts_mx_as_locale
|
34
|
-
Request.new('MX')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_fetches_parsable_response
|
38
|
-
Excon.stub({}, body: '<foo/>')
|
39
|
-
res = @req.item_lookup({}, mock: true)
|
40
|
-
refute_empty res.parse
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_alternative_query_syntax
|
44
|
-
Excon.stub({}, body: '<foo/>')
|
45
|
-
res = @req.item_lookup(query: {}, mock: true)
|
46
|
-
refute_empty res.parse
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_force_encodes_body
|
50
|
-
res = Object.new
|
51
|
-
def res.body
|
52
|
-
(+'').force_encoding(Encoding::ASCII_8BIT)
|
53
|
-
end
|
54
|
-
assert_equal 'UTF-8', Response.new(res).body.encoding.name
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_sets_custom_parser_on_class_level
|
58
|
-
original_parser = Response.parser
|
59
|
-
Excon.stub({}, body: '<foo/>')
|
60
|
-
parser = MiniTest::Mock.new
|
61
|
-
parser.expect(:parse, '123', ['<foo/>'])
|
62
|
-
Response.parser = parser
|
63
|
-
res = @req.item_lookup(query: {}, mock: true)
|
64
|
-
assert_equal '123', res.parse
|
65
|
-
Response.parser = original_parser # clean up
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_sets_custom_parser_on_instance_level
|
69
|
-
Excon.stub({}, body: '<foo/>')
|
70
|
-
res = @req.item_lookup(query: {}, mock: true)
|
71
|
-
parser = MiniTest::Mock.new
|
72
|
-
parser.expect(:parse, '123', ['<foo/>'])
|
73
|
-
res.parser = parser
|
74
|
-
assert_equal '123', res.parse
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_casts_to_hash
|
78
|
-
Excon.stub({}, body: '<foo/>')
|
79
|
-
parser = MiniTest::Mock.new
|
80
|
-
res = @req.item_lookup(query: {}, mock: true)
|
81
|
-
assert_kind_of Hash, res.to_h
|
82
|
-
res.parser = parser
|
83
|
-
assert_kind_of Hash, res.to_h
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_digs
|
87
|
-
Excon.stub({}, body: '<foo><bar>baz</bar></foo>')
|
88
|
-
parser = MiniTest::Mock.new
|
89
|
-
res = @req.item_lookup(query: {}, mock: true)
|
90
|
-
assert_equal 'baz', res.dig('foo', 'bar')
|
91
|
-
res.parser = parser
|
92
|
-
assert_equal 'baz', res.dig('foo', 'bar')
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_handles_authorisation_errors
|
96
|
-
Excon.stub({}, status: 400)
|
97
|
-
res = @req.item_lookup(query: {}, mock: true)
|
98
|
-
assert_equal 400, res.status
|
99
|
-
assert_raises Excon::Error::BadRequest do
|
100
|
-
@req.item_lookup(query: {}, expects: 200, mock: true)
|
101
|
-
end
|
102
|
-
Excon.stub({}, status: 403)
|
103
|
-
res = @req.item_lookup(query: {}, mock: true)
|
104
|
-
assert_equal 403, res.status
|
105
|
-
end
|
106
|
-
end
|