apirunner 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/apirunner.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apirunner}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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"]
@@ -87,7 +87,6 @@
87
87
  method: 'PUT'
88
88
  body:
89
89
  "m1035": 1
90
- "m2087": 0.5
91
90
  "m1554": 2
92
91
  "m2981": 1.0
93
92
  "m1590": 2
@@ -122,7 +121,6 @@
122
121
  - m78
123
122
  ratings:
124
123
  "m1035": "1.0"
125
- "m2087": "0.5"
126
124
  "m1554": "2.0"
127
125
  "m2981": "1.0"
128
126
  "m1590": "2.0"
@@ -130,7 +128,7 @@
130
128
  "m1875": "5.0"
131
129
  "m7258": "2.5"
132
130
  - name: 'User creation should fail on wrong username'
133
- priority: 2
131
+ priority: 1
134
132
  request:
135
133
  headers:
136
134
  Content-Type: 'application/json'
@@ -141,7 +139,7 @@
141
139
  response_expectation:
142
140
  status_code: 409
143
141
  - name: 'User creation should fail on wrong fsk'
144
- priority: 2
142
+ priority: 1
145
143
  request:
146
144
  headers:
147
145
  Content-Type: 'application/json'
@@ -153,7 +151,7 @@
153
151
  response_expectation:
154
152
  status_code: 409
155
153
  - name: 'User creation should fail on wrong expiration_date'
156
- priority: 2
154
+ priority: 1
157
155
  request:
158
156
  headers:
159
157
  Content-Type: 'application/json'
@@ -1 +1,237 @@
1
1
  ---
2
+ - name: 'Update existing user - update watchlist'
3
+ request:
4
+ headers:
5
+ Content-Type: 'application/json'
6
+ path: '/users/duffyduck/watchlist'
7
+ method: 'PUT'
8
+ body:
9
+ - m367
10
+ - m73
11
+ - m42
12
+ - m23
13
+ response_expectation:
14
+ status_code: 204
15
+ body:
16
+ - name: 'Check users watchlist afterwards'
17
+ request:
18
+ headers:
19
+ Content-Type: 'application/json'
20
+ path: '/users/duffyduck'
21
+ method: 'GET'
22
+ response_expectation:
23
+ status_code: 200
24
+ headers:
25
+ Last-Modified: /.*/
26
+ body:
27
+ username: 'duffyduck'
28
+ watchlist:
29
+ - m367
30
+ - m73
31
+ - m42
32
+ - m23
33
+ - name: 'Update existing user - clean watchlist'
34
+ request:
35
+ headers:
36
+ Content-Type: 'application/json'
37
+ path: '/users/duffyduck/watchlist'
38
+ method: 'PUT'
39
+ body: []
40
+ response_expectation:
41
+ status_code: 204
42
+ - name: 'Check users watchlist for emptyness afterwards'
43
+ request:
44
+ headers:
45
+ Content-Type: 'application/json'
46
+ path: '/users/duffyduck'
47
+ method: 'GET'
48
+ response_expectation:
49
+ status_code: 200
50
+ headers:
51
+ Last-Modified: /.*/
52
+ body:
53
+ username: 'duffyduck'
54
+ watchlist: []
55
+ - name: 'Update existing user - update skiplist'
56
+ request:
57
+ headers:
58
+ Content-Type: 'application/json'
59
+ path: '/users/duffyduck/skiplist'
60
+ method: 'PUT'
61
+ body:
62
+ - m366
63
+ - m72
64
+ - m41
65
+ - m22
66
+ response_expectation:
67
+ status_code: 204
68
+ body:
69
+ - name: 'Check users skiplist afterwards'
70
+ request:
71
+ headers:
72
+ Content-Type: 'application/json'
73
+ path: '/users/duffyduck'
74
+ method: 'GET'
75
+ response_expectation:
76
+ status_code: 200
77
+ headers:
78
+ Last-Modified: /.*/
79
+ body:
80
+ username: 'duffyduck'
81
+ skiplist:
82
+ - m366
83
+ - m72
84
+ - m41
85
+ - m22
86
+ - name: 'Update existing user - clean skiplist'
87
+ request:
88
+ headers:
89
+ Content-Type: 'application/json'
90
+ path: '/users/duffyduck/skiplist'
91
+ method: 'PUT'
92
+ body: []
93
+ response_expectation:
94
+ status_code: 204
95
+ body:
96
+ - name: 'Check users skiplist emptyness afterwards'
97
+ request:
98
+ headers:
99
+ Content-Type: 'application/json'
100
+ path: '/users/duffyduck'
101
+ method: 'GET'
102
+ response_expectation:
103
+ status_code: 200
104
+ headers:
105
+ Last-Modified: /.*/
106
+ body:
107
+ username: 'duffyduck'
108
+ skiplist: []
109
+ - name: 'Update existing user - update blacklist'
110
+ request:
111
+ headers:
112
+ Content-Type: 'application/json'
113
+ path: '/users/duffyduck/blacklist'
114
+ method: 'PUT'
115
+ body:
116
+ - m365
117
+ - m71
118
+ - m40
119
+ - m21
120
+ response_expectation:
121
+ status_code: 204
122
+ body:
123
+ - name: 'Check Users blacklist afterwards'
124
+ request:
125
+ headers:
126
+ Content-Type: 'application/json'
127
+ path: '/users/duffyduck'
128
+ method: 'GET'
129
+ response_expectation:
130
+ status_code: 200
131
+ headers:
132
+ Last-Modified: /.*/
133
+ body:
134
+ username: 'duffyduck'
135
+ blacklist:
136
+ - m365
137
+ - m71
138
+ - m40
139
+ - m21
140
+ - name: 'Update existing user - clean blacklist'
141
+ request:
142
+ headers:
143
+ Content-Type: 'application/json'
144
+ path: '/users/duffyduck/blacklist'
145
+ method: 'PUT'
146
+ body: []
147
+ response_expectation:
148
+ status_code: 204
149
+ body:
150
+ - name: 'Check users blacklist emptyness afterwards'
151
+ request:
152
+ headers:
153
+ Content-Type: 'application/json'
154
+ path: '/users/duffyduck'
155
+ method: 'GET'
156
+ response_expectation:
157
+ status_code: 200
158
+ headers:
159
+ Last-Modified: /.*/
160
+ body:
161
+ username: 'duffyduck'
162
+ blacklist: []
163
+ - name : 'Watchlist update of a non existing profile should return 404'
164
+ request:
165
+ headers:
166
+ Content-Type: 'application/json'
167
+ path: '/users/foobarfooz/watchlist'
168
+ method: 'PUT'
169
+ body:
170
+ watchlist:
171
+ - m365
172
+ - m71
173
+ response_expectation:
174
+ status_code: 404
175
+ - name : 'Skiplist update of a non existing profile should return 404'
176
+ request:
177
+ headers:
178
+ Content-Type: 'application/json'
179
+ path: '/users/foobarfooz/skiplist'
180
+ method: 'PUT'
181
+ body:
182
+ skiplist:
183
+ - m365
184
+ - m71
185
+ response_expectation:
186
+ status_code: 404
187
+ - name : 'Blacklist update of a non existing profile should return 404'
188
+ request:
189
+ headers:
190
+ Content-Type: 'application/json'
191
+ path: '/users/foobarfooz/blacklist'
192
+ method: 'PUT'
193
+ body:
194
+ blacklist:
195
+ - m365
196
+ - m71
197
+ response_expectation:
198
+ status_code: 404
199
+ - name : 'Watchlist update with non existing movies should return 409'
200
+ request:
201
+ headers:
202
+ Content-Type: 'application/json'
203
+ path: '/users/duffyduck/watchlist'
204
+ method: 'PUT'
205
+ body:
206
+ watchlist:
207
+ - m9999999999999999
208
+ - m8888888888888888
209
+ - m7777777777777777
210
+ response_expectation:
211
+ status_code: 409
212
+ - name : 'Blacklist update with non existing movies should return 409'
213
+ request:
214
+ headers:
215
+ Content-Type: 'application/json'
216
+ path: '/users/duffyduck/blacklist'
217
+ method: 'PUT'
218
+ body:
219
+ blacklist:
220
+ - m9999999999999999
221
+ - m8888888888888888
222
+ - m7777777777777777
223
+ response_expectation:
224
+ status_code: 409
225
+ - name : 'Skiplist update with non existing movies should return 409'
226
+ request:
227
+ headers:
228
+ Content-Type: 'application/json'
229
+ path: '/users/duffyduck/skiplist'
230
+ method: 'PUT'
231
+ body:
232
+ skiplist:
233
+ - m9999999999999999
234
+ - m8888888888888888
235
+ - m7777777777777777
236
+ response_expectation:
237
+ status_code: 409
@@ -1 +1,27 @@
1
1
  ---
2
+ - name: "Without per_page there should come out 1 rateable movie"
3
+ request:
4
+ path: '/users/duffyduck/rateables'
5
+ method: 'GET'
6
+ headers:
7
+ Content-Type: 'application/json'
8
+ body: {}
9
+ response_expectation:
10
+ status_code: 200
11
+ headers:
12
+ Last-Modified: /.*/
13
+ body: /^\["m\d+"\]$/
14
+ - name: "With per_page 10 there should come out 10 rateable movies"
15
+ request:
16
+ path: '/users/duffyduck/rateables?per_page=10'
17
+ parameters:
18
+ per_page: 10
19
+ method: 'GET'
20
+ headers:
21
+ Content-Type: 'application/json'
22
+ body: {}
23
+ response_expectation:
24
+ status_code: 200
25
+ headers:
26
+ Last-Modified: /.*/
27
+ body: /^\[("m\d+",?){10}\]$/
@@ -6,17 +6,42 @@
6
6
  body: {}
7
7
  response_expectation:
8
8
  status_code: 202
9
+ - name: 'User 1 should be nonexistant afterwards'
10
+ request:
11
+ path: '/users/duffyduck'
12
+ method: 'GET'
13
+ body: {}
14
+ response_expectation:
15
+ status_code: 404
9
16
  - name: 'Delete User 2'
17
+ priority: 1
10
18
  request:
11
19
  path: '/users/duffyduck2'
12
20
  method: 'DELETE'
13
21
  body: {}
14
22
  response_expectation:
15
23
  status_code: 202
24
+ - name: 'User 2 should be nonexistant afterwards'
25
+ priority: 1
26
+ request:
27
+ path: '/users/duffyduck2'
28
+ method: 'GET'
29
+ body: {}
30
+ response_expectation:
31
+ status_code: 404
16
32
  - name: 'Delete User 3'
33
+ priority: 1
17
34
  request:
18
35
  path: '/users/duffyduck3'
19
36
  method: 'DELETE'
20
37
  body: {}
21
38
  response_expectation:
22
39
  status_code: 202
40
+ - name: 'User 3 should be nonexistant afterwards'
41
+ priority: 1
42
+ request:
43
+ path: '/users/duffyduck3'
44
+ method: 'GET'
45
+ body: {}
46
+ response_expectation:
47
+ status_code: 404
@@ -66,6 +66,15 @@ class ExpectationMatcher
66
66
  def response_body(response, testcase)
67
67
  result = Result.new(testcase, response)
68
68
 
69
+ # special case: the whole body has to be matched via a regular expression
70
+ if is_regex?(testcase['response_expectation']['body'])
71
+ if not regex_matches?(testcase['response_expectation']['body'], response.body)
72
+ result.succeeded = false
73
+ result.error_message = " expected the whole body to match regex --#{testcase['response_expectation']['body']}--\n got --#{response.body}--"
74
+ end
75
+ return result
76
+ end
77
+
69
78
  expected_body_hash = testcase['response_expectation']['body']
70
79
 
71
80
  # in case we have no body expectation we simply return success
@@ -76,7 +85,7 @@ class ExpectationMatcher
76
85
  responded_body_hash = JSON.parse(response.body)
77
86
  rescue
78
87
  result = Result.new(testcase, response)
79
- result.success = false
88
+ result.succeeded = false
80
89
  result.error_message = " expected response to have a body\n got raw body --#{response.body}-- which is nil or an unparseable hash"
81
90
  return result
82
91
  end
@@ -90,6 +99,10 @@ class ExpectationMatcher
90
99
  expectation_node = expectation_tree.xpath(path).first
91
100
  response_node = response_tree.xpath(path).first
92
101
 
102
+ debugger
103
+ # in some (not awesome) cases the root node occures as leaf, so we have to skip him here
104
+ next if expectation_node.name == "hash"
105
+
93
106
  # return error if response body does not have the expected entry
94
107
  if response_node.nil?
95
108
  result.succeeded = false
data/lib/http_client.rb CHANGED
@@ -17,7 +17,6 @@ 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
21
20
  response_struct = Struct.new(:code, :message, :headers, :body)
22
21
  response = response_struct.new
23
22
  response.code = raw_response.code
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - jan@moviepilot.com
@@ -271,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
271
  requirements:
272
272
  - - ">="
273
273
  - !ruby/object:Gem::Version
274
- hash: -2602692957616549135
274
+ hash: -3503113694537890218
275
275
  segments:
276
276
  - 0
277
277
  version: "0"