soaspec 0.3.3 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +14 -0
- data/lib/soaspec/baseline.rb +7 -5
- data/lib/soaspec/exchange/exchange_properties.rb +1 -1
- data/lib/soaspec/exchange_handlers/request/rest_request.rb +43 -24
- data/lib/soaspec/exchange_handlers/rest_handler.rb +3 -21
- data/lib/soaspec/exchange_handlers/soap_handler.rb +3 -2
- data/lib/soaspec/version.rb +1 -1
- data/lib/soaspec/virtual_server.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3843bc70d12aba4f2d2d825ef0eb3f142cea08fe50c6042875bcbc8f08d770
|
4
|
+
data.tar.gz: 6448d093a3a2df45fa7db32c2c230349fd892258ffcf8d863f01759b79913a67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f81e8e90e494743cdd9fdd87d251194cb7c791631a53508c224f458787458417c1c12b0d8cae942e246f92b7ffe2bd76cede518ddf60f156ef85eb3d4874138e
|
7
|
+
data.tar.gz: 43c1a37a03e64cacce5a478083d183b6e4422d1ab5db5edc94b81c812968a804326df97c3c9ba539101e10fee8c27981f41186e337517e115d221194f922f7ad
|
data/ChangeLog
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
Version 0.3.6
|
2
|
+
* Enhancement
|
3
|
+
* Build up Rest request using `RestClient::Request` rather than use resource to allow
|
4
|
+
sending payload to HTTP methods like `delete` and `get` which doesn't usually take one but
|
5
|
+
sometimes does
|
6
|
+
|
7
|
+
Version 0.3.5
|
8
|
+
* Enhancement
|
9
|
+
* Clean up the Handler code, mainly REST by moving logic into RestRequest method
|
10
|
+
|
11
|
+
Version 0.3.4
|
12
|
+
* Bug fix
|
13
|
+
* Don't put global options on STDOUT. Put within logger
|
14
|
+
|
1
15
|
Version 0.3.3
|
2
16
|
* Enhancement
|
3
17
|
* Ability to specify multipart on Soaspec::OAuth2, not always assume it's value
|
data/lib/soaspec/baseline.rb
CHANGED
@@ -4,7 +4,9 @@ require_relative 'exe_helpers'
|
|
4
4
|
|
5
5
|
module Soaspec
|
6
6
|
# Used for defining parameters for recording and asserting against
|
7
|
-
# a baseline
|
7
|
+
# a baseline.
|
8
|
+
# This does not take into account different payloads in the request, only
|
9
|
+
# for where a response varies by suburls or query parameters
|
8
10
|
class Baseline
|
9
11
|
include Soaspec::ExeHelpers
|
10
12
|
@folder = File.join('config', 'baseline')
|
@@ -24,10 +26,10 @@ module Soaspec
|
|
24
26
|
def initialize(exchange, format)
|
25
27
|
self.exchange = exchange
|
26
28
|
self.format = format
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
return if ALLOWED_FORMATS.include? format
|
30
|
+
|
31
|
+
raise ArgumentError, "Expected format #{format} to be " \
|
32
|
+
"either #{ALLOWED_FORMATS}"
|
31
33
|
end
|
32
34
|
|
33
35
|
# Compare baseline with expected result. This will create baseline
|
@@ -6,7 +6,7 @@ module Soaspec
|
|
6
6
|
module ExchangeProperties
|
7
7
|
# Set default exchange handler for this exchange
|
8
8
|
# This is helpful for when you need a new exchange handler created for each exchange
|
9
|
-
# @param [
|
9
|
+
# @param [< ExchangeHandler] handler_class Class of ExchangeHandler to set Exchange to use
|
10
10
|
# @param [String] name Name to call handler when it's instantiated (Defaults to class name)
|
11
11
|
# @param [Hash] params Hash of parameters to set for instance of ExchangeHandler
|
12
12
|
def default_handler(handler_class, name = handler_class.to_s, params = '')
|
@@ -7,9 +7,11 @@ module Soaspec
|
|
7
7
|
# :get
|
8
8
|
# @return [Symbol] REST method used
|
9
9
|
attr_accessor :method
|
10
|
+
# This will be the actual payload sent. This could be set in Exchange through the payload
|
11
|
+
# explicitly, the 'body' param which will convert a Hash to JSON or a template
|
10
12
|
# @example JSON body
|
11
13
|
# {"test":5}
|
12
|
-
# @return [String] Body of request sent
|
14
|
+
# @return [String] Body of request sent. Payload that will be sent in request
|
13
15
|
attr_accessor :body
|
14
16
|
# @return [String] Name given to test to describe it
|
15
17
|
attr_accessor :test_name
|
@@ -27,6 +29,13 @@ module Soaspec
|
|
27
29
|
# @return [Soaspec::RestHandler] RestHandler used for this request
|
28
30
|
attr_accessor :rest_handler
|
29
31
|
|
32
|
+
# @return [String] Base url plus sub url
|
33
|
+
def full_url
|
34
|
+
url = rest_handler.base_url_value
|
35
|
+
url += "/#{suburl}" if suburl
|
36
|
+
@full_url = ERB.new(url).result(binding)
|
37
|
+
end
|
38
|
+
|
30
39
|
# Interpret REST parameters given provided parameters and adding defaults, making
|
31
40
|
# transformations
|
32
41
|
#
|
@@ -51,19 +60,21 @@ module Soaspec
|
|
51
60
|
|
52
61
|
# @param [Hash] overall Overall parameters used in Request
|
53
62
|
# @param [Hash] options Headers and basic auth options
|
54
|
-
# @param [Soaspec::RestHandler] rest_handler RestHandler handling creation of this request
|
63
|
+
# @param [< Soaspec::RestHandler] rest_handler RestHandler handling creation of this request
|
55
64
|
def initialize(overall, options, rest_handler)
|
56
65
|
self.rest_handler = rest_handler
|
57
66
|
overall_params = interpret_parameters(overall)
|
58
|
-
@overall_params = overall_params
|
67
|
+
@overall_params = overall_params.dup
|
59
68
|
self.method = overall_params.delete(:method)
|
60
|
-
self.body =
|
69
|
+
self.body = post_data
|
70
|
+
overall_params.delete(:body)
|
71
|
+
overall_params.delete(:payload)
|
61
72
|
self.suburl = overall_params.delete(:suburl)
|
62
73
|
self.test_name = overall_params.delete(:name)
|
63
74
|
self.other_params = overall_params
|
64
75
|
self.basic_auth_user = options[:user]
|
65
76
|
self.basic_auth_password = options[:password]
|
66
|
-
self.headers = options[:headers]
|
77
|
+
self.headers = options[:headers] # TODO: Use this in request
|
67
78
|
end
|
68
79
|
|
69
80
|
# @return [Hash] Query parameters for a REST Request
|
@@ -98,30 +109,38 @@ module Soaspec
|
|
98
109
|
File.join(*components.collect!(&:to_s))
|
99
110
|
end
|
100
111
|
|
101
|
-
#
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
112
|
+
# Use the request parameters to call the REST api
|
113
|
+
def call(merged_options)
|
114
|
+
rest_handler.exception = nil # Remove any previously stored exception
|
115
|
+
Soaspec::SpecLogger.info("request body: #{body}") if body
|
116
|
+
merge_headers = (merged_options[:headers] || {}).merge(other_params)
|
117
|
+
params = merged_options.merge(method: method, url: full_url,
|
118
|
+
headers: merge_headers)
|
119
|
+
params.merge!(payload: body) if body
|
120
|
+
RestClient::Request.execute params
|
121
|
+
rescue RestClient::Exception => e
|
122
|
+
rest_handler.exception = e
|
123
|
+
raise e unless e.respond_to? :response
|
124
|
+
|
125
|
+
e.response
|
109
126
|
end
|
110
127
|
|
111
|
-
# TODO: Implement this for this object
|
112
128
|
# Work out data to send based upon payload, template_name, or body
|
113
|
-
# @return [String] Payload to send in REST request
|
129
|
+
# @return [String, NilClass] Payload to send in REST request. Nil if nothing is to be sent
|
114
130
|
def post_data
|
115
131
|
option = rest_handler.request_option
|
116
|
-
if option == :hash && !@overall_params[:payload]
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
132
|
+
body = if option == :hash && !@overall_params[:payload]
|
133
|
+
@overall_params[:payload] = JSON.generate(rest_handler.hash_used_in_request(@overall_params[:body])).to_s
|
134
|
+
elsif option == :template
|
135
|
+
test_values = nil
|
136
|
+
test_values = @overall_params[:body].dup if @overall_params[:body]
|
137
|
+
Soaspec::TemplateReader.new.render_body(rest_handler.template_name, test_values || @overall_params)
|
138
|
+
else
|
139
|
+
@overall_params[:payload]
|
140
|
+
end
|
141
|
+
return body if body && body != '{}'
|
142
|
+
|
143
|
+
nil
|
125
144
|
end
|
126
145
|
end
|
127
146
|
end
|
@@ -64,26 +64,8 @@ module Soaspec
|
|
64
64
|
# @return [RestClient::Response] Response from making request
|
65
65
|
def make_request(override_parameters)
|
66
66
|
req_params = request_parameters override_parameters
|
67
|
-
|
68
|
-
|
69
|
-
@resource_used = req_params.suburl ? @resource[req_params.suburl] : @resource
|
70
|
-
|
71
|
-
self.exception = nil # Remove any previously stored exception
|
72
|
-
begin
|
73
|
-
response = case req_params.method
|
74
|
-
when :post, :patch, :put
|
75
|
-
Soaspec::SpecLogger.info("request body: #{req_params.post_data}")
|
76
|
-
@resource_used.send(req_params.method, req_params.post_data, req_params.other_params)
|
77
|
-
else # :get, :delete
|
78
|
-
@resource_used.send(req_params.method, req_params.other_params )
|
79
|
-
end
|
80
|
-
rescue RestClient::Exception => e
|
81
|
-
self.exception = e
|
82
|
-
raise e unless e.respond_to? :response
|
83
|
-
|
84
|
-
response = e.response
|
85
|
-
end
|
86
|
-
Soaspec::SpecLogger.info("response: \n headers: #{response&.headers}\n body: #{response}\n")
|
67
|
+
response = req_params.call @merged_options
|
68
|
+
Soaspec::SpecLogger.info("response:\n headers: #{response&.headers}\n body: #{response}\n")
|
87
69
|
after_response(response, self)
|
88
70
|
response
|
89
71
|
end
|
@@ -160,7 +142,7 @@ module Soaspec
|
|
160
142
|
|
161
143
|
# @return [Integer] HTTP Status code for response
|
162
144
|
def status_code_for(response)
|
163
|
-
response
|
145
|
+
response&.code
|
164
146
|
end
|
165
147
|
|
166
148
|
# Returns the value at the provided xpath
|
@@ -66,7 +66,8 @@ module Soaspec
|
|
66
66
|
|
67
67
|
# Setup object to handle communicating with a particular SOAP WSDL
|
68
68
|
# @param [String] name Name to describe handler. Used in calling 'to_s'
|
69
|
-
# @param [Hash] options Options defining SOAP request. WSDL, authentication,
|
69
|
+
# @param [Hash] options Options defining SOAP request. WSDL, authentication,
|
70
|
+
# See http://savonrb.com/version2/globals.html for list of options
|
70
71
|
def initialize(name = self.class.to_s, options = {})
|
71
72
|
if name.is_a?(Hash) && options == {} # If name is not set
|
72
73
|
options = name
|
@@ -77,9 +78,9 @@ module Soaspec
|
|
77
78
|
merged_options = SoapDefaults.options
|
78
79
|
merged_options.merge!(logging_options) if Soaspec::SpecLogger.log_api_traffic?
|
79
80
|
merged_options.merge! savon_options
|
80
|
-
puts 'globals' + savon_globals.to_s
|
81
81
|
merged_options.merge! savon_globals
|
82
82
|
merged_options.merge!(options)
|
83
|
+
Soaspec::SpecLogger.info "Using Savon globals: #{merged_options}"
|
83
84
|
self.client = Savon.client(merged_options)
|
84
85
|
end
|
85
86
|
|
data/lib/soaspec/version.rb
CHANGED
@@ -107,6 +107,11 @@ module Soaspec
|
|
107
107
|
params.to_s
|
108
108
|
end
|
109
109
|
|
110
|
+
documentation 'Sends back body received for delete'
|
111
|
+
delete '/echoer' do
|
112
|
+
request.body
|
113
|
+
end
|
114
|
+
|
110
115
|
# Used for simple testing of posing
|
111
116
|
documentation 'Simply sends the response body back'
|
112
117
|
post '/echoer' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soaspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamuelGarrattIQA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|