apirunner 0.5.0 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,12 +5,12 @@ local:
5
5
  namespace: api1v0
6
6
  staging:
7
7
  protocol: http
8
- host: staging.premium.moviepilot.com
8
+ host: staging.premium.yourhost.com
9
9
  port: 80
10
10
  namespace: api1v0
11
11
  production:
12
12
  protocol: http
13
- host: vtu.premium.moviepilot.com
13
+ host: vtu.premium.yourhost.com
14
14
  port: 80
15
15
  namespace: api1v0
16
16
  general:
@@ -1,173 +1,260 @@
1
1
  ---
2
- - name: 'Create new Basic User'
2
+ - name: "001/1: Search for non existing user without correct OAuth sig should fail"
3
3
  request:
4
4
  headers:
5
5
  Content-Type: 'application/json'
6
- path: '/users/duffybasic'
7
- method: 'PUT'
6
+ Accept: 'application/json'
7
+ path: '/users/0815471169'
8
+ method: 'GET'
8
9
  body:
9
- username: 'duffybasic'
10
- expires_at: 2011-09-09T22:41:50+00:00
10
+ response_expectation:
11
+ status_code: 401
12
+ headers:
13
+ Last-Modified: /.*/
14
+ body:
15
+ - name: "001/2: Search for non existing user with correct OAuth sig should return a 204"
16
+ request:
17
+ headers:
18
+ Content-Type: 'application/json'
19
+ Accept: 'application/json'
20
+ path: '/users/0815471169'
21
+ method: 'GET'
22
+ body:
23
+ oauth: true
24
+ response_expectation:
25
+ status_code: 204
26
+ headers:
27
+ Last-Modified: /.*/
28
+ body:
29
+ - name: "001/3: Creating a guest user with POST parameters should succeed with a 201"
30
+ request:
31
+ headers:
32
+ Accept: 'application/json'
33
+ path: '/users'
34
+ method: 'POST'
35
+ parameters:
36
+ id: '08154711'
37
+ body:
38
+ oauth: true
11
39
  response_expectation:
12
40
  status_code: 201
13
41
  headers:
14
42
  Last-Modified: /.*/
15
43
  body:
16
- username: 'duffybasic'
17
- - name: 'Create new User'
44
+ - name: "001/4: Creating a guest user with JSON parameters should succeed with a 201"
18
45
  request:
19
46
  headers:
20
47
  Content-Type: 'application/json'
21
- path: '/users/duffyduck'
22
- method: 'PUT'
23
- body:
24
- username: 'duffyduck'
25
- watchlist:
26
- - m1035
27
- - m2087
28
- blacklist:
29
- - m1554
30
- - m2981
31
- skiplist:
32
- - m1590
33
- - m1056
34
- ratings:
35
- m12493: 4.0
36
- m1875: 2.5
37
- m7258: 3.0
38
- m7339: 4.0
39
- m3642: 5.0
40
- expires_at: 2011-09-09T22:41:50+00:00
48
+ Accept: 'application/json'
49
+ path: '/users'
50
+ method: 'POST'
51
+ body:
52
+ id: '08154712'
53
+ oauth: true
41
54
  response_expectation:
42
55
  status_code: 201
43
56
  headers:
44
57
  Last-Modified: /.*/
45
58
  body:
46
- username: 'duffyduck'
47
- watchlist:
48
- - m1035
49
- - m2087
50
- blacklist:
51
- - m1554
52
- - m2981
53
- skiplist:
54
- - m1590
55
- - m1056
56
- ratings:
57
- m12493: 4.0
58
- m1875: 2.5
59
- m7258: 3.0
60
- m7339: 4.0
61
- m3642: 5.0
62
- fsk: "18"
63
- - name: 'Update existing User - Update watchlist'
59
+ - name: "001/5: Creating a guest user with JSON parameters without OAuth should result in a 401"
64
60
  request:
65
61
  headers:
66
62
  Content-Type: 'application/json'
67
- path: '/users/duffyduck/watchlist'
68
- method: 'PUT'
63
+ Accept: 'application/json'
64
+ path: '/users'
65
+ method: 'POST'
69
66
  body:
70
- - m367
71
- - m73
67
+ id: '08154713'
72
68
  response_expectation:
73
- status_code: 204
69
+ status_code: 401
70
+ headers:
71
+ Last-Modified: /.*/
74
72
  body:
75
- - name: 'Check User FSK,Watchlist'
73
+ - name: "001/6: Search for previously created user with correct OAuth sig should return the user"
76
74
  request:
77
75
  headers:
78
76
  Content-Type: 'application/json'
79
- path: '/users/duffyduck'
80
- method: 'GET'
77
+ Accept: 'application/json'
78
+ path: '/users/08154712'
79
+ method: 'GET'
80
+ body:
81
+ oauth: true
81
82
  response_expectation:
82
83
  status_code: 200
83
84
  headers:
84
85
  Last-Modified: /.*/
85
86
  body:
86
- username: 'duffyduck'
87
- fsk: "18"
88
- watchlist:
89
- - m367
90
- - m73
91
- blacklist:
92
- - m1554
93
- - m2981
94
- skiplist:
95
- - m1590
96
- - m1056
97
- ratings:
98
- m12493: 4.0
99
- m1875: 2.5
100
- m7258: 3.0
101
- m7339: 4.0
102
- m3642: 5.0
103
- - name: 'Set 10 Ratings'
87
+ version: 'v5'
88
+ content:
89
+ user:
90
+ vz_id: '08154712'
91
+ username: /^Guest_.*$/
92
+ guest: true
93
+ - name: "001/7: Recreating a guest user with POST parameters should fail in case the user already exists"
94
+ request:
95
+ headers:
96
+ Accept: 'application/json'
97
+ path: '/users'
98
+ method: 'POST'
99
+ parameters:
100
+ id: '08154712'
101
+ body:
102
+ oauth: true
103
+ response_expectation:
104
+ status_code: 422
105
+ headers:
106
+ Last-Modified: /.*/
107
+ body:
108
+ - name: "001/8: Recreating a guest user with JSON parameters should fail in case the user already exists"
104
109
  request:
105
110
  headers:
106
111
  Content-Type: 'application/json'
107
- path: '/users/duffyduck/ratings'
108
- method: 'PUT'
112
+ Accept: 'application/json'
113
+ path: '/users'
114
+ method: 'POST'
109
115
  body:
110
- "m1035": 1
111
- "m1554": 2
112
- "m2981": 1.0
113
- "m1590": 2
114
- "m12493": 4
115
- "m1875": 5
116
- "m7258": 2.5
116
+ id: '08154712'
117
+ oauth: true
117
118
  response_expectation:
118
- status_code: 204
119
+ status_code: 422
119
120
  headers:
120
121
  Last-Modified: /.*/
121
- - name: 'Check User Ratings Update'
122
+ body:
123
+ - name: "001/9: Updating a guest user via PUT parameters should succeed"
124
+ priority: 5
125
+ request:
126
+ headers:
127
+ Accept: 'application/json'
128
+ path: '/users/08154712'
129
+ method: 'PUT'
130
+ parameters:
131
+ access_token: 'vz_t0k3n'
132
+ body:
133
+ oauth: true
134
+ response_expectation:
135
+ status_code: 201
136
+ headers:
137
+ Last-Modified: /.*/
138
+ body:
139
+ version: 'v5'
140
+ content:
141
+ user:
142
+ vz_id: '08154712'
143
+ username: /^Guest_.*$/
144
+ guest: true
145
+ - name: "001/10: Updating a guest user via JSON should succeed"
122
146
  request:
123
147
  headers:
124
148
  Content-Type: 'application/json'
125
- path: '/users/duffyduck'
126
- method: 'GET'
149
+ Accept: 'application/json'
150
+ path: '/users/08154712'
151
+ method: 'PUT'
152
+ body:
153
+ id: '08154712'
154
+ access_token: 'vz_t0k3n'
155
+ oauth: true
127
156
  response_expectation:
128
- status_code: 200
157
+ status_code: 201
158
+ headers:
159
+ Last-Modified: /.*/
160
+ body:
161
+ version: 'v5'
162
+ content:
163
+ user:
164
+ vz_id: '08154712'
165
+ username: /^Guest_.*$/
166
+ guest: true
167
+ - name: "001/11: Updating a guest user via PUT parameters without valid OAuth sig should fail"
168
+ request:
169
+ headers:
170
+ Accept: 'application/json'
171
+ path: '/users/08154712'
172
+ method: 'PUT'
173
+ parameters:
174
+ id: '08154712'
175
+ access_token: 'vz_t0k3n'
176
+ body:
177
+ response_expectation:
178
+ status_code: 401
129
179
  headers:
130
180
  Last-Modified: /.*/
131
181
  body:
132
- username: 'duffyduck'
133
- fsk: "18"
134
- ratings:
135
- "m1035": "1.0"
136
- "m1554": "2.0"
137
- "m2981": "1.0"
138
- "m1590": "2.0"
139
- "m12493": "4.0"
140
- "m1875": "5.0"
141
- "m7258": "2.5"
142
- - name: 'User creation should fail on bogus characters in username'
143
- priority: 3
182
+ - name: "001/12: Updating a guest user via JSON without valid OAuth sig should fail"
144
183
  request:
145
184
  headers:
146
185
  Content-Type: 'application/json'
147
- path: '/users/duffyduck_fix_me'
148
- method: 'PUT'
186
+ Accept: 'application/json'
187
+ path: '/users/08154712'
188
+ method: 'PUT'
149
189
  body:
190
+ id: '08154712'
191
+ access_token: 'vz_t0k3n'
150
192
  response_expectation:
151
- status_code: 409
152
- - name: 'User creation should fail on wrong fsk'
193
+ status_code: 401
194
+ headers:
195
+ Last-Modified: /.*/
196
+ body:
197
+ - name: "001/13: Updating a guest user via PUT parameters with invalid parameters should fail"
198
+ request:
199
+ headers:
200
+ Accept: 'application/json'
201
+ path: '/users/08154712'
202
+ method: 'PUT'
203
+ parameters:
204
+ user:
205
+ username: 'duffyduck'
206
+ body:
207
+ oauth: true
208
+ response_expectation:
209
+ status_code: 422
210
+ headers:
211
+ Last-Modified: /.*/
212
+ body:
213
+ - name: "001/14: Updating a guest user via JSON without valid OAuth sig should fail"
153
214
  request:
154
215
  headers:
155
216
  Content-Type: 'application/json'
156
- path: '/users/duffyduck2'
157
- method: 'PUT'
217
+ Accept: 'application/json'
218
+ path: '/users/08154712'
219
+ method: 'PUT'
158
220
  body:
159
- username: 'duffyduck2'
160
- fsk: 2000000
221
+ user:
222
+ username: 'duffyduck'
223
+ oauth: true
161
224
  response_expectation:
162
- status_code: 409
163
- - name: 'User creation should fail on wrong expiration_date'
225
+ status_code: 422
226
+ headers:
227
+ Last-Modified: /.*/
228
+ body:
229
+ - name: "001/15: Updating a guest user via PUT parameters with invalid user_id should fail with 404"
230
+ request:
231
+ headers:
232
+ Accept: 'application/json'
233
+ path: '/users/08154799'
234
+ method: 'PUT'
235
+ parameters:
236
+ user:
237
+ username: 'duffyduck'
238
+ body:
239
+ oauth: true
240
+ response_expectation:
241
+ status_code: 404
242
+ headers:
243
+ Last-Modified: /.*/
244
+ body:
245
+ - name: "001/16: Updating a guest user via JSON with invalid user_id should fail with 404"
164
246
  request:
165
247
  headers:
166
248
  Content-Type: 'application/json'
167
- path: '/users/duffyduck3'
168
- method: 'PUT'
249
+ Accept: 'application/json'
250
+ path: '/users/08154799'
251
+ method: 'PUT'
169
252
  body:
170
- username: 'duffyduck3'
171
- expires_at: 2009-09-09T22:41:50+00:00
253
+ user:
254
+ username: 'duffyduck'
255
+ oauth: true
172
256
  response_expectation:
173
- status_code: 409
257
+ status_code: 404
258
+ headers:
259
+ Last-Modified: /.*/
260
+ body:
@@ -1,6 +1,6 @@
1
1
  class ApiRunner
2
2
  require 'yaml'
3
- require 'csv_writer'
3
+ require 'csv_writer' if defined?(Rails) and Rails.version.match(/^3.+$/)
4
4
  require 'string_ext' if not String.respond_to?(:underscore)
5
5
  require 'expectation_matcher'
6
6
  require 'http_client'
@@ -24,14 +24,14 @@ class ApiRunner
24
24
  load_url_spec
25
25
  @http_client = HttpClient.new(@configuration.protocol, @configuration.host, @configuration.port, @configuration.namespace)
26
26
  @expectation = ExpectationMatcher.new(@excludes)
27
- @csv_writer = CsvWriter.new(self.class.csv_path, env)
27
+ @csv_writer = CsvWriter.new(self.class.csv_path, env) if defined?(Rails) and Rails.version.match(/^3.+$/)
28
28
  end
29
29
 
30
30
  # checks servers availability and invokes test cases
31
31
  def run
32
32
  if server_is_available?
33
33
  run_tests
34
- @csv_writer.write(@configuration.csv_mode, @results) unless @results.empty?
34
+ @csv_writer.write(@configuration.csv_mode, @results) unless @results.empty? if defined?(Rails) and Rails.version.match(/^3.+$/)
35
35
  @results.each_with_index do |result, index|
36
36
  result.honk_in(@configuration.verbosity, index)
37
37
  end unless @results.empty?
@@ -1,11 +1,12 @@
1
1
  require 'apirunner'
2
- require 'rails'
2
+ require 'rails' if defined?(Rails) and Rails.version.match(/^3.+/)
3
3
 
4
4
  module Apirunner
5
- class Railtie < Rails::Railtie
6
-
7
- rake_tasks do
8
- load "tasks/api.rake"
5
+ if defined?(Rails) and Rails.version.match(/^3.+/)
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/api.rake"
9
+ end
9
10
  end
10
11
  end
11
12
  end
@@ -10,7 +10,8 @@ class Result
10
10
  end
11
11
 
12
12
  # honk out the errors message corresponding to the verbosity configuration the user took
13
- def honk_in(verbosity="rspec", index)
13
+ def honk_in(verbosity, index)
14
+ verbosity ||= "rspec"
14
15
  self.send(verbosity.to_sym, index)
15
16
  end
16
17
 
@@ -1,7 +1,14 @@
1
+ if defined?(Rails) and Rails.version.match(/^2.+$/)
2
+ APIRUNNER_ROOT = File.dirname(__FILE__).to_s + "/../../"
3
+ TEST_EXAMPLES_PATH = APIRUNNER_ROOT + "examples/test/api_runner"
4
+ CONFIG_EXAMPLE_PATH = APIRUNNER_ROOT + "examples/config"
5
+ end
6
+
1
7
  begin
2
8
  config = YAML.load_file("#{Rails.root}/config/api_runner.yml")
3
9
  rescue
4
10
  end
11
+
5
12
  namespace :api do
6
13
  namespace :run do
7
14
  config.delete_if{ |key| key == "general" }.each_key do |env|