apirunner 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apirunner.gemspec +1 -1
- data/examples/test/api_runner/001_create_ressource.yml +10 -0
- data/lib/api_runner.rb +4 -4
- data/lib/expectation_matcher.rb +0 -1
- data/lib/http_client.rb +14 -41
- data/lib/result.rb +14 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/apirunner.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
---
|
2
2
|
- name: 'Create new User'
|
3
3
|
request:
|
4
|
+
headers:
|
5
|
+
Content-Type: 'application/json'
|
4
6
|
path: '/users/duffyduck'
|
5
7
|
method: 'PUT'
|
6
8
|
body:
|
@@ -42,6 +44,8 @@
|
|
42
44
|
fsk: "18"
|
43
45
|
- name: 'Update existing User - Update watchlist'
|
44
46
|
request:
|
47
|
+
headers:
|
48
|
+
Content-Type: 'application/json'
|
45
49
|
path: '/users/duffyduck/watchlist'
|
46
50
|
method: 'PUT'
|
47
51
|
body:
|
@@ -52,6 +56,8 @@
|
|
52
56
|
body:
|
53
57
|
- name: 'Check User FSK,Watchlist'
|
54
58
|
request:
|
59
|
+
headers:
|
60
|
+
Content-Type: 'application/json'
|
55
61
|
path: '/users/duffyduck'
|
56
62
|
method: 'GET'
|
57
63
|
response_expectation:
|
@@ -75,6 +81,8 @@
|
|
75
81
|
m79: 2.5
|
76
82
|
- name: 'Set 10 Ratings'
|
77
83
|
request:
|
84
|
+
headers:
|
85
|
+
Content-Type: 'application/json'
|
78
86
|
path: '/users/duffyduck/ratings'
|
79
87
|
method: 'PUT'
|
80
88
|
body:
|
@@ -92,6 +100,8 @@
|
|
92
100
|
Last-Modified: /.*/
|
93
101
|
- name: 'Check User Ratings Update'
|
94
102
|
request:
|
103
|
+
headers:
|
104
|
+
Content-Type: 'application/json'
|
95
105
|
path: '/users/duffyduck'
|
96
106
|
method: 'GET'
|
97
107
|
response_expectation:
|
data/lib/api_runner.rb
CHANGED
@@ -38,7 +38,7 @@ class ApiRunner
|
|
38
38
|
# runs all testcases that are provided by the testclass an fills errors if there are any
|
39
39
|
def run_tests
|
40
40
|
@spec.each do |test_case|
|
41
|
-
response = send_request(test_case['request']['method'].downcase.to_sym, test_case['request']['path'], test_case['request']['body'])
|
41
|
+
response = send_request(test_case['request']['method'].downcase.to_sym, test_case['request']['path'], test_case['request']['headers'], test_case['request']['body'])
|
42
42
|
@expectation.test_types.each do |test_type|
|
43
43
|
result = @expectation.check(test_type, response, test_case)
|
44
44
|
if not result.succeeded
|
@@ -56,8 +56,8 @@ class ApiRunner
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# sends http request and fetches response using the given http client
|
59
|
-
def send_request(method, uri, data)
|
60
|
-
@http_client.send_request(method, uri, data)
|
59
|
+
def send_request(method, uri, headers, data)
|
60
|
+
@http_client.send_request(method, uri, headers, data)
|
61
61
|
end
|
62
62
|
|
63
63
|
# builds target uri from base uri generated of host port and namespace as well as the ressource path
|
@@ -68,7 +68,7 @@ class ApiRunner
|
|
68
68
|
# returns true if server is available
|
69
69
|
def server_is_available?
|
70
70
|
return true
|
71
|
-
!@http_client.send_request(:get, "#{@configuration.protocol}://#{@configuration.host}:#{@configuration.port}", {:timeout => 5}).nil?
|
71
|
+
!@http_client.send_request(:get, "#{@configuration.protocol}://#{@configuration.host}:#{@configuration.port}", nil, {:timeout => 5}).nil?
|
72
72
|
end
|
73
73
|
|
74
74
|
# loads environment config data from yaml file
|
data/lib/expectation_matcher.rb
CHANGED
@@ -31,7 +31,6 @@ class ExpectationMatcher
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# checks the format of the given data of JSON conformity
|
34
|
-
# returns a structure containing return value and error if there is one
|
35
34
|
def response_body_format(response, testcase)
|
36
35
|
result_struct = Struct.new(:succeeded, :error)
|
37
36
|
results = result_struct.new(:succeeded => true, :error => nil)
|
data/lib/http_client.rb
CHANGED
@@ -8,8 +8,8 @@ class HttpClient
|
|
8
8
|
@namespace = namespace
|
9
9
|
end
|
10
10
|
|
11
|
-
def send_request(method, resource, data=nil)
|
12
|
-
build_response(self.send(method.to_s.downcase, resource, data))
|
11
|
+
def send_request(method, resource, headers=nil, data=nil)
|
12
|
+
build_response(self.send(method.to_s.downcase, headers, resource, data))
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
@@ -26,28 +26,27 @@ class HttpClient
|
|
26
26
|
response
|
27
27
|
end
|
28
28
|
|
29
|
-
def get(resource, params)
|
30
|
-
request = Net::HTTP::Get.new(resource_path(resource), initheader =
|
31
|
-
|
32
|
-
return response
|
29
|
+
def get(headers, resource, params)
|
30
|
+
request = Net::HTTP::Get.new(resource_path(resource), initheader = headers)
|
31
|
+
@http.request(request)
|
33
32
|
end
|
34
33
|
|
35
|
-
def put(resource, data)
|
36
|
-
request = Net::HTTP::Put.new(resource_path(resource), initheader =
|
34
|
+
def put(headers, resource, data)
|
35
|
+
request = Net::HTTP::Put.new(resource_path(resource), initheader = headers)
|
37
36
|
request.body = data.to_json
|
38
|
-
|
37
|
+
@http.request(request)
|
39
38
|
end
|
40
39
|
|
41
|
-
def post(resource, data)
|
42
|
-
request = Net::HTTP::Post.new(resource_path(resource), initheader =
|
40
|
+
def post(headers, resource, data)
|
41
|
+
request = Net::HTTP::Post.new(resource_path(resource), initheader = headers)
|
43
42
|
request.body = data.to_json
|
44
|
-
|
43
|
+
@http.request(request)
|
45
44
|
end
|
46
45
|
|
47
46
|
|
48
|
-
def delete(resource, params)
|
49
|
-
request = Net::HTTP::Delete.new(resource_path(resource), initheader =
|
50
|
-
|
47
|
+
def delete(headers, resource, params)
|
48
|
+
request = Net::HTTP::Delete.new(resource_path(resource), initheader = headers)
|
49
|
+
@http.request(request)
|
51
50
|
end
|
52
51
|
|
53
52
|
def resource_path(resource)
|
@@ -55,29 +54,3 @@ class HttpClient
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
|
59
|
-
class HttPartyClient
|
60
|
-
require 'httparty'
|
61
|
-
include HTTParty
|
62
|
-
|
63
|
-
# sends http request with given method, uri and data and returns servers response
|
64
|
-
def send_request(method, uri, data=nil)
|
65
|
-
options = { :body => data.to_json, :format => :json }
|
66
|
-
build_response(self.class.send(method, uri, options))
|
67
|
-
end
|
68
|
-
|
69
|
-
protected
|
70
|
-
|
71
|
-
# returns struct containing response.code, headers, body and message
|
72
|
-
# this is only for easily interfaceing another http client
|
73
|
-
def build_response(raw_response)
|
74
|
-
response_struct = Struct.new(:code, :message, :headers, :body)
|
75
|
-
response = response_struct.new
|
76
|
-
response.code = raw_response.code
|
77
|
-
response.message = raw_response.message
|
78
|
-
response.headers = raw_response.headers
|
79
|
-
response.body = raw_response.body
|
80
|
-
response
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
data/lib/result.rb
CHANGED
@@ -45,16 +45,22 @@ class Result
|
|
45
45
|
|
46
46
|
# yields the verbose error messages
|
47
47
|
def be_verbose(index)
|
48
|
+
debugger
|
48
49
|
puts "\n#{result_case} (#{index+1}) - \"#{@testcase['name']}\""
|
49
50
|
puts @error_message
|
50
|
-
puts
|
51
|
-
puts
|
52
|
-
puts
|
53
|
-
puts
|
54
|
-
puts
|
55
|
-
puts
|
56
|
-
puts
|
57
|
-
puts
|
51
|
+
puts(" More more more verbosity\n")
|
52
|
+
puts(" request method: #{@testcase['request']['method']}")
|
53
|
+
puts(" resource path: #{@testcase['request']['path']}")
|
54
|
+
puts(" request headers: #{@testcase['request']['headers']}")
|
55
|
+
puts(" JSON body sent: #{@testcase['request']['body']}")
|
56
|
+
puts(" expectation:")
|
57
|
+
puts(" response status code: #{@testcase['response_expectation']['status_code']}")
|
58
|
+
puts(" response headers: #{@testcase['response_expectation']['headers']}")
|
59
|
+
puts(" response body: #{@testcase['response_expectation']['body']}")
|
60
|
+
puts(" result:")
|
61
|
+
puts(" response status code: #{@response.code}")
|
62
|
+
puts(" response headers: #{@response.headers}")
|
63
|
+
puts(" repsonse body: #{JSON.parse(@response.body)}")
|
58
64
|
end
|
59
65
|
|
60
66
|
# returns the result case for interpolation in the output message header
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 10
|
9
|
+
version: 0.1.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jan@moviepilot.com
|
@@ -265,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
265
265
|
requirements:
|
266
266
|
- - ">="
|
267
267
|
- !ruby/object:Gem::Version
|
268
|
-
hash: -
|
268
|
+
hash: -1888087046839663550
|
269
269
|
segments:
|
270
270
|
- 0
|
271
271
|
version: "0"
|