soaspec 0.1.9 → 0.1.10
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.
- checksums.yaml +4 -4
- data/ChangeLog +7 -0
- data/Todo.md +2 -0
- data/lib/soaspec.rb +9 -7
- data/lib/soaspec/exchange.rb +8 -3
- data/lib/soaspec/exchange_handlers/exchange_handler.rb +6 -0
- data/lib/soaspec/exchange_handlers/rest_handler.rb +21 -10
- data/lib/soaspec/exchange_handlers/soap_handler.rb +4 -5
- data/lib/soaspec/template_reader.rb +27 -0
- data/lib/soaspec/version.rb +1 -1
- data/templates/rest_template.json +22 -0
- data/templates/soap_template.xml +7 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d48c8b910dd2bf87abcae57a3a7ef25f9bdd59d
|
4
|
+
data.tar.gz: 4c0d3566be81b05fa06878f7a01d0b54ccf776ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee025f3a394441a6ee3612befcaf94f36c3a0d3d5dc2901230f300f4d0798424f08315e6c82009b574d0ab98dce77f432579d265e445bf4ec15c8220f5b05824
|
7
|
+
data.tar.gz: 50abba523c74d01f098a9bd1e9b061ea9e6fbe66735c59cf5110e13174c5cb166537f1d0361c1fae9377f1889f2e2c6b048d81e358e3a6aac0f108c4b9644ab7
|
data/ChangeLog
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
Version 0.1.10
|
2
|
+
* Enhancements
|
3
|
+
* Rename default template folder from to 'template' to 'templates'
|
4
|
+
* Use TemplateReader to simplify and add error handling to extracting templates
|
5
|
+
* Got convenience Rest Methods able to handle taking in template_name
|
6
|
+
* Started making a request method to access request of API actually sent
|
7
|
+
|
1
8
|
Version 0.1.9
|
2
9
|
* Enhancements
|
3
10
|
* Finally move `soaspec-virtual-server` into same binary as `soaspec` utilising Thor
|
data/Todo.md
CHANGED
data/lib/soaspec.rb
CHANGED
@@ -10,6 +10,7 @@ require 'jsonpath'
|
|
10
10
|
|
11
11
|
require 'soaspec/version'
|
12
12
|
require 'soaspec/o_auth2'
|
13
|
+
require 'soaspec/template_reader'
|
13
14
|
require 'soaspec/exchange_handlers/soap_handler'
|
14
15
|
require 'soaspec/exchange_handlers/exchange_handler'
|
15
16
|
require 'soaspec/exchange_handlers/rest_methods'
|
@@ -34,19 +35,25 @@ require 'soaspec/wsdl_generator'
|
|
34
35
|
# Gem for handling SOAP and REST api tests
|
35
36
|
module Soaspec
|
36
37
|
|
37
|
-
@template_folder = '
|
38
|
+
@template_folder = 'templates'
|
38
39
|
@auto_oauth = true
|
39
40
|
|
40
41
|
class << self
|
41
42
|
# Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
|
42
43
|
attr_writer :debug_oauth
|
43
44
|
# Folder used to store templates for API calls
|
44
|
-
|
45
|
+
attr_reader :template_folder
|
45
46
|
# Stores last exchange
|
46
47
|
attr_accessor :last_exchange
|
47
48
|
# Automatically add Authorization header to RestHandler where oauth2 credentials are specified
|
48
49
|
attr_accessor :auto_oauth
|
49
50
|
|
51
|
+
# Folder used to store templates for API calls
|
52
|
+
# Converts folder / folders into an array depending upon string passed
|
53
|
+
def template_folder=(folder)
|
54
|
+
@template_folder = folder.include?('\\') ? folder.split('\\') : folder.split('/')
|
55
|
+
end
|
56
|
+
|
50
57
|
# Folder used to store credentials
|
51
58
|
# Used in auth2_file command
|
52
59
|
# @param [String] folder
|
@@ -86,11 +93,6 @@ module Soaspec
|
|
86
93
|
@debug_oauth || false
|
87
94
|
end
|
88
95
|
|
89
|
-
# @return [String] Folder used to store templates for API calls
|
90
|
-
# def template_folder
|
91
|
-
# @template_folder || 'template'
|
92
|
-
# end
|
93
|
-
|
94
96
|
# Whether to log all API traffic
|
95
97
|
def log_api_traffic=(set)
|
96
98
|
@log_api_traffic = set
|
data/lib/soaspec/exchange.rb
CHANGED
@@ -144,9 +144,9 @@ class Exchange
|
|
144
144
|
end
|
145
145
|
|
146
146
|
# Returns response object from Api. Will make the request if not made and then cache it for later on
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
147
|
+
# @example For SOAP it will be a Savon response
|
148
|
+
# response.body (body of response as Hash)
|
149
|
+
# response.header (head of response as Hash)
|
150
150
|
def response
|
151
151
|
Soaspec.last_exchange = self
|
152
152
|
@response ||= make_request
|
@@ -154,6 +154,11 @@ class Exchange
|
|
154
154
|
|
155
155
|
alias call response
|
156
156
|
|
157
|
+
# Request of API call. Either intended request or actual request
|
158
|
+
def request
|
159
|
+
exchange_handler.request(@response)
|
160
|
+
end
|
161
|
+
|
157
162
|
# Get status code from api class. This is http response for Web Api
|
158
163
|
# @return [Integer] Status code from api class
|
159
164
|
def status_code
|
@@ -100,5 +100,11 @@ module Soaspec
|
|
100
100
|
false
|
101
101
|
end
|
102
102
|
|
103
|
+
# Request of API call. Either intended request or actual request
|
104
|
+
def request(response)
|
105
|
+
return "Request not yet sent Request option is #{@request_option}" unless response
|
106
|
+
'Specific API handler should implement this'
|
107
|
+
end
|
108
|
+
|
103
109
|
end
|
104
110
|
end
|
@@ -272,19 +272,26 @@ module Soaspec
|
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
275
|
+
# Request of API call. Either intended request or actual request
|
276
|
+
def request(response)
|
277
|
+
return 'Request not yet sent' if response.nil?
|
278
|
+
response.request
|
279
|
+
end
|
280
|
+
|
275
281
|
private
|
276
282
|
|
277
283
|
# Work out data to send based upon payload, template_name
|
278
284
|
# @return [String] Payload to send in REST request
|
279
285
|
def post_data(test_values)
|
280
|
-
if test_values[:body]
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
286
|
+
data = if test_values[:body]
|
287
|
+
test_values[:payload] = JSON.generate(hash_used_in_request(test_values[:body])).to_s
|
288
|
+
elsif @request_option == :template
|
289
|
+
Soaspec::TemplateReader.new.render_body(template_name, binding)
|
290
|
+
else
|
291
|
+
test_values[:payload]
|
292
|
+
end
|
293
|
+
# Soaspec::SpecLogger.info "Request Empty for '#{@request_option}'" if data.strip.empty?
|
294
|
+
data
|
288
295
|
end
|
289
296
|
|
290
297
|
# @return [Hash] Hash used in REST request based on data conversion
|
@@ -307,9 +314,13 @@ module Soaspec
|
|
307
314
|
# @param [Hash] params Exchange parameters
|
308
315
|
# @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
|
309
316
|
define_method(rest_method) do |params = {}|
|
310
|
-
# params ||= {}
|
311
317
|
params[:name] ||= rest_method
|
312
|
-
|
318
|
+
exchange_params = { name: params[:name] }
|
319
|
+
if params[:template_name]
|
320
|
+
exchange_params[:template_name] = params[:template_name]
|
321
|
+
params.delete :template_name
|
322
|
+
end
|
323
|
+
new(exchange_params)
|
313
324
|
Exchange.new(params[:name], method: rest_method.to_sym, **params)
|
314
325
|
end
|
315
326
|
end
|
@@ -99,16 +99,15 @@ module Soaspec
|
|
99
99
|
# @param [Hash] request_parameters Parameters used to overwrite defaults in request
|
100
100
|
def make_request(request_parameters)
|
101
101
|
test_values = request_body_params request_parameters
|
102
|
+
# Call the SOAP operation with the request XML provided
|
102
103
|
begin
|
103
104
|
if @request_option == :template
|
104
|
-
|
105
|
-
render_body = ERB.new(request_body).result(binding)
|
106
|
-
client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided
|
105
|
+
client.call(operation, xml: Soaspec::TemplateReader.new.render_body(template_name, binding))
|
107
106
|
elsif @request_option == :hash
|
108
107
|
client.call(operation, message: @default_hash.merge(test_values), attributes: request_root_attributes)
|
109
108
|
end
|
110
|
-
rescue Savon::HTTPError =>
|
111
|
-
|
109
|
+
rescue Savon::HTTPError => soap_error
|
110
|
+
soap_error
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Soaspec
|
4
|
+
# Handles reading templates for tests
|
5
|
+
class TemplateReader
|
6
|
+
# Name of file where template is stored
|
7
|
+
attr_accessor :template_name
|
8
|
+
|
9
|
+
# @return [String] Path to where template file is stored
|
10
|
+
def file_location
|
11
|
+
File.join(*Soaspec.template_folder, template_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [String] template_name File where template is stored
|
15
|
+
# @return [String] Body of template after determining test_values
|
16
|
+
def render_body(template_name, binding)
|
17
|
+
self.template_name = template_name
|
18
|
+
unless File.exist? file_location
|
19
|
+
raise "Cannot see file at #{file_location}. "\
|
20
|
+
"Global folder is '#{Soaspec.template_folder}' and filename is '#{template_name}'"
|
21
|
+
end
|
22
|
+
request_body = File.read file_location
|
23
|
+
raise "Template at #{file_location} not parsed correctly" if request_body.strip.empty?
|
24
|
+
ERB.new(request_body).result(binding)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/soaspec/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"glossary": {
|
3
|
+
"title": "example glossary",
|
4
|
+
"GlossDiv": {
|
5
|
+
"title": "<%= test_values[:gloss_title] || 'Gloss' %>",
|
6
|
+
"GlossList": {
|
7
|
+
"GlossEntry": {
|
8
|
+
"ID": "SGML",
|
9
|
+
"SortAs": "SGML",
|
10
|
+
"GlossTerm": "Standard Generalized Markup Language",
|
11
|
+
"Acronym": "SGML",
|
12
|
+
"Abbrev": "ISO 8879:1986",
|
13
|
+
"GlossDef": {
|
14
|
+
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
15
|
+
"GlossSeeAlso": ["GML", "XML"]
|
16
|
+
},
|
17
|
+
"GlossSee": "markup"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://thomas-bayer.com/blz/" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
|
2
|
+
<env:Body>
|
3
|
+
<tns:getBank>
|
4
|
+
<tns:blz><%= test_values[:blz] || '70070010' %></tns:blz>
|
5
|
+
</tns:getBank>
|
6
|
+
</env:Body>
|
7
|
+
</env:Envelope>
|
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.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamuelGarrattIQA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -356,6 +356,7 @@ files:
|
|
356
356
|
- lib/soaspec/o_auth2.rb
|
357
357
|
- lib/soaspec/soaspec_shared_examples.rb
|
358
358
|
- lib/soaspec/spec_logger.rb
|
359
|
+
- lib/soaspec/template_reader.rb
|
359
360
|
- lib/soaspec/test_server/bank.wsdl
|
360
361
|
- lib/soaspec/test_server/get_bank.rb
|
361
362
|
- lib/soaspec/test_server/id_manager.rb
|
@@ -369,6 +370,8 @@ files:
|
|
369
370
|
- lib/soaspec/virtual_server.rb
|
370
371
|
- lib/soaspec/wsdl_generator.rb
|
371
372
|
- soaspec.gemspec
|
373
|
+
- templates/rest_template.json
|
374
|
+
- templates/soap_template.xml
|
372
375
|
- test.wsdl
|
373
376
|
- test.xml
|
374
377
|
- test_wsdl.rb
|