apirunner 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apirunner.gemspec +8 -2
- data/examples/config/api_runner.yml +1 -0
- data/examples/test/api_runner/001_create_user.yml +166 -0
- data/examples/test/api_runner/002_update_resources.yml +1 -0
- data/examples/test/api_runner/003_update_ratings.yml +1 -0
- data/examples/test/api_runner/004_pagination.yml +1 -0
- data/examples/test/api_runner/005_cache_operations.yml +1 -0
- data/examples/test/api_runner/999_delete_user.yml +22 -0
- data/lib/api_configuration.rb +1 -1
- data/lib/api_runner.rb +35 -1
- data/lib/http_client.rb +4 -1
- data/lib/result.rb +16 -19
- metadata +11 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/apirunner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apirunner}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["jan@moviepilot.com"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-28}
|
13
13
|
s.description = %q{apirunner is a testsuite to query your RESTful JSON API and match response with your defined expectations}
|
14
14
|
s.email = %q{developers@moviepilot.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,7 +29,13 @@ Gem::Specification.new do |s|
|
|
29
29
|
"changelog.txt",
|
30
30
|
"examples/config/api_runner.yml",
|
31
31
|
"examples/test/api_runner/001_create_ressource.yml",
|
32
|
+
"examples/test/api_runner/001_create_user.yml",
|
33
|
+
"examples/test/api_runner/002_update_resources.yml",
|
34
|
+
"examples/test/api_runner/003_update_ratings.yml",
|
35
|
+
"examples/test/api_runner/004_pagination.yml",
|
36
|
+
"examples/test/api_runner/005_cache_operations.yml",
|
32
37
|
"examples/test/api_runner/999_delete_ressource.yml",
|
38
|
+
"examples/test/api_runner/999_delete_user.yml",
|
33
39
|
"examples/test/api_runner/excludes.yml",
|
34
40
|
"features/apirunner.feature",
|
35
41
|
"features/step_definitions/apirunner_steps.rb",
|
@@ -0,0 +1,166 @@
|
|
1
|
+
---
|
2
|
+
- name: 'Create new User'
|
3
|
+
request:
|
4
|
+
headers:
|
5
|
+
Content-Type: 'application/json'
|
6
|
+
path: '/users/duffyduck'
|
7
|
+
method: 'PUT'
|
8
|
+
body:
|
9
|
+
username: 'duffyduck'
|
10
|
+
watchlist:
|
11
|
+
- m333
|
12
|
+
- m79
|
13
|
+
blacklist:
|
14
|
+
- m334
|
15
|
+
- m77
|
16
|
+
skiplist:
|
17
|
+
- m335
|
18
|
+
- m78
|
19
|
+
ratings:
|
20
|
+
m336: 4
|
21
|
+
m79: 2.5
|
22
|
+
m777: 3.0
|
23
|
+
m567: 4.0
|
24
|
+
m354: 5.0
|
25
|
+
expires_at: 2011-09-09T22:41:50+00:00
|
26
|
+
response_expectation:
|
27
|
+
status_code: 201
|
28
|
+
headers:
|
29
|
+
Last-Modified: /.*/
|
30
|
+
body:
|
31
|
+
username: 'duffyduck'
|
32
|
+
watchlist:
|
33
|
+
- m333
|
34
|
+
- m79
|
35
|
+
blacklist:
|
36
|
+
- m334
|
37
|
+
- m77
|
38
|
+
skiplist:
|
39
|
+
- m335
|
40
|
+
- m78
|
41
|
+
ratings:
|
42
|
+
m336: 4.0
|
43
|
+
m79: 2.5
|
44
|
+
fsk: "18"
|
45
|
+
- name: 'Update existing User - Update watchlist'
|
46
|
+
request:
|
47
|
+
headers:
|
48
|
+
Content-Type: 'application/json'
|
49
|
+
path: '/users/duffyduck/watchlist'
|
50
|
+
method: 'PUT'
|
51
|
+
body:
|
52
|
+
- m367
|
53
|
+
- m73
|
54
|
+
response_expectation:
|
55
|
+
status_code: 204
|
56
|
+
body:
|
57
|
+
- name: 'Check User FSK,Watchlist'
|
58
|
+
request:
|
59
|
+
headers:
|
60
|
+
Content-Type: 'application/json'
|
61
|
+
path: '/users/duffyduck'
|
62
|
+
method: 'GET'
|
63
|
+
response_expectation:
|
64
|
+
status_code: 200
|
65
|
+
headers:
|
66
|
+
Last-Modified: /.*/
|
67
|
+
body:
|
68
|
+
username: 'duffyduck'
|
69
|
+
fsk: "18"
|
70
|
+
watchlist:
|
71
|
+
- m367
|
72
|
+
- m73
|
73
|
+
blacklist:
|
74
|
+
- m334
|
75
|
+
- m77
|
76
|
+
skiplist:
|
77
|
+
- m335
|
78
|
+
- m78
|
79
|
+
ratings:
|
80
|
+
m336: 4.0
|
81
|
+
m79: 2.5
|
82
|
+
- name: 'Set 10 Ratings'
|
83
|
+
request:
|
84
|
+
headers:
|
85
|
+
Content-Type: 'application/json'
|
86
|
+
path: '/users/duffyduck/ratings'
|
87
|
+
method: 'PUT'
|
88
|
+
body:
|
89
|
+
"m1035": 1
|
90
|
+
"m2087": 0.5
|
91
|
+
"m1554": 2
|
92
|
+
"m2981": 1.0
|
93
|
+
"m1590": 2
|
94
|
+
"m12493": 4
|
95
|
+
"m1875": 5
|
96
|
+
"m7258": 2.5
|
97
|
+
response_expectation:
|
98
|
+
status_code: 204
|
99
|
+
headers:
|
100
|
+
Last-Modified: /.*/
|
101
|
+
- name: 'Check User Ratings Update'
|
102
|
+
request:
|
103
|
+
headers:
|
104
|
+
Content-Type: 'application/json'
|
105
|
+
path: '/users/duffyduck'
|
106
|
+
method: 'GET'
|
107
|
+
response_expectation:
|
108
|
+
status_code: 200
|
109
|
+
headers:
|
110
|
+
Last-Modified: /.*/
|
111
|
+
body:
|
112
|
+
username: 'duffyduck'
|
113
|
+
fsk: "18"
|
114
|
+
watchlist:
|
115
|
+
- m367
|
116
|
+
- m73
|
117
|
+
blacklist:
|
118
|
+
- m334
|
119
|
+
- m77
|
120
|
+
skiplist:
|
121
|
+
- m335
|
122
|
+
- m78
|
123
|
+
ratings:
|
124
|
+
"m1035": "1.0"
|
125
|
+
"m2087": "0.5"
|
126
|
+
"m1554": "2.0"
|
127
|
+
"m2981": "1.0"
|
128
|
+
"m1590": "2.0"
|
129
|
+
"m12493": "4.0"
|
130
|
+
"m1875": "5.0"
|
131
|
+
"m7258": "2.5"
|
132
|
+
- name: 'User creation should fail on wrong username'
|
133
|
+
priority: 2
|
134
|
+
request:
|
135
|
+
headers:
|
136
|
+
Content-Type: 'application/json'
|
137
|
+
path: '/users/duffyduck'
|
138
|
+
method: 'PUT'
|
139
|
+
body:
|
140
|
+
username: '!"§$%&/()=?QWERTZUI"§$%& /('
|
141
|
+
response_expectation:
|
142
|
+
status_code: 409
|
143
|
+
- name: 'User creation should fail on wrong fsk'
|
144
|
+
priority: 2
|
145
|
+
request:
|
146
|
+
headers:
|
147
|
+
Content-Type: 'application/json'
|
148
|
+
path: '/users/duffyduck2'
|
149
|
+
method: 'PUT'
|
150
|
+
body:
|
151
|
+
username: 'duffyduck2'
|
152
|
+
fsk: 2000000
|
153
|
+
response_expectation:
|
154
|
+
status_code: 409
|
155
|
+
- name: 'User creation should fail on wrong expiration_date'
|
156
|
+
priority: 2
|
157
|
+
request:
|
158
|
+
headers:
|
159
|
+
Content-Type: 'application/json'
|
160
|
+
path: '/users/duffyduck3'
|
161
|
+
method: 'PUT'
|
162
|
+
body:
|
163
|
+
username: 'duffyduck3'
|
164
|
+
expires_at: 2009-09-09T22:41:50+00:00
|
165
|
+
response_expectation:
|
166
|
+
status_code: 409
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
- name: 'Delete User 1'
|
3
|
+
request:
|
4
|
+
path: '/users/duffyduck'
|
5
|
+
method: 'DELETE'
|
6
|
+
body: {}
|
7
|
+
response_expectation:
|
8
|
+
status_code: 202
|
9
|
+
- name: 'Delete User 2'
|
10
|
+
request:
|
11
|
+
path: '/users/duffyduck2'
|
12
|
+
method: 'DELETE'
|
13
|
+
body: {}
|
14
|
+
response_expectation:
|
15
|
+
status_code: 202
|
16
|
+
- name: 'Delete User 3'
|
17
|
+
request:
|
18
|
+
path: '/users/duffyduck3'
|
19
|
+
method: 'DELETE'
|
20
|
+
body: {}
|
21
|
+
response_expectation:
|
22
|
+
status_code: 202
|
data/lib/api_configuration.rb
CHANGED
data/lib/api_runner.rb
CHANGED
@@ -76,14 +76,48 @@ class ApiRunner
|
|
76
76
|
config = YAML.load_file(self.class.config_file)
|
77
77
|
config[env.to_s].each { |key, value| @configuration.instance_variable_set("@#{key}", value) }
|
78
78
|
@configuration.verbosity = config['general']['verbosity'].first
|
79
|
+
@configuration.priority = config['general']['priority'] || 0
|
79
80
|
end
|
80
81
|
|
81
82
|
# loads spec cases from yaml files
|
82
83
|
def load_url_spec
|
83
84
|
path = self.class.spec_path
|
85
|
+
specs = []
|
84
86
|
Dir.new(path).entries.each do |dir_entry|
|
85
|
-
|
87
|
+
specs.push *YAML.load_file(path+dir_entry) if not (File.directory? dir_entry or dir_entry.match(/^\./) or dir_entry.match(/excludes/))
|
86
88
|
end
|
89
|
+
@spec = priorize(partition(specs))
|
90
|
+
end
|
91
|
+
|
92
|
+
# returns only spec whose priority level is less or equals configures priority level
|
93
|
+
# if no priority level is configured for the api runner, 0 is assumed
|
94
|
+
# if no priority level ist configured for a story, 0 is assumed
|
95
|
+
def priorize(specs)
|
96
|
+
relevant_specs = []
|
97
|
+
specs.each do |spec|
|
98
|
+
relevant_specs << spec if spec['priority'].nil? or spec['priority'].to_i <= @configuration.priority.to_i
|
99
|
+
end
|
100
|
+
relevant_specs
|
101
|
+
end
|
102
|
+
|
103
|
+
# partitions the spec if keywords like 'focus', 'until' or 'from exist'
|
104
|
+
# and returns the relevant subset of specs that have to be tested then
|
105
|
+
def partition(specs)
|
106
|
+
relevant_specs = []
|
107
|
+
specs.each do |spec|
|
108
|
+
if spec['focus']
|
109
|
+
relevant_specs << spec
|
110
|
+
break
|
111
|
+
elsif spec['until']
|
112
|
+
relevant_specs = specs[0..specs.index(spec)]
|
113
|
+
break
|
114
|
+
elsif spec['from']
|
115
|
+
relevant_specs = specs[specs.index(spec)..specs.size+1]
|
116
|
+
break
|
117
|
+
end
|
118
|
+
end
|
119
|
+
relevant_specs = specs if relevant_specs.empty?
|
120
|
+
relevant_specs
|
87
121
|
end
|
88
122
|
|
89
123
|
# loads and parses items that need to be excluded from the checks in certain environments
|
data/lib/http_client.rb
CHANGED
@@ -17,12 +17,15 @@ class HttpClient
|
|
17
17
|
# returns struct containing response.code, headers, body and message
|
18
18
|
# this is only for easily interfaceing another http client
|
19
19
|
def build_response(raw_response)
|
20
|
+
debugger
|
20
21
|
response_struct = Struct.new(:code, :message, :headers, :body)
|
21
22
|
response = response_struct.new
|
22
23
|
response.code = raw_response.code
|
23
24
|
response.message = raw_response.message
|
24
25
|
response.body = raw_response.body
|
25
|
-
response.headers = raw_response.header
|
26
|
+
# response.headers = raw_response.header
|
27
|
+
# TODO improve me!
|
28
|
+
response.headers = JSON.parse(raw_response.header.to_json) rescue nil
|
26
29
|
response
|
27
30
|
end
|
28
31
|
|
data/lib/result.rb
CHANGED
@@ -27,9 +27,7 @@ class Result
|
|
27
27
|
|
28
28
|
# yields a more verbose error message only in case of an error
|
29
29
|
def verbose_on_error(index)
|
30
|
-
if not @succeeded
|
31
|
-
be_verbose(index)
|
32
|
-
end
|
30
|
+
be_verbose(index) if not @succeeded
|
33
31
|
end
|
34
32
|
|
35
33
|
# yields a more verbose message in case of an error AND success
|
@@ -45,22 +43,21 @@ class Result
|
|
45
43
|
|
46
44
|
# yields the verbose error messages
|
47
45
|
def be_verbose(index)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
puts(" repsonse body: #{JSON.parse(@response.body) rescue nil}")
|
46
|
+
puts "\n#{result_case} (#{index+1}) - \"#{@testcase['name']}\""
|
47
|
+
puts @error_message
|
48
|
+
puts(" More more more verbosity\n")
|
49
|
+
puts(" request method: #{@testcase['request']['method']}")
|
50
|
+
puts(" resource path: #{@testcase['request']['path']}")
|
51
|
+
puts(" request headers: #{@testcase['request']['headers']}")
|
52
|
+
puts(" JSON body sent: #{@testcase['request']['body']}")
|
53
|
+
puts(" expectation:")
|
54
|
+
puts(" response status code: #{@testcase['response_expectation']['status_code']}")
|
55
|
+
puts(" response headers: #{@testcase['response_expectation']['headers']}")
|
56
|
+
puts(" response body: #{@testcase['response_expectation']['body']}")
|
57
|
+
puts(" result:")
|
58
|
+
puts(" response status code: #{@response.code}")
|
59
|
+
puts(" response headers: #{@response.headers}")
|
60
|
+
puts(" response body: #{JSON.parse(@response.body) rescue nil}")
|
64
61
|
end
|
65
62
|
|
66
63
|
# returns the result case for interpolation in the output message header
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jan@moviepilot.com
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-28 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -233,7 +233,13 @@ files:
|
|
233
233
|
- changelog.txt
|
234
234
|
- examples/config/api_runner.yml
|
235
235
|
- examples/test/api_runner/001_create_ressource.yml
|
236
|
+
- examples/test/api_runner/001_create_user.yml
|
237
|
+
- examples/test/api_runner/002_update_resources.yml
|
238
|
+
- examples/test/api_runner/003_update_ratings.yml
|
239
|
+
- examples/test/api_runner/004_pagination.yml
|
240
|
+
- examples/test/api_runner/005_cache_operations.yml
|
236
241
|
- examples/test/api_runner/999_delete_ressource.yml
|
242
|
+
- examples/test/api_runner/999_delete_user.yml
|
237
243
|
- examples/test/api_runner/excludes.yml
|
238
244
|
- features/apirunner.feature
|
239
245
|
- features/step_definitions/apirunner_steps.rb
|
@@ -265,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
265
271
|
requirements:
|
266
272
|
- - ">="
|
267
273
|
- !ruby/object:Gem::Version
|
268
|
-
hash: -
|
274
|
+
hash: -2602692957616549135
|
269
275
|
segments:
|
270
276
|
- 0
|
271
277
|
version: "0"
|