soaspec 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56ac205ff7703289265257468f900434409c01a9
4
- data.tar.gz: 484529924c2c37a100e95670ce57e1d3e136b07e
3
+ metadata.gz: 1c1e38e1213ce6461e1bca9a181d6be4130295a4
4
+ data.tar.gz: 9e2170b74242c21f8c9ac3fe51fccf5676a4db49
5
5
  SHA512:
6
- metadata.gz: feae39ed4711cdf52ad5f1090e143af59e12dfb565c569ae5e864242692bf029fe132ec58279f52f430d3c7f456d773e8d2958736fd7836c14bda5b8cca72f17
7
- data.tar.gz: b2c63f622cecd0e6e39eb7b6ae9a2a432a9aafbd02b2fa8cf6bce1ed0355c5c75888f7518b606c16775beeef6f5071fccb2a1b3e5cd95887d36414b531569767
6
+ metadata.gz: 9c41202a31e2e2740688628efada58bb0631cd91b5f1b60f624219d0f254c1cb5e823f00d2ea2451f16890b8059594fe8add22c9db4cb4d4db3acca8f06dcd90
7
+ data.tar.gz: 76bbf2ad8ba5a5e1333cb33653ba45220c9dcca5d8257b7e5c235dc849dfd85ea0b5783d3e1100ee7b606c3072a9cf95c5e4e362e91ba2b4f3c1a8586ccb0d05
data/.gitlab-ci.yml CHANGED
@@ -18,6 +18,23 @@ cucumber:
18
18
  script:
19
19
  - bundle exec cucumber
20
20
 
21
+ code_quality:
22
+ image: docker:stable
23
+ variables:
24
+ DOCKER_DRIVER: overlay2
25
+ allow_failure: true
26
+ services:
27
+ - docker:stable-dind
28
+ script:
29
+ - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
30
+ - docker run
31
+ --env SOURCE_CODE="$PWD"
32
+ --volume "$PWD":/code
33
+ --volume /var/run/docker.sock:/var/run/docker.sock
34
+ "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
35
+ artifacts:
36
+ paths: [gl-code-quality-report.json]
37
+
21
38
  pages:
22
39
  stage: deploy
23
40
  dependencies:
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Version 0.1.3
2
+ * Enhancements
3
+ * Ability to set template folder
4
+ * Json Path handle multiple paths separated by commas
5
+
1
6
  Version 0.1.1
2
7
  * Enhancements
3
8
  * Added ability to turn off logs (helpful if making a lot of API calls)
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ## Getting Started
26
26
 
27
- To create a new test suite using this you can use the 'soaspec-init' binary.
27
+ To create a new test suite using this you can use the 'soaspec' binary.
28
28
 
29
29
  Example:
30
30
 
@@ -51,10 +51,38 @@ for such defaults. When describing an API override this in 'savon_options' metho
51
51
 
52
52
  See specs for example of usage. This will be added to later.
53
53
 
54
- ### Recommended
54
+ Basically you create a class inheriting from a ‘Handler’ class for each web service that’s tested.
55
+ In this class you define the common parameters used for testing this class.
56
+
57
+ For example:
58
+
59
+ ```ruby
60
+ class PuppyService < Soaspec::RestHandler
61
+
62
+ headers accept: 'application/json', content_type: 'application/json'
63
+
64
+ base_url 'http://petstore.swagger.io/v2/pet'
65
+
66
+ element :id, :id
67
+ element :category_id, '$..category.id'
68
+ end
69
+ ```
70
+
71
+ Then you reference this class in creating `Exchange`’s (representing a request / response pair).
72
+ Upon initialization of the Exchange object or later on through setters, parameters specific to this request are set
73
+ All getters of the Exchange are on the response & will implicitly trigger the API request to be made.
74
+
75
+ For example:
76
+
77
+ ```ruby
78
+ context PuppyService.new('Order Puppies') do
79
+ describe post(:create_pet, body: { status: 'sold' }) do # Post with status as sold in request
80
+ its(['status']) { is_expected.to eq 'sold' } # Check responses status is sold
81
+ end
82
+ end
83
+ ```
55
84
 
56
- It is recommended that a class be created representing a Web Service Operation or REST call. Then tests refer back to
57
- that class. See 'weather_web_service.rb' class in spec/soaspec/soap folder for example.
85
+ ### Recommended
58
86
 
59
87
  If you find having a large backtrace on errors or RSpec shared examples such as 'success scenarios' this can shorten the
60
88
  backtrace.
data/lib/soaspec.rb CHANGED
@@ -32,9 +32,13 @@ require 'soaspec/wsdl_generator'
32
32
  # Gem for handling SOAP and REST api tests
33
33
  module Soaspec
34
34
 
35
+ @template_folder = 'template'
36
+
35
37
  class << self
36
38
  # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
37
39
  attr_writer :debug_oauth
40
+ # Folder used to store templates for API calls
41
+ attr_accessor :template_folder
38
42
 
39
43
  # Folder used to store credentials
40
44
  # Used in auth2_file command
@@ -75,6 +79,11 @@ module Soaspec
75
79
  @debug_oauth || false
76
80
  end
77
81
 
82
+ # @return [String] Folder used to store templates for API calls
83
+ # def template_folder
84
+ # @template_folder || 'template'
85
+ # end
86
+
78
87
  # Whether to log all API traffic
79
88
  def log_api_traffic=(set)
80
89
  @log_api_traffic = set
@@ -229,9 +229,12 @@ module Soaspec
229
229
  return result.inner_text if attribute.nil?
230
230
  return result.attributes[attribute].inner_text
231
231
  when :json
232
- matching_values = json_path_values_for(response, path, attribute: attribute)
233
- raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty?
234
- matching_values.first
232
+ paths_to_check = path.split(',')
233
+ matching_values = paths_to_check.collect do |path_to_check|
234
+ json_path_values_for(response, path_to_check, attribute: attribute)
235
+ end.reject(&:empty?)
236
+ raise NoElementAtPath, "Path '#{path}' not found in '#{response.body}'" if matching_values.empty?
237
+ matching_values.first.first
235
238
  when :hash
236
239
  response.dig(path.split('.')) # Use path as Hash dig expression separating params via '.' TODO: Unit test
237
240
  else
@@ -273,7 +276,7 @@ module Soaspec
273
276
  if test_values[:body]
274
277
  test_values[:payload] = JSON.generate(hash_used_in_request(test_values[:body])).to_s
275
278
  elsif @request_option == :template
276
- request_body = File.read('template/' + template_name)
279
+ request_body = File.read(File.join(Soaspec.template_folder, template_name))
277
280
  ERB.new(request_body).result(binding)
278
281
  else
279
282
  test_values[:payload]
@@ -101,7 +101,7 @@ module Soaspec
101
101
  test_values = request_body_params request_parameters
102
102
  begin
103
103
  if @request_option == :template
104
- request_body = File.read('template/' + template_name)
104
+ request_body = File.read(File.join(Soaspec.template_folder, template_name))
105
105
  render_body = ERB.new(request_body).result(binding)
106
106
  client.call(operation, xml: render_body) # Call the SOAP operation with the request XML provided
107
107
  elsif @request_option == :hash
@@ -1,4 +1,3 @@
1
-
2
1
  # Raised to represent when there's no element at an Xpath
3
2
  class NoElementAtPath < StandardError
4
3
  def initialize(msg = 'No element at path found')
@@ -11,4 +10,4 @@ class NoElementInHash < StandardError
11
10
  def initialize(msg = 'No element in Hash found')
12
11
  super
13
12
  end
14
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler