webspicy 0.5.0 → 0.6.0

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: 2f7e458fbf3c7ac65bd95574e127f16791f56391
4
- data.tar.gz: e2cdfa60d3e9ba3831bd49cb4a6931e675752eea
3
+ metadata.gz: 03f975ac99f95fc2b6ce4bc70b1bebd93ca6052f
4
+ data.tar.gz: 59ab9a40fc6f3f8aa076b762aff29507cba7a3af
5
5
  SHA512:
6
- metadata.gz: 94edf71925034c01b1297c58e049f2f4729330c80e4db0e601e24f9409b6d609f88b24b8b8f8c707d3d6e52c7cf18dc137d948d4728e222e2305bf097ca1dfd8
7
- data.tar.gz: a88aecd9681674821f4953e96519635f1a2a5d452abf100de57de0fd8d01b7121f54a72f97252384be4d23e2c93dcee5d6518f1b2ff1f1ef317d8e8de07c99b0
6
+ metadata.gz: b5c0a7794268c727152a95a58c9af9c9cf52a6126bee5e3c00af7659e221511e14ac3e3565bbfee58db8683b57149b4647780d2b164c70041cc1addfc781b00c
7
+ data.tar.gz: 52eeff05d0809f8946591c6a81d456f6da89fa1203b23023f3ec96ebbd741a2b175955f3d136c89352f4d3e2f3f17982f0c221a84e6ef0c69c09134dc3b359c5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- webspicy (0.5.0.pre.rc0)
4
+ webspicy (0.5.0)
5
5
  finitio (~> 0.5.2)
6
6
  http (~> 2)
7
7
  path (~> 1.3)
@@ -3,6 +3,7 @@ require 'json'
3
3
  require 'path'
4
4
  require 'finitio'
5
5
  require 'rack/robustness'
6
+ require 'csv'
6
7
 
7
8
  SCHEMA = Finitio::DEFAULT_SYSTEM.parse (Path.dir/'webspicy/schema.fio').read
8
9
 
@@ -44,14 +45,25 @@ end
44
45
 
45
46
  post '/todo/' do
46
47
  content_type :json
47
- todo = SCHEMA["Todo"].dress(JSON.load(request.body.read))
48
- if settings.todolist.find{|t| t[:id] == todo[:id] }
49
- status 409
50
- {error: "Identifier already in use"}.to_json
51
- else
52
- settings.todolist << todo
48
+ case todos = loaded_body
49
+ when Array
50
+ n = 0
51
+ todos.each do |todo|
52
+ settings.todolist << todo
53
+ n += 1
54
+ end
53
55
  status 201
54
- todo.to_json
56
+ { count: n }.to_json
57
+ when Hash
58
+ todo = SCHEMA["Todo"].dress(todos)
59
+ if settings.todolist.find{|t| t[:id] == todo[:id] }
60
+ status 409
61
+ {error: "Identifier already in use"}.to_json
62
+ else
63
+ settings.todolist << todo
64
+ status 201
65
+ todo.to_json
66
+ end
55
67
  end
56
68
  end
57
69
 
@@ -73,7 +85,7 @@ patch '/todo/:id' do |id|
73
85
  status 404
74
86
  {error: "No such todo"}.to_json
75
87
  else
76
- patch = SCHEMA["TodoPatch"].dress(JSON.load(request.body.read))
88
+ patch = SCHEMA["TodoPatch"].dress(loaded_body)
77
89
  patched = todo.merge(patch)
78
90
  settings.todolist = settings.todolist.reject{|todo| todo[:id] == Integer(id) }
79
91
  settings.todolist << patched
@@ -92,4 +104,18 @@ delete '/todo/:id' do |id|
92
104
  status 204
93
105
  content_type "text/plain"
94
106
  end
107
+ end
108
+
109
+ ###
110
+
111
+ def loaded_body
112
+ case ctype = request.content_type
113
+ when /json/
114
+ JSON.load(request.body.read)
115
+ when /csv/
116
+ csv = ::CSV.new(request.body.read, :headers => true, :header_converters => :symbol)
117
+ csv.map {|row| row.to_hash }
118
+ else
119
+ halt [415,{},["Unsupported content type"]]
120
+ end
95
121
  end
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: |-
3
+ Todo
4
+
5
+ url: |-
6
+ /todo/
7
+
8
+ services:
9
+ - method: |-
10
+ POST
11
+
12
+ description: |-
13
+ Creates new todo items through a CSV import
14
+
15
+ preconditions: |-
16
+
17
+ input_schema: |-
18
+ {}
19
+
20
+ output_schema: |-
21
+ { count: Integer }
22
+
23
+ error_schema: |-
24
+ ErrorSchema
25
+
26
+ examples:
27
+
28
+ - description: |-
29
+ when requested with a valid CSV
30
+ params: {}
31
+ headers:
32
+ Content-Type: text/csv
33
+ body: |-
34
+ id,description
35
+ 10,Write documentation
36
+ 11,Create website
37
+ 12,Add smart tools
38
+ expected:
39
+ content_type: application/json
40
+ status: 201
41
+ assert:
42
+ - "pathFD('', count: 3)"
@@ -21,7 +21,7 @@ module Webspicy
21
21
  url = scope.to_real_url(url)
22
22
 
23
23
  # Invoke the service now
24
- api.public_send(service.method.to_s.downcase.to_sym, url, params, headers)
24
+ api.public_send(service.method.to_s.downcase.to_sym, url, params, headers, test_case.body)
25
25
 
26
26
  # Return the result
27
27
  Resource::Service::Invocation.new(service, test_case, api.last_response, self)
@@ -31,7 +31,7 @@ module Webspicy
31
31
 
32
32
  attr_reader :last_response
33
33
 
34
- def get(url, params = {}, headers = nil)
34
+ def get(url, params = {}, headers = nil, body = nil)
35
35
  Webspicy.info("GET #{url} -- #{params.inspect}")
36
36
 
37
37
  @last_response = HTTP[headers || {}].get(url, params: params)
@@ -42,10 +42,19 @@ module Webspicy
42
42
  @last_response
43
43
  end
44
44
 
45
- def post(url, params = {}, headers = nil)
45
+ def post(url, params = {}, headers = nil, body = nil)
46
46
  Webspicy.info("POST #{url} -- #{params.inspect}")
47
47
 
48
- @last_response = HTTP[headers || {}].post(url, body: params.to_json)
48
+ url = url + "?" + Rack::Utils.build_query(params) if body && !params.empty?
49
+
50
+ headers ||= {}
51
+ headers['Content-Type'] ||= 'application/json'
52
+
53
+ if body
54
+ @last_response = HTTP[headers].post(url, body: body)
55
+ else
56
+ @last_response = HTTP[headers].post(url, body: params.to_json)
57
+ end
49
58
 
50
59
  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
51
60
  Webspicy.debug("Response: #{@last_response.body}")
@@ -53,10 +62,12 @@ module Webspicy
53
62
  @last_response
54
63
  end
55
64
 
56
- def patch(url, params = {}, headers = nil)
65
+ def patch(url, params = {}, headers = nil, body = nil)
57
66
  Webspicy.info("PATCH #{url} -- #{params.inspect}")
58
67
 
59
- @last_response = HTTP[headers || {}].patch(url, body: params.to_json)
68
+ headers ||= {}
69
+ headers['Content-Type'] ||= 'application/json'
70
+ @last_response = HTTP[headers].patch(url, body: params.to_json)
60
71
 
61
72
  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
62
73
  Webspicy.debug("Response: #{@last_response.body}")
@@ -64,7 +75,7 @@ module Webspicy
64
75
  @last_response
65
76
  end
66
77
 
67
- def post_form(url, params = {}, headers = nil)
78
+ def post_form(url, params = {}, headers = nil, body = nil)
68
79
  Webspicy.info("POST #{url} -- #{params.inspect}")
69
80
 
70
81
  @last_response = HTTP[headers || {}].post(url, form: params)
@@ -75,7 +86,7 @@ module Webspicy
75
86
  @last_response
76
87
  end
77
88
 
78
- def delete(url, params = {}, headers = nil)
89
+ def delete(url, params = {}, headers = nil, body = nil)
79
90
  Webspicy.info("DELETE #{url} -- #{params.inspect}")
80
91
 
81
92
  @last_response = HTTP[headers || {}].delete(url, body: params.to_json)
@@ -17,13 +17,14 @@ module Webspicy
17
17
  # Instantiate the parameters
18
18
  headers = test_case.headers.dup
19
19
  params = test_case.dress_params? ? service.dress_params(test_case.params) : test_case.params
20
+ body = test_case.body
20
21
 
21
22
  # Instantiate the url and strip parameters
22
23
  url, params = resource.instantiate_url(params)
23
24
  url = scope.to_real_url(url){ url }
24
25
 
25
26
  # Invoke the service now
26
- api.public_send(service.method.to_s.downcase.to_sym, url, params, headers)
27
+ api.public_send(service.method.to_s.downcase.to_sym, url, params, headers, body)
27
28
 
28
29
  # Return the result
29
30
  Resource::Service::Invocation.new(service, test_case, api.last_response, self)
@@ -60,7 +61,7 @@ module Webspicy
60
61
  @app = app
61
62
  end
62
63
 
63
- def get(url, params = {}, headers = nil)
64
+ def get(url, params = {}, headers = nil, body = nil)
64
65
  handler = get_handler(headers)
65
66
 
66
67
  Webspicy.info("GET #{url} -- #{params.inspect} -- #{headers.inspect}")
@@ -74,12 +75,18 @@ module Webspicy
74
75
  @last_response
75
76
  end
76
77
 
77
- def post(url, params = {}, headers = nil)
78
+ def post(url, params = {}, headers = nil, body = nil)
78
79
  handler = get_handler(headers)
79
80
 
81
+ url = url + "?" + Rack::Utils.build_query(params) if body && !params.empty?
82
+
80
83
  Webspicy.info("POST #{url} -- #{params.inspect} -- #{headers.inspect}")
81
84
 
82
- handler.post(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
85
+ if body
86
+ handler.post(url, body)
87
+ else
88
+ handler.post(url, params.to_json, {"CONTENT_TYPE" => "application/json"})
89
+ end
83
90
  @last_response = handler.last_response
84
91
 
85
92
  Webspicy.debug("Headers: #{@last_response.headers.to_hash}")
@@ -88,7 +95,7 @@ module Webspicy
88
95
  @last_response
89
96
  end
90
97
 
91
- def patch(url, params = {}, headers = nil)
98
+ def patch(url, params = {}, headers = nil, body = nil)
92
99
  handler = get_handler(headers)
93
100
 
94
101
  Webspicy.info("PATCH #{url} -- #{params.inspect} -- #{headers.inspect}")
@@ -102,7 +109,7 @@ module Webspicy
102
109
  @last_response
103
110
  end
104
111
 
105
- def post_form(url, params = {}, headers = nil)
112
+ def post_form(url, params = {}, headers = nil, body = nil)
106
113
  handler = get_handler(headers)
107
114
 
108
115
  Webspicy.info("POST #{url} -- #{params.inspect} -- #{headers.inspect}")
@@ -116,7 +123,7 @@ module Webspicy
116
123
  @last_response
117
124
  end
118
125
 
119
- def delete(url, params = {}, headers = nil)
126
+ def delete(url, params = {}, headers = nil, body = nil)
120
127
  handler = get_handler(headers)
121
128
 
122
129
  Webspicy.info("DELETE #{url} -- #{params.inspect} -- #{headers.inspect}")
@@ -33,6 +33,7 @@ TestCase =
33
33
  dress_params :? Boolean
34
34
  params : Params
35
35
  headers :? .Hash
36
+ body :? String
36
37
  seeds :? String
37
38
  requester :? String
38
39
  expected: {
@@ -37,6 +37,10 @@ module Webspicy
37
37
  @raw[:params]
38
38
  end
39
39
 
40
+ def body
41
+ @raw[:body]
42
+ end
43
+
40
44
  def expected_content_type
41
45
  @raw[:expected].fetch(:content_type){ 'application/json' }
42
46
  end
@@ -1,7 +1,7 @@
1
1
  module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -144,6 +144,7 @@ files:
144
144
  - examples/restful/webspicy/todo/getTodo.yml
145
145
  - examples/restful/webspicy/todo/getTodos.yml
146
146
  - examples/restful/webspicy/todo/patchTodo.yml
147
+ - examples/restful/webspicy/todo/postCsv.yml
147
148
  - examples/restful/webspicy/todo/postTodos.yml
148
149
  - lib/webspicy.rb
149
150
  - lib/webspicy/checker.rb
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  requirements: []
195
196
  rubyforge_project:
196
- rubygems_version: 2.6.11
197
+ rubygems_version: 2.5.1
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: Webspicy helps testing web services as software operation black boxes!