soaspec 0.0.24 → 0.0.25
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 +5 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +3 -1
- data/config/data/default.yml +14 -1
- data/lib/soaspec.rb +30 -4
- data/lib/soaspec/basic_soap_handler.rb +5 -0
- data/lib/soaspec/matchers.rb +1 -1
- data/lib/soaspec/rest_handler.rb +50 -5
- data/lib/soaspec/version.rb +1 -1
- data/test_rest.rb +41 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1bcd1af7218c1860476c8b8c71d8cb97236640
|
4
|
+
data.tar.gz: ac9d54164f634b5887a22eb87779eb8e34c366b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d7b2d861828838632b0ae50645b7ec87a55a63bef9513d626cfa4434e1db3c2b04b35edb58e217c40e7673acdbfa89979da4c6d9e88586b9c46e76ef07a8b3
|
7
|
+
data.tar.gz: 3bcd6ae8198b0dc230dd4fe0a12ed219248a276a5e9a7f04b04a2317512cf838e2419ddbb11a749d72f4011655071ed7b5b06b68d7cfd495e71dbfa501041bfe
|
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.0.25 / 2018-2-25
|
2
|
+
* Enhancements
|
3
|
+
* Updated rest_handler to convert JSON and XML into Hash and use it in 'contain_value'. This still needs work.
|
4
|
+
* Showed example of workflow using 'pet' url
|
5
|
+
|
1
6
|
Version 0.0.24 / 2018-2-25
|
2
7
|
* Enhancements
|
3
8
|
* Added to soaspec-generate more types when creating YAML with data (int, boolean, double and custom enumeration).
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -2,8 +2,10 @@ require 'bundler/gem_tasks'
|
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
require 'rake/clean'
|
4
4
|
|
5
|
+
ENV['folder'] ||= ''
|
6
|
+
|
5
7
|
RSpec::Core::RakeTask.new(:run_spec) do |t|
|
6
|
-
t.pattern = "spec
|
8
|
+
t.pattern = "spec/*/#{ENV['folder']}*/*_spec.rb"
|
7
9
|
end
|
8
10
|
|
9
11
|
desc 'Prepare log files'
|
data/config/data/default.yml
CHANGED
data/lib/soaspec.rb
CHANGED
@@ -22,10 +22,6 @@ require 'soaspec/rest_handler'
|
|
22
22
|
# Gem for handling SOAP and REST api tests
|
23
23
|
module Soaspec
|
24
24
|
|
25
|
-
def self.hi
|
26
|
-
puts 'Hello world!'
|
27
|
-
end
|
28
|
-
|
29
25
|
# Represents Environment parameters used in Soaspec tests
|
30
26
|
module Environment
|
31
27
|
|
@@ -61,4 +57,34 @@ module Soaspec
|
|
61
57
|
end
|
62
58
|
|
63
59
|
end
|
60
|
+
|
61
|
+
# Contains commonly used REST methods
|
62
|
+
module RestMethods
|
63
|
+
# Make REST Post Exchange
|
64
|
+
# @param [String] name Name of test displayed
|
65
|
+
# @param [Hash] params Exchange parameters
|
66
|
+
# @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
|
67
|
+
def post(name, params = {})
|
68
|
+
Exchange.new(name, method: :post, **params)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Make REST Get Exchange
|
72
|
+
# @param [String] name Name of test displayed
|
73
|
+
# @param [Hash] params Exchange parameters
|
74
|
+
# @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
|
75
|
+
def get(name, params = {})
|
76
|
+
Exchange.new(name, method: :get, **params)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Make REST Delete Exchange
|
80
|
+
# @param [String] name Name of test displayed
|
81
|
+
# @param [Hash] params Exchange parameters
|
82
|
+
# @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
|
83
|
+
def delete(name, params = {})
|
84
|
+
Exchange.new(name, method: :delete, **params)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
64
88
|
end
|
89
|
+
|
90
|
+
RestClient.log = Soaspec::SpecLogger.create
|
@@ -132,5 +132,10 @@ module Soaspec
|
|
132
132
|
xpath_value_for(exchange: exchange, xpath: path)
|
133
133
|
end
|
134
134
|
|
135
|
+
# Whether any of the keys of the Body Hash include value
|
136
|
+
def include_value?(response, expected_value)
|
137
|
+
response.body.include_value?(expected_value)
|
138
|
+
end
|
139
|
+
|
135
140
|
end
|
136
141
|
end
|
data/lib/soaspec/matchers.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative 'xpath_not_found'
|
|
7
7
|
# Whether response has any element with the provided value
|
8
8
|
RSpec::Matchers.define :contain_value do |expected|
|
9
9
|
match do |actual|
|
10
|
-
expect(actual.
|
10
|
+
expect(actual.api_class.include_value?(actual.response, expected)).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
failure_message do |actual|
|
data/lib/soaspec/rest_handler.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require_relative 'tester'
|
3
3
|
require_relative 'hash_methods'
|
4
4
|
require_relative 'xpath_not_found'
|
5
|
+
require 'json'
|
6
|
+
require 'nori'
|
5
7
|
|
6
8
|
module Soaspec
|
7
9
|
# Wraps around Savon client defining default values dependent on the soap request
|
@@ -18,7 +20,7 @@ module Soaspec
|
|
18
20
|
}
|
19
21
|
end
|
20
22
|
|
21
|
-
# Default Savon options. See
|
23
|
+
# Default Savon options. See https://github.com/rest-client/rest-client for details
|
22
24
|
# @return [Hash] Default Savon options for all BasicSoapHandler
|
23
25
|
def default_options
|
24
26
|
{
|
@@ -41,12 +43,12 @@ module Soaspec
|
|
41
43
|
end
|
42
44
|
|
43
45
|
# Setup object to handle communicating with a particular SOAP WSDL
|
44
|
-
# @param [Hash] specific_options Options defining SOAP request. WSDL, authentication
|
46
|
+
# @param [Hash] specific_options Options defining SOAP request. WSDL, authentication
|
45
47
|
def initialize(name, specific_options = {})
|
46
48
|
options = default_options.merge logging_options
|
47
49
|
options.merge! rest_resource_options
|
48
50
|
options.merge!(specific_options)
|
49
|
-
@resource = RestClient::Resource.new(base_url, options
|
51
|
+
@resource = RestClient::Resource.new(base_url, options) # @resource[url_extension].get
|
50
52
|
super
|
51
53
|
end
|
52
54
|
|
@@ -65,14 +67,57 @@ module Soaspec
|
|
65
67
|
def make_request(override_parameters)
|
66
68
|
test_values = override_parameters
|
67
69
|
test_values[:params] ||= {}
|
68
|
-
|
69
|
-
|
70
|
+
test_values[:suburl] = test_values[:suburl].to_s if test_values[:suburl]
|
71
|
+
|
72
|
+
response = case test_values[:method]
|
73
|
+
when :post
|
74
|
+
if test_values[:suburl]
|
75
|
+
@resource[test_values[:suburl]].send(test_values[:method].to_s, test_values[:payload], test_values[:params])
|
76
|
+
else
|
77
|
+
@resource.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
if test_values[:suburl]
|
81
|
+
@resource[test_values[:suburl]].send(test_values[:method].to_s, test_values[:params])
|
82
|
+
else
|
83
|
+
@resource.send(test_values[:method].to_s, test_values[:params])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
Soaspec::SpecLogger.add_to(response)
|
87
|
+
response
|
70
88
|
end
|
71
89
|
|
72
90
|
def include_in_body?(response, expected)
|
73
91
|
response.body.include? expected
|
74
92
|
end
|
75
93
|
|
94
|
+
# Convert XML or JSON response into a Hash
|
95
|
+
def extract_hash(response)
|
96
|
+
raise "Empty Body. Can't assert on it" if response.body.empty?
|
97
|
+
type = case response.body[0]
|
98
|
+
when '<'
|
99
|
+
:xml
|
100
|
+
when '{'
|
101
|
+
:json
|
102
|
+
else
|
103
|
+
:unknown
|
104
|
+
end
|
105
|
+
|
106
|
+
case type
|
107
|
+
when :json
|
108
|
+
JSON.parse(response.body).transform_keys_to_symbols
|
109
|
+
when :xml
|
110
|
+
parser = Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
|
111
|
+
parser.parse(response.body)
|
112
|
+
else
|
113
|
+
raise "Neither XML nor JSON detected. It is #{type}. Don't know how to parse It is #{response.body}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def include_value?(response, expected)
|
118
|
+
extract_hash(response).include_value? expected
|
119
|
+
end
|
120
|
+
|
76
121
|
def status_code_for(response)
|
77
122
|
response.code
|
78
123
|
end
|
data/lib/soaspec/version.rb
CHANGED
data/test_rest.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
|
2
2
|
require 'rest-client'
|
3
|
+
require 'json'
|
4
|
+
require 'data_magic'
|
3
5
|
|
4
6
|
options = {
|
5
7
|
headers: {
|
6
8
|
# accept: "application/xml",
|
7
|
-
accept: "application/json"
|
8
|
-
|
9
|
+
accept: "application/json",
|
10
|
+
content_type: "application/json"
|
9
11
|
# log: Logger.new('logs/traffic.log')
|
10
12
|
}
|
11
13
|
}
|
@@ -16,43 +18,59 @@ data_string = <<-EOF
|
|
16
18
|
{
|
17
19
|
"id": 1,
|
18
20
|
"category": {
|
19
|
-
"id":
|
21
|
+
"id": 1,
|
20
22
|
"name": "string"
|
21
23
|
},
|
22
|
-
"name": "
|
24
|
+
"name": "test_rest",
|
23
25
|
"photoUrls": [
|
24
26
|
"string"
|
25
27
|
],
|
26
28
|
"tags": [
|
27
29
|
{
|
28
|
-
"id":
|
30
|
+
"id": 1,
|
29
31
|
"name": "string"
|
30
32
|
}
|
31
33
|
],
|
32
|
-
"status": "
|
34
|
+
"status": "sold"
|
33
35
|
}
|
34
36
|
EOF
|
35
37
|
|
36
38
|
|
37
39
|
data = {
|
38
|
-
id
|
39
|
-
category
|
40
|
-
id
|
41
|
-
name
|
40
|
+
'id' => '1',
|
41
|
+
'category' => {
|
42
|
+
'id' => '1',
|
43
|
+
'name' => "string"
|
42
44
|
},
|
43
|
-
name
|
44
|
-
photoUrls
|
45
|
+
'name' => "test_rest",
|
46
|
+
'photoUrls' => [
|
45
47
|
"string"
|
46
48
|
],
|
47
|
-
tags
|
49
|
+
'tags' => [
|
48
50
|
{
|
49
|
-
id
|
50
|
-
name
|
51
|
+
'id' => '1',
|
52
|
+
'name' => "string"
|
51
53
|
}
|
52
54
|
],
|
53
|
-
status
|
55
|
+
'status' => "sold"
|
54
56
|
}
|
55
57
|
|
58
|
+
# puts data.to_s
|
59
|
+
#
|
60
|
+
|
61
|
+
include DataMagic
|
62
|
+
|
63
|
+
id = '1'
|
64
|
+
default = data_for 'default/pet'
|
65
|
+
merged_result = default.merge({ 'id' => id })
|
66
|
+
|
67
|
+
#converted_data = JSON.generate(data).to_s
|
68
|
+
converted_data = JSON.generate(merged_result).to_s
|
69
|
+
|
70
|
+
puts converted_data
|
71
|
+
# puts 'data'
|
72
|
+
# puts data_string
|
73
|
+
|
56
74
|
resource = RestClient::Resource.new('http://petstore.swagger.io/v2', options)
|
57
75
|
# begin
|
58
76
|
# response = resource['pet'].post(data)
|
@@ -64,13 +82,17 @@ begin
|
|
64
82
|
#response = resource['store/order/1'].get
|
65
83
|
#response = resource['store/inventory'].get
|
66
84
|
#
|
67
|
-
response = resource['pet/findByStatus?status=sold'].get(accept: 'application/xml')
|
68
|
-
|
85
|
+
#response = resource['pet/findByStatus?status=sold'].get(accept: 'application/xml')
|
86
|
+
|
87
|
+
|
88
|
+
#response = resource['pet'].post(data_string)
|
89
|
+
#response = resource['pet'].post(converted_data)
|
90
|
+
response = resource['pet/' + id].get
|
91
|
+
#response = resource['pet/' + id].delete
|
69
92
|
rescue RestClient::ExceptionWithResponse => e
|
70
93
|
puts e.response
|
71
94
|
end
|
72
95
|
|
73
|
-
#puts response.to_s
|
74
96
|
puts response.body
|
75
97
|
puts response.code
|
76
98
|
puts response.request
|
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.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamuelGarrattIQA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|