soaspec 0.0.48 → 0.0.49

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: d66f4dd1240984bed39579008a20ca1c08127b52
4
- data.tar.gz: bb11a11eb0d9c6d51ad10f6f95a181c2eea2d572
3
+ metadata.gz: c3182f568caa56ca4f1f2982fd34cd03add94841
4
+ data.tar.gz: 0df96f12941e1b74393ebe45621d583f2e1ff956
5
5
  SHA512:
6
- metadata.gz: 5fe6dfb9d15a1357929a447b1f02d2dd88703880ed22310df523a309c1d487c583101253f212012dc7aae7a1df1d278d374dd65bd4169223ecd086863935c16a
7
- data.tar.gz: 05d5655a71a73503dfa09b511a6bff38bd906fb4079e604b28b23a57b045dd5d7bb5940e9083ed7e46f9051a1b076dc7c9a15b5f3dba983c56e82fea484223fe
6
+ metadata.gz: 932fe45f675620f1afa72ef36cb84fa8c54f6beebc7dd22686258fdf27c2f158a70b0a82bb7f280b111c81ae7657a01d7c5357af745247df58406efb764fd85d
7
+ data.tar.gz: f0e01064bacd3a5e10f59c24b4a74fdc7c471579012a61088b60d715912113696624b1893abbbbdb0de7b63e7a70dfe46c5f450041a591cc9a4f2e9f6b8daaab
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.48)
4
+ soaspec (0.0.49)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
data/Todo.md CHANGED
@@ -1,4 +1,9 @@
1
+ * ouath2 - handler
2
+ * Need to handle where username and password and no security token
3
+ * Perform ERB on values taken by file
4
+
1
5
  * SoapHandler - define exhange method for each SOAP operation
6
+ * Accessors - similar to HappyMapper
2
7
  * exchange add fields to overide parameters to support cucumber steps. exchange[from_temp] =
3
8
  * Demonstrate using Cucumber
4
9
  * Give examples and convenience methods for building classes for each SOAP or REST operation
@@ -19,7 +19,7 @@ require 'soaspec/hash_methods'
19
19
  require 'soaspec/spec_logger'
20
20
  require 'soaspec/exe_helpers'
21
21
  require 'soaspec/exchange_handlers/rest_handler'
22
- require 'soaspec/accessors'
22
+ require 'soaspec/exchange_handlers/handler_accessors'
23
23
  require 'soaspec/interpreter'
24
24
  require 'soaspec/not_found_errors'
25
25
 
@@ -28,6 +28,12 @@ class Exchange
28
28
  @override_parameters = override_parameters
29
29
  @retry_for_success = false
30
30
  self.retry_count = 3
31
+ puts 'ELE ' + @api_class.elements.to_s
32
+ @api_class.elements.each do |element|
33
+ define_singleton_method(element) do
34
+ @api_class.__send__(element, response)
35
+ end
36
+ end
31
37
  end
32
38
 
33
39
  # Make request to handler with parameters defined
@@ -1,12 +1,21 @@
1
1
 
2
+ require_relative 'handler_accessors'
3
+
2
4
  module Soaspec
5
+
3
6
  # Inherit this for a class describing how to implement a particular exchange.
4
7
  # Has basic methods common for methods defining RSpec tests in YAML
5
8
  class ExchangeHandler
9
+ extend Soaspec::HandlerAccessors
6
10
 
7
11
  # Retrieve the name of the template file to be used in the API request
8
12
  attr_reader :template_name
9
13
 
14
+ # Explicitly defined elements for which a path has been predefined
15
+ def elements
16
+ @elements || []
17
+ end
18
+
10
19
  # Set instance variable name
11
20
  # @param [String, Symbol] name Name used when describing API test
12
21
  # @param [Hash] options Parameters defining handler. Used in descendants
@@ -30,6 +39,7 @@ module Soaspec
30
39
  end
31
40
 
32
41
  # Set the request option type and the template name
42
+ # Erb is used to parse the template file, executing Ruby code in `<%= %>` blocks to work out the final request
33
43
  # @param [String] name Name of file inside 'template' folder excluding extension
34
44
  def template_name=(name)
35
45
  @request_option = :template
@@ -1,7 +1,7 @@
1
1
  module Soaspec
2
2
  # Describes methods test handlers use to easily set attributes
3
3
  # Some are included in 'success scenarios' and to configure the request sent
4
- module Accessors
4
+ module HandlerAccessors
5
5
 
6
6
  # Defines expected_mandatory_elements method used in 'success_scenario' shared examples
7
7
  # to indicate certain elements must be present
@@ -60,5 +60,19 @@ module Soaspec
60
60
  end
61
61
  end
62
62
 
63
+ # Links a particular path to a meaningful name. This will use the 'value_from_path' method which
64
+ # should be implemented by each ExchangeHandler
65
+ # @param [String, Symbol] name Method name used to access element
66
+ # @param [String, Symbol] path Path to find object (e.g, XPath, JSONPath)
67
+ def element(name, path)
68
+ # puts 'Making with ' + name.to_s + path
69
+ @elements ||= []
70
+ @elements << name.to_s # Add record to list of elements used by exchange
71
+ # puts 'NOW ELE' + @elements.to_s
72
+ define_method(name.to_s) do |response|
73
+ value_from_path(response, path.to_s)
74
+ end
75
+ end
76
+
63
77
  end
64
78
  end
@@ -2,7 +2,7 @@
2
2
  require_relative 'exchange_handler'
3
3
  require_relative '../hash_methods'
4
4
  require_relative '../not_found_errors'
5
- require_relative '../accessors'
5
+ require_relative 'handler_accessors'
6
6
  require_relative '../interpreter'
7
7
  require 'json'
8
8
  require 'jsonpath'
@@ -34,6 +34,20 @@ module Soaspec
34
34
  username: username,
35
35
  password: (password + security_token),
36
36
  multipart: true
37
+ },
38
+ cache_control: 'no_cache',
39
+ verify_ssl: false
40
+ )
41
+ elsif password && username
42
+ RestClient.post(
43
+ token_url,
44
+ {
45
+ grant_type: 'password',
46
+ client_id: client_id,
47
+ client_secret: client_secret,
48
+ username: username,
49
+ password: password,
50
+ multipart: true
37
51
  },
38
52
  cache_control: 'no_cache',
39
53
  verify_ssl: false
@@ -41,11 +55,11 @@ module Soaspec
41
55
  else
42
56
  RestClient.post(
43
57
  token_url,
44
- {
45
- grant_type: 'client_credentials',
46
- client_id: client_id,
47
- client_secret: client_secret
48
- },
58
+ {
59
+ grant_type: 'client_credentials',
60
+ client_id: client_id,
61
+ client_secret: client_secret
62
+ },
49
63
  cache_control: 'no_cache',
50
64
  verify_ssl: false
51
65
  )
@@ -58,7 +72,7 @@ module Soaspec
58
72
  # @param [String] path_to_filename Will have Soaspec.credentials_folder appended to it if set
59
73
  def oauth2_file(path_to_filename)
60
74
  full_path = Soaspec.credentials_folder ? File.join(Soaspec.credentials_folder, path_to_filename + '.yml') : path_to_filename + '.yml'
61
- file_hash = YAML.load_file(full_path)
75
+ file_hash = eval(ERB.new(YAML.load_file(full_path).to_s).result(binding))
62
76
  raise 'File at ' + full_path + ' is not a hash ' unless file_hash.is_a? Hash
63
77
  oauth_hash = file_hash.transform_keys_to_symbols
64
78
  oauth2 **oauth_hash
@@ -69,7 +83,6 @@ module Soaspec
69
83
  # Wraps around Savon client defining default values dependent on the soap request
70
84
  class RestHandler < ExchangeHandler
71
85
  extend Soaspec::RestAccessors
72
- extend Soaspec::Accessors
73
86
 
74
87
  # Savon client used to make SOAP calls
75
88
  attr_accessor :client
@@ -2,7 +2,7 @@
2
2
  require_relative 'exchange_handler'
3
3
  require_relative '../hash_methods'
4
4
  require_relative '../not_found_errors'
5
- require_relative '../accessors'
5
+ require_relative 'handler_accessors'
6
6
  require_relative '../interpreter'
7
7
 
8
8
  module Soaspec
@@ -20,7 +20,6 @@ module Soaspec
20
20
 
21
21
  # Wraps around Savon client defining default values dependent on the soap request
22
22
  class SoapHandler < ExchangeHandler
23
- extend Soaspec::Accessors
24
23
  extend Soaspec::SoapAccessors
25
24
 
26
25
  # Savon client used to make SOAP calls
@@ -89,8 +88,7 @@ module Soaspec
89
88
 
90
89
  # Used in together with Exchange request that passes such override parameters
91
90
  def make_request(override_parameters)
92
- test_values = override_parameters # Used in Erb
93
- # Erb parses template file, executing Ruby code in `<% %>` blocks to work out final request
91
+ test_values = override_parameters # Used in making request via hash or in template via Erb
94
92
  test_values = test_values.transform_keys_to_symbols if Soaspec.always_use_keys?
95
93
  begin
96
94
  if @request_option == :template
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.48'
2
+ VERSION = '0.0.49'
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.0.48
4
+ version: 0.0.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,9 +167,9 @@ files:
167
167
  - exe/soaspec-init
168
168
  - exe/xml_to_yaml_file
169
169
  - lib/soaspec.rb
170
- - lib/soaspec/accessors.rb
171
170
  - lib/soaspec/exchange.rb
172
171
  - lib/soaspec/exchange_handlers/exchange_handler.rb
172
+ - lib/soaspec/exchange_handlers/handler_accessors.rb
173
173
  - lib/soaspec/exchange_handlers/rest_handler.rb
174
174
  - lib/soaspec/exchange_handlers/rest_methods.rb
175
175
  - lib/soaspec/exchange_handlers/soap_handler.rb