soaspec 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5fd821e9ac9431eda83eb84e36cf5901cba2e1e
4
- data.tar.gz: 9557f06d415ecbf523d9d3d4c4ff8235575da19a
3
+ metadata.gz: a77bc501e360feb0326d9e0453fd134f534488d9
4
+ data.tar.gz: 0a5543099fdea5c919f5a6fcb10c15823f9d8889
5
5
  SHA512:
6
- metadata.gz: fc8a3eca5fead9e365fad90c72bb5943a83889cebf3c2bf5bac286878a1791ebcbcae4570692f0679239002dbca4889015d8709bb7779d23073d54b144a6710e
7
- data.tar.gz: 12332a4d42e8738640fd9dbafa655693bcc4ba2f093ed009812f35ce6fcf2f58d9e984325ffd7f23c7f47fc2f37cab8172ce0239f55138b648d7598cad51355d
6
+ metadata.gz: 737e926e4fd459e15f4174c22991dd792d2c891f60ba48b36b538f9bf6beda5c652b4e32f50ce1cfdf189841da7bec26920e3f0ea284ff26417424271375dfc2
7
+ data.tar.gz: ad5987dbd6099d7887fc0186de8806821c973138f7e1229ec7a7aba179085a20ca6a011850e4c97f69006950bf63bba98d246ae16bac180b2a4ec9fce8d8617f
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.1.9
2
+ * Enhancements
3
+ * Finally move `soaspec-virtual-server` into same binary as `soaspec` utilising Thor
4
+
1
5
  Version 0.1.8
2
6
  * Bug fix
3
7
  * Could not see OAuth parameters sent in logs when setting oauth debugging to true
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ CLOBBER.include 'logs/*'
18
18
  desc 'Start virtual web service'
19
19
  task :start_test_server do
20
20
  mkdir_p 'logs'
21
- ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
21
+ ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec', 'virtual_server', err: %w[logs/test_server.log w]).to_s
22
22
  sleep 2 # Wait a little for virtual server to start up
23
23
  puts 'Running test server at pid ' + ENV['test_server_pid']
24
24
  end
data/exe/soaspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  require 'thor'
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  require 'savon'
7
7
  require 'soaspec'
8
8
 
@@ -32,8 +32,8 @@ module Soaspec
32
32
  create_file(filename: 'Gemfile')
33
33
  create_file(filename: 'Rakefile')
34
34
  create_file(filename: '.rspec')
35
- create_file(filename: '.travis.yml') if options[:ci] == 'travis'
36
35
  create_file(filename: 'README.md')
36
+ create_file(filename: '.travis.yml') if options[:ci] == 'travis'
37
37
  if type == 'soap'
38
38
  create_file filename: 'lib/blz_service.rb'
39
39
  create_file filename: 'lib/shared_example.rb'
@@ -104,6 +104,15 @@ module Soaspec
104
104
  end
105
105
  end
106
106
 
107
+ long_desc <<-LONGDESC
108
+ Run virtual web services on localhost. See root for documentation of web services provided.
109
+ LONGDESC
110
+ desc 'virtual_server [port]', 'Run virtual web service on localhost'
111
+ def virtual_server(port = '4999')
112
+ ENV['port'] = port
113
+ require 'soaspec/virtual_server'
114
+ Soaspec::VirtualServer.run!(Port: port)
115
+ end
107
116
  end
108
117
  end
109
118
 
@@ -13,7 +13,7 @@ task default: :spec # This runs the 'spec' task by default when no task is menti
13
13
  <% if @virtual %>
14
14
  desc 'Start virtual web service'
15
15
  task :start_test_server do
16
- ENV['test_server_pid'] = Process.spawn('soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
16
+ ENV['test_server_pid'] = Process.spawn('soaspec', 'virtual_server', err: %w[logs/test_server.log w]).to_s
17
17
  puts 'Running test server at pid ' + ENV['test_server_pid']
18
18
  sleep 0.5 # Wait a little for virtual server to start up
19
19
  end
@@ -11,6 +11,7 @@ module Soaspec
11
11
  # @param [String] api_username Username to use which can be set by Soaspec::ExchangeHandler
12
12
  def initialize(params, api_username)
13
13
  raise 'client_id and client_secret not set' unless params[:client_id] && params[:client_secret]
14
+ raise 'token_url mandatory' unless params[:token_url]
14
15
  self.params = params
15
16
  params[:username] = api_username || ERB.new(params[:username]).result(binding) if params[:username]
16
17
  params[:security_token] = ERB.new(params[:security_token]).result(binding) if params[:security_token]
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.1.8'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  end
@@ -0,0 +1,153 @@
1
+ require 'soaspec'
2
+ require 'sinatra'
3
+ require 'sinatra/basic_auth'
4
+ require 'docdsl'
5
+ require 'nokogiri'
6
+ require 'erb'
7
+ require 'json'
8
+ require 'faker'
9
+
10
+ module Soaspec
11
+ # Used to run virtual web service on localhost. This makes tests more reliable and faster
12
+ # First argument overrides the default port
13
+ class VirtualServer < Sinatra::Application
14
+ set :bind, '0.0.0.0'
15
+ set :port, (ENV['port'] || 4999).to_i
16
+
17
+ register Sinatra::DocDsl
18
+
19
+ page do
20
+ title 'Soaspec Virtual Services'
21
+ header 'Perform efficient API testing with Ruby'
22
+ introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
23
+ end
24
+
25
+ documentation 'Nothing under /. Go look at /docs' do
26
+ response 'redirects to the documentation page'
27
+ status 303
28
+ end
29
+ get '/' do
30
+ redirect '/docs'
31
+ end
32
+
33
+ doc_endpoint '/docs'
34
+
35
+ documentation 'Used to test attributes' do
36
+ response 'A simple Note XML with a date attribute'
37
+ end
38
+ get '/test_attribute' do
39
+ Soaspec::TestServer::TestAttribute.note
40
+ end
41
+
42
+ documentation 'Used to test namespaces' do
43
+ response 'XML with 2 namespaces and same elements inside it'
44
+ end
45
+ get '/namespace' do
46
+ Soaspec::TestServer::TestNamespace.food
47
+ end
48
+
49
+ documentation 'Used for showing a simple difference in value depending on the id used' do
50
+ param :num, 'Number of tester'
51
+ param :id, 'Test parameter'
52
+ response 'JSON with success or true or false and the id sent
53
+ Idea is for tester to find the id that causes a failure (the fake "defect")
54
+ '
55
+ end
56
+ get '/packages/:num/:id' do |num, id|
57
+ JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
58
+ end
59
+
60
+ post '/packages/developed' do
61
+ Soaspec::TestServer::IdManager.developed = request.body.include?('true')
62
+ Soaspec::TestServer::IdManager.developed.to_s
63
+ end
64
+
65
+ # Used for simple testing of posing
66
+ documentation 'Simply sends the response body back'
67
+ post '/echoer' do
68
+ request.body
69
+ end
70
+
71
+ documentation "Simulate retrieving an ouath token Passed to '/invoices'"
72
+ post '/as/token.oauth2' do
73
+ Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
74
+ [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
75
+ end
76
+
77
+ documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
78
+ get '/invoice/:id' do |id|
79
+ JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
80
+ end
81
+
82
+ documentation 'This is returned when a query for the WSDL is made' do
83
+ response 'WSDL containing SCHEMA information'
84
+ end
85
+ get '/BLZService' do
86
+ [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
87
+ end
88
+
89
+ authorize do |username, password|
90
+ username == 'admin' && password == 'secret'
91
+ end
92
+
93
+ protect do
94
+ documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
95
+ response 'Secret text'
96
+ end
97
+ get '/basic_secrets' do
98
+ 'Secret data'
99
+ end
100
+
101
+ documentation 'This is the basic service being hit by SOAP actions'
102
+ post '/BLZService' do
103
+ Soaspec::TestServer::GetBank.response_for request
104
+ end
105
+ end
106
+
107
+ documentation 'Used for testing storage of data' do
108
+ payload 'Puppy JSON',
109
+ Name: 'Test', Failure_Type__c: 'Fail'
110
+ end
111
+ post '/test/puppy' do
112
+ request_hash = JSON.parse(request.body.string)
113
+ id = Soaspec::TestServer::PuppyService.new_id
114
+ Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
115
+ Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
116
+ response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
117
+ JSON.generate response_hash
118
+ end
119
+
120
+ documentation 'Used for testing retrieving storage of data'
121
+ get '/test/puppy/:id' do |id|
122
+ result = Soaspec::TestServer::PuppyService.data[id.to_i]
123
+ JSON.generate result
124
+ end
125
+
126
+ documentation 'Used for testing updating data'
127
+ patch '/test/puppy/:id' do |id|
128
+ request_hash = JSON.parse(request.body.string)
129
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
130
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
131
+ JSON.generate response_hash
132
+ end
133
+
134
+ documentation 'Used for testing the handling of JSON path' do
135
+ response 'JSON with multiple elements of the same name at different nested levels'
136
+ end
137
+ get '/test/multiple_json' do
138
+ <<-BOOKS
139
+ {"store":
140
+ {"bicycle":
141
+ {"price":19.95, "color":"red"},
142
+ "book":[
143
+ {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
144
+ {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
145
+ {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
146
+ {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
147
+ ]
148
+ }
149
+ }
150
+ BOOKS
151
+ end
152
+ end
153
+ 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.8
4
+ version: 0.1.9
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-07 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -310,7 +310,6 @@ email:
310
310
  - samuel.garratt@integrationqa.com
311
311
  executables:
312
312
  - soaspec
313
- - soaspec-virtual-server
314
313
  - xml_to_yaml_file
315
314
  extensions: []
316
315
  extra_rdoc_files: []
@@ -327,7 +326,6 @@ files:
327
326
  - Rakefile
328
327
  - Todo.md
329
328
  - exe/soaspec
330
- - exe/soaspec-virtual-server
331
329
  - exe/xml_to_yaml_file
332
330
  - lib/soaspec.rb
333
331
  - lib/soaspec/core_ext/hash.rb
@@ -368,6 +366,7 @@ files:
368
366
  - lib/soaspec/test_server/test_attribute.rb
369
367
  - lib/soaspec/test_server/test_namespace.rb
370
368
  - lib/soaspec/version.rb
369
+ - lib/soaspec/virtual_server.rb
371
370
  - lib/soaspec/wsdl_generator.rb
372
371
  - soaspec.gemspec
373
372
  - test.wsdl
@@ -1,156 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
- require 'soaspec'
5
- require 'sinatra'
6
- require 'sinatra/basic_auth'
7
- require 'docdsl'
8
- require 'nokogiri'
9
- require 'erb'
10
- require 'json'
11
- require 'faker'
12
-
13
- # Used to run virtual web service on localhost. This makes tests more reliable and faster
14
- # First argument overrides the default port
15
- class SoaspecVirtualServer < Sinatra::Application
16
- set :bind, '0.0.0.0'
17
- set :port, (ARGV[0] || 4999).to_i
18
-
19
- register Sinatra::DocDsl
20
-
21
- page do
22
- title 'Soaspec Virtual Services'
23
- header 'Perform efficient API testing with Ruby'
24
- introduction 'This has some simple virtual services aimed at helping you with testing your Ruby API code.'
25
- end
26
-
27
- documentation 'Nothing under /. Go look at /docs' do
28
- response 'redirects to the documentation page'
29
- status 303
30
- end
31
- get '/' do
32
- redirect '/docs'
33
- end
34
-
35
- doc_endpoint '/docs'
36
-
37
- documentation 'Used to test attributes' do
38
- response 'A simple Note XML with a date attribute'
39
- end
40
- get '/test_attribute' do
41
- Soaspec::TestServer::TestAttribute.note
42
- end
43
-
44
- documentation 'Used to test namespaces' do
45
- response 'XML with 2 namespaces and same elements inside it'
46
- end
47
- get '/namespace' do
48
- Soaspec::TestServer::TestNamespace.food
49
- end
50
-
51
- documentation 'Used for showing a simple difference in value depending on the id used' do
52
- param :num, 'Number of tester'
53
- param :id, 'Test parameter'
54
- response 'JSON with success or true or false and the id sent
55
- Idea is for tester to find the id that causes a failure (the fake "defect")
56
- '
57
- end
58
- get '/packages/:num/:id' do |num, id|
59
- JSON.generate(success: Soaspec::TestServer::IdManager.result_for(num, id), id: id)
60
- end
61
-
62
- post '/packages/developed' do
63
- Soaspec::TestServer::IdManager.developed = request.body.include?('true')
64
- Soaspec::TestServer::IdManager.developed.to_s
65
- end
66
-
67
- # Used for simple testing of posing
68
- documentation 'Simply sends the response body back'
69
- post '/echoer' do
70
- request.body
71
- end
72
-
73
- documentation "Simulate retrieving an ouath token Passed to '/invoices'"
74
- post '/as/token.oauth2' do
75
- Soaspec::TestServer::Invoices.user_used = request.env['rack.request.form_hash']['username']
76
- [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
77
- end
78
-
79
- documentation 'Replies with HTTP authorization and user set in /as/token.oauth2'
80
- get '/invoice/:id' do |id|
81
- JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'], user: Soaspec::TestServer::Invoices.user_used)
82
- end
83
-
84
- documentation 'This is returned when a query for the WSDL is made' do
85
- response 'WSDL containing SCHEMA information'
86
- end
87
- get '/BLZService' do
88
- [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
89
- end
90
-
91
- authorize do |username, password|
92
- username == 'admin' && password == 'secret'
93
- end
94
-
95
- protect do
96
- documentation "Get path used to test basic auth. User is 'admin' & password is 'secret'" do
97
- response 'Secret text'
98
- end
99
- get '/basic_secrets' do
100
- 'Secret data'
101
- end
102
-
103
- documentation 'This is the basic service being hit by SOAP actions'
104
- post '/BLZService' do
105
- Soaspec::TestServer::GetBank.response_for request
106
- end
107
- end
108
-
109
- documentation 'Used for testing storage of data' do
110
- payload 'Puppy JSON',
111
- Name: 'Test', Failure_Type__c: 'Fail'
112
- end
113
- post '/test/puppy' do
114
- request_hash = JSON.parse(request.body.string)
115
- id = Soaspec::TestServer::PuppyService.new_id
116
- Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
117
- Soaspec::TestServer::PuppyService.data[id][:Failure_Type__c] = request_hash['Failure_Type__c'] if request_hash['Failure_Type__c']
118
- response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
119
- JSON.generate response_hash
120
- end
121
-
122
- documentation 'Used for testing retrieving storage of data'
123
- get '/test/puppy/:id' do |id|
124
- result = Soaspec::TestServer::PuppyService.data[id.to_i]
125
- JSON.generate result
126
- end
127
-
128
- documentation 'Used for testing updating data'
129
- patch '/test/puppy/:id' do |id|
130
- request_hash = JSON.parse(request.body.string)
131
- Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
132
- response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
133
- JSON.generate response_hash
134
- end
135
-
136
- documentation 'Used for testing the handling of JSON path' do
137
- response 'JSON with multiple elements of the same name at different nested levels'
138
- end
139
- get '/test/multiple_json' do
140
- <<-BOOKS
141
- {"store":
142
- {"bicycle":
143
- {"price":19.95, "color":"red"},
144
- "book":[
145
- {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
146
- {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
147
- {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
148
- {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
149
- ]
150
- }
151
- }
152
- BOOKS
153
- end
154
- end
155
-
156
- SoaspecVirtualServer.run!