flapjack-diner 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +135 -0
  5. data/Gemfile +7 -0
  6. data/README.md +86 -20
  7. data/flapjack-diner.gemspec +11 -15
  8. data/lib/flapjack-diner.rb +23 -548
  9. data/lib/flapjack-diner/argument_validator.rb +31 -22
  10. data/lib/flapjack-diner/resources/checks.rb +58 -0
  11. data/lib/flapjack-diner/resources/contacts.rb +70 -0
  12. data/lib/flapjack-diner/resources/entities.rb +68 -0
  13. data/lib/flapjack-diner/resources/maintenance_periods.rb +82 -0
  14. data/lib/flapjack-diner/resources/media.rb +61 -0
  15. data/lib/flapjack-diner/resources/notification_rules.rb +66 -0
  16. data/lib/flapjack-diner/resources/notifications.rb +27 -0
  17. data/lib/flapjack-diner/resources/pagerduty_credentials.rb +60 -0
  18. data/lib/flapjack-diner/resources/reports.rb +33 -0
  19. data/lib/flapjack-diner/tools.rb +277 -0
  20. data/lib/flapjack-diner/version.rb +1 -1
  21. data/spec/argument_validator_spec.rb +15 -15
  22. data/spec/flapjack-diner_spec.rb +58 -1275
  23. data/spec/pacts/flapjack-diner-flapjack.json +4522 -0
  24. data/spec/resources/checks_spec.rb +171 -0
  25. data/spec/resources/contacts_spec.rb +297 -0
  26. data/spec/resources/entities_spec.rb +181 -0
  27. data/spec/resources/maintenance_periods_spec.rb +603 -0
  28. data/spec/resources/media_spec.rb +277 -0
  29. data/spec/resources/notification_rules_spec.rb +341 -0
  30. data/spec/resources/notifications_spec.rb +210 -0
  31. data/spec/resources/pagerduty_credentials_spec.rb +243 -0
  32. data/spec/resources/reports_spec.rb +255 -0
  33. data/spec/spec_helper.rb +14 -2
  34. metadata +35 -72
@@ -1,5 +1,5 @@
1
1
  module Flapjack
2
2
  module Diner
3
- VERSION = "1.0.0"
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -12,21 +12,21 @@ describe Flapjack::ArgumentValidator do
12
12
  subject { Flapjack::ArgumentValidator.new(query) }
13
13
 
14
14
  it 'does not raise an exception when query entity is valid' do
15
- lambda { subject.validate(:query => :entity, :as => :required) }.should_not raise_exception
15
+ expect { subject.validate(:query => :entity, :as => :required) }.not_to raise_exception
16
16
  end
17
17
 
18
18
  it 'raises ArgumentError when query entity is invalid' do
19
19
  query[:entity] = nil
20
- lambda { subject.validate(:query => :entity, :as => :required) }.should raise_exception
20
+ expect { subject.validate(:query => :entity, :as => :required) }.to raise_exception
21
21
  end
22
22
 
23
23
  it 'handles arrays as query values valid' do
24
- lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should_not raise_exception
24
+ expect { subject.validate(:query => [:entity, :check], :as => :required) }.not_to raise_exception
25
25
  end
26
26
 
27
27
  it 'handles arrays as query values invalid' do
28
28
  query[:check] = nil
29
- lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should raise_exception
29
+ expect { subject.validate(:query => [:entity, :check], :as => :required) }.to raise_exception
30
30
  end
31
31
  end
32
32
 
@@ -39,37 +39,37 @@ describe Flapjack::ArgumentValidator do
39
39
  subject { Flapjack::ArgumentValidator.new(query) }
40
40
 
41
41
  it 'does not raise an exception when query start_time is valid' do
42
- lambda { subject.validate(:query => :start_time, :as => :time) }.should_not raise_exception
42
+ expect { subject.validate(:query => :start_time, :as => :time) }.not_to raise_exception
43
43
  end
44
44
 
45
45
  it 'raises an exception when query start_time is invalid' do
46
46
  query[:start_time] = 1234
47
- lambda { subject.validate(:query => :start_time, :as => :time) }.should raise_exception
47
+ expect { subject.validate(:query => :start_time, :as => :time) }.to raise_exception
48
48
  end
49
49
 
50
50
  it 'handles arrays as query values valid' do
51
51
  query[:end_time] = Time.now
52
- lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should_not raise_exception
52
+ expect { subject.validate(:query => [:start_time, :end_time], :as => :time) }.not_to raise_exception
53
53
  end
54
54
 
55
55
  it 'handles arrays as query values invalid' do
56
56
  query[:end_time] = 3904
57
- lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should raise_exception
57
+ expect { subject.validate(:query => [:start_time, :end_time], :as => :time) }.to raise_exception
58
58
  end
59
59
 
60
60
  it 'handles dates as query values' do
61
61
  query[:end_time] = Date.today
62
- lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
62
+ expect { subject.validate(:query => :end_time, :as => :time) }.not_to raise_exception
63
63
  end
64
64
 
65
65
  it 'handles ISO 8601 strings as query values' do
66
66
  query[:end_time] = Time.now.iso8601
67
- lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
67
+ expect { subject.validate(:query => :end_time, :as => :time) }.not_to raise_exception
68
68
  end
69
69
 
70
70
  it 'raises an exception when invalid time strings are provided' do
71
71
  query[:end_time] = '2011-08-01T00:00'
72
- lambda { subject.validate(:query => :end_time, :as => :time) }.should raise_exception
72
+ expect { subject.validate(:query => :end_time, :as => :time) }.to raise_exception
73
73
  end
74
74
  end
75
75
 
@@ -82,12 +82,12 @@ describe Flapjack::ArgumentValidator do
82
82
  subject { Flapjack::ArgumentValidator.new(query) }
83
83
 
84
84
  it 'does not raise an exception when query duration is valid' do
85
- lambda { subject.validate(:query => :duration, :as => :integer) }.should_not raise_exception
85
+ expect { subject.validate(:query => :duration, :as => :integer) }.not_to raise_exception
86
86
  end
87
87
 
88
88
  it 'raises an exception when query duration is invalid' do
89
89
  query[:duration] = '23'
90
- lambda { subject.validate(:query => :duration, :as => :integer) }.should raise_exception
90
+ expect { subject.validate(:query => :duration, :as => :integer) }.to raise_exception
91
91
  end
92
92
  end
93
93
 
@@ -100,12 +100,12 @@ describe Flapjack::ArgumentValidator do
100
100
  subject { Flapjack::ArgumentValidator.new(query) }
101
101
 
102
102
  it 'does not raise an exception when query start_time is valid' do
103
- lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should_not raise_exception
103
+ expect { subject.validate(:query => :start_time, :as => [:time, :required]) }.not_to raise_exception
104
104
  end
105
105
 
106
106
  it 'raises an exception when query start_time is invalid' do
107
107
  query[:start_time] = nil
108
- lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should raise_exception
108
+ expect { subject.validate(:query => :start_time, :as => [:time, :required]) }.to raise_exception
109
109
  end
110
110
  end
111
111
  end
@@ -14,1275 +14,58 @@ describe Flapjack::Diner do
14
14
  before(:each) do
15
15
  Flapjack::Diner.base_uri(server)
16
16
  Flapjack::Diner.logger = nil
17
- Flapjack::Diner.return_keys_as_strings = true
18
17
  end
19
18
 
20
19
  after(:each) do
21
20
  WebMock.reset!
22
21
  end
23
22
 
24
- context 'contacts' do
25
- context 'create' do
23
+ context 'argument parsing' do
26
24
 
27
- it "submits a POST request for a contact" do
28
- data = [{:first_name => 'Jim',
29
- :last_name => 'Smith',
30
- :email => 'jims@example.com',
31
- :timezone => 'UTC',
32
- :tags => ['admin', 'night_shift']}]
33
-
34
- req = stub_request(:post, "http://#{server}/contacts").
35
- with(:body => {:contacts => data}.to_json,
36
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
37
- to_return(:status => 201, :body => response_with_data('contacts', data))
38
-
39
- result = Flapjack::Diner.create_contacts(data)
40
- req.should have_been_requested
41
- result.should_not be_nil
42
- result.should be_true
43
- end
44
-
45
- it "submits a POST request for several contacts" do
46
- data = [{:first_name => 'Jim',
47
- :last_name => 'Smith',
48
- :email => 'jims@example.com',
49
- :timezone => 'UTC',
50
- :tags => ['admin', 'night_shift']},
51
- {:first_name => 'Joan',
52
- :last_name => 'Smith',
53
- :email => 'joans@example.com'}]
54
-
55
- req = stub_request(:post, "http://#{server}/contacts").
56
- with(:body => {:contacts => data}.to_json,
57
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
58
- to_return(:status => 201, :body => response_with_data('contacts', data))
59
-
60
- result = Flapjack::Diner.create_contacts(data)
61
- req.should have_been_requested
62
- result.should_not be_nil
63
- result.should be_true
64
- end
65
-
66
- end
67
-
68
- context 'read' do
69
- it "submits a GET request for all contacts" do
70
- data = [{:id => "21"}]
71
-
72
- req = stub_request(:get, "http://#{server}/contacts").to_return(
73
- :status => 200, :body => response_with_data('contacts', data))
74
-
75
- result = Flapjack::Diner.contacts
76
- req.should have_been_requested
77
- result.should_not be_nil
78
- result.should be_an_instance_of(Array)
79
- result.length.should be(1)
80
- result[0].should be_an_instance_of(Hash)
81
- result[0].should have_key('id')
82
- end
83
-
84
- it "can return keys as symbols" do
85
- Flapjack::Diner.return_keys_as_strings = false
86
- data = [{
87
- :id => "21",
88
- :first_name => "Ada",
89
- :last_name => "Lovelace",
90
- :email => "ada@example.com",
91
- :timezone => "Europe/London",
92
- :tags => [ "legend", "first computer programmer" ],
93
- :links => {
94
- :entities => ["7", "12", "83"],
95
- :media => ["21_email", "21_sms"],
96
- :notification_rules => ["30fd36ae-3922-4957-ae3e-c8f6dd27e543"]
97
- }
98
- }]
99
-
100
- req = stub_request(:get, "http://#{server}/contacts").to_return(
101
- :status => 200, :body => response_with_data('contacts', data))
102
-
103
- result = Flapjack::Diner.contacts
104
- req.should have_been_requested
105
- result.should_not be_nil
106
- result.should be_an_instance_of(Array)
107
- result.length.should be(1)
108
- result[0].should be_an_instance_of(Hash)
109
- result[0].should have_key(:id)
110
- result[0].should have_key(:links)
111
- result[0][:links].should have_key(:entities)
112
- end
113
-
114
- it "submits a GET request for one contact" do
115
- req = stub_request(:get, "http://#{server}/contacts/72").to_return(
116
- :body => response_with_data('contacts'))
117
-
118
- result = Flapjack::Diner.contacts('72')
119
- req.should have_been_requested
120
- result.should_not be_nil
121
- end
122
-
123
- it "submits a GET request for several contacts" do
124
- req = stub_request(:get, "http://#{server}/contacts/72,150").to_return(
125
- :body => response_with_data('contacts'))
126
-
127
- result = Flapjack::Diner.contacts('72', '150')
128
- req.should have_been_requested
129
- result.should_not be_nil
130
- end
131
- end
132
-
133
- context 'update' do
134
-
135
- it "submits a PATCH request for one contact" do
136
- req = stub_request(:patch, "http://#{server}/contacts/23").
137
- with(:body => [{:op => 'replace', :path => '/contacts/0/timezone', :value => 'UTC'}].to_json,
138
- :headers => {'Content-Type'=>'application/json-patch+json'}).
139
- to_return(:status => 204)
140
-
141
- result = Flapjack::Diner.update_contacts(23, :timezone => 'UTC')
142
- req.should have_been_requested
143
- result.should_not be_nil
144
- result.should be_true
145
- end
146
-
147
- it "submits a PATCH request for several contacts" do
148
- req = stub_request(:patch, "http://#{server}/contacts/23,87").
149
- with(:body => [{:op => 'replace', :path => '/contacts/0/timezone', :value => 'UTC'}].to_json,
150
- :headers => {'Content-Type'=>'application/json-patch+json'}).
151
- to_return(:status => 204)
152
-
153
- result = Flapjack::Diner.update_contacts(23, 87, :timezone => 'UTC')
154
- req.should have_been_requested
155
- result.should_not be_nil
156
- result.should be_true
157
- end
158
-
159
- it "submits a PATCH request to change a link for one contact" do
160
- req = stub_request(:patch, "http://#{server}/contacts/23").
161
- with(:body => [{:op => 'add', :path => '/contacts/0/links/entities/-', :value => '57'}].to_json,
162
- :headers => {'Content-Type'=>'application/json-patch+json'}).
163
- to_return(:status => 204)
164
-
165
- result = Flapjack::Diner.update_contacts(23, :add_entity => '57')
166
- req.should have_been_requested
167
- result.should_not be_nil
168
- result.should be_true
169
- end
170
-
171
- it "submits a PATCH request to change links for several contacts" do
172
- req = stub_request(:patch, "http://#{server}/contacts/23,87").
173
- with(:body => [{:op => 'add', :path => '/contacts/0/links/entities/-', :value => '57'}].to_json,
174
- :headers => {'Content-Type'=>'application/json-patch+json'}).
175
- to_return(:status => 204)
176
-
177
- result = Flapjack::Diner.update_contacts(23, 87, :add_entity => '57')
178
- req.should have_been_requested
179
- result.should_not be_nil
180
- result.should be_true
181
- end
182
-
183
- end
184
-
185
- context 'delete' do
186
- it "submits a DELETE request for one contact" do
187
- req = stub_request(:delete, "http://#{server}/contacts/72").
188
- to_return(:status => 204)
189
-
190
- result = Flapjack::Diner.delete_contacts('72')
191
- req.should have_been_requested
192
- result.should_not be_nil
193
- result.should be_true
194
- end
195
-
196
- it "submits a DELETE request for several contacts" do
197
- req = stub_request(:delete, "http://#{server}/contacts/72,150").
198
- to_return(:status => 204)
199
-
200
- result = Flapjack::Diner.delete_contacts('72', '150')
201
- req.should have_been_requested
202
- result.should_not be_nil
203
- result.should be_true
204
- end
205
- end
206
25
  end
207
26
 
208
- context 'media' do
209
- context 'create' do
210
-
211
- it "submits a POST request for a medium" do
212
- data = [{
213
- :type => 'sms',
214
- :address => '0123456789',
215
- :interval => 300,
216
- :rollup_threshold => 5
217
- }]
218
-
219
- req = stub_request(:post, "http://#{server}/contacts/1/media").
220
- with(:body => {:media => data}.to_json,
221
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
222
- to_return(:status => 201, :body => response_with_data('media', data))
223
-
224
- result = Flapjack::Diner.create_contact_media(1, data)
225
- req.should have_been_requested
226
- result.should_not be_nil
227
- result.should be_true
228
- end
229
-
230
- it "submits a POST request for several media" do
231
- data = [{
232
- :type => 'sms',
233
- :address => '0123456789',
234
- :interval => 300,
235
- :rollup_threshold => 5
236
- }, {
237
- :type => 'email',
238
- :address => 'ablated@example.org',
239
- :interval => 180,
240
- :rollup_threshold => 3
241
- }]
242
-
243
- req = stub_request(:post, "http://#{server}/contacts/1/media").
244
- with(:body => {:media => data}.to_json,
245
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
246
- to_return(:status => 201, :body => response_with_data('media', data))
247
-
248
- result = Flapjack::Diner.create_contact_media(1, data)
249
- req.should have_been_requested
250
- result.should_not be_nil
251
- result.should be_true
252
- end
253
-
254
- end
255
-
256
- context 'read' do
257
- it "submits a GET request for all media" do
258
- req = stub_request(:get, "http://#{server}/media").
259
- to_return(:body => response_with_data('media'))
260
-
261
- result = Flapjack::Diner.media
262
- req.should have_been_requested
263
- result.should_not be_nil
264
- end
265
-
266
- it "submits a GET request for one medium" do
267
- req = stub_request(:get, "http://#{server}/media/72_sms").
268
- to_return(:body => response_with_data('media'))
269
-
270
- result = Flapjack::Diner.media('72_sms')
271
- req.should have_been_requested
272
- result.should_not be_nil
273
- end
274
-
275
- it "submits a GET request for several media" do
276
- req = stub_request(:get, "http://#{server}/media/72_sms,150_email").
277
- to_return(:body => response_with_data('media'))
278
-
279
- result = Flapjack::Diner.media('72_sms', '150_email')
280
- req.should have_been_requested
281
- result.should_not be_nil
282
- end
283
- end
284
-
285
- context 'update' do
286
-
287
- it "submits a PATCH request for one medium" do
288
- req = stub_request(:patch, "http://#{server}/media/23_email").
289
- with(:body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
290
- {:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}].to_json,
291
- :headers => {'Content-Type'=>'application/json-patch+json'}).
292
- to_return(:status => 204)
293
-
294
- result = Flapjack::Diner.update_media('23_email', :interval => 50, :rollup_threshold => 3)
295
- req.should have_been_requested
296
- result.should_not be_nil
297
- result.should be_true
298
- end
299
-
300
- it "submits a PATCH request for several media" do
301
- req = stub_request(:patch, "http://#{server}/media/23_email,87_sms").
302
- with(:body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
303
- {:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}].to_json,
304
- :headers => {'Content-Type'=>'application/json-patch+json'}).
305
- to_return(:status => 204)
306
-
307
- result = Flapjack::Diner.update_media('23_email', '87_sms', :interval => 50, :rollup_threshold => 3)
308
- req.should have_been_requested
309
- result.should_not be_nil
310
- result.should be_true
311
- end
312
-
313
- end
314
-
315
- context 'delete' do
316
- it "submits a DELETE request for one medium" do
317
- req = stub_request(:delete, "http://#{server}/media/72_sms").
318
- to_return(:status => 204)
319
-
320
- result = Flapjack::Diner.delete_media('72_sms')
321
- req.should have_been_requested
322
- result.should_not be_nil
323
- result.should be_true
324
- end
325
-
326
- it "submits a DELETE request for several media" do
327
- req = stub_request(:delete, "http://#{server}/media/72_sms,150_email").
328
- to_return(:status => 204)
329
-
330
- result = Flapjack::Diner.delete_media('72_sms', '150_email')
331
- req.should have_been_requested
332
- result.should_not be_nil
333
- result.should be_true
334
- end
335
- end
336
- end
337
-
338
- context 'pagerduty credentials' do
339
- context 'create' do
340
-
341
- it "submits a POST request for pagerduty credentials" do
342
- data = [{:service_key => 'abc',
343
- :subdomain => 'def',
344
- :username => 'ghi',
345
- :password => 'jkl',
346
- }]
347
-
348
- req = stub_request(:post, "http://#{server}/contacts/1/pagerduty_credentials").
349
- with(:body => {:pagerduty_credentials => data}.to_json,
350
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
351
- to_return(:status => 201, :body => response_with_data('pagerduty_credentials', data))
352
-
353
- result = Flapjack::Diner.create_contact_pagerduty_credentials(1, data)
354
- req.should have_been_requested
355
- result.should_not be_nil
356
- result.should be_true
357
- end
358
-
359
- end
360
-
361
- context 'read' do
362
- it "submits a GET request for all pagerduty credentials" do
363
- req = stub_request(:get, "http://#{server}/pagerduty_credentials").
364
- to_return(:body => response_with_data('pagerduty_credentials'))
365
-
366
- result = Flapjack::Diner.pagerduty_credentials
367
- req.should have_been_requested
368
- result.should_not be_nil
369
- end
370
-
371
- it "submits a GET request for one set of pagerduty credentials" do
372
- req = stub_request(:get, "http://#{server}/pagerduty_credentials/72").
373
- to_return(:body => response_with_data('pagerduty_credentials'))
374
-
375
- result = Flapjack::Diner.pagerduty_credentials('72')
376
- req.should have_been_requested
377
- result.should_not be_nil
378
- end
379
-
380
- it "submits a GET request for several sets of pagerduty credentials" do
381
- req = stub_request(:get, "http://#{server}/pagerduty_credentials/72,150").
382
- to_return(:body => response_with_data('pagerduty_credentials'))
383
-
384
- result = Flapjack::Diner.pagerduty_credentials('72', '150')
385
- req.should have_been_requested
386
- result.should_not be_nil
387
- end
388
- end
389
-
390
- context 'update' do
391
-
392
- it "submits a PATCH request for one set of pagerduty credentials" do
393
- req = stub_request(:patch, "http://#{server}/pagerduty_credentials/23").
394
- with(:body => [{:op => 'replace', :path => '/pagerduty_credentials/0/password', :value => 'lmno'}].to_json,
395
- :headers => {'Content-Type'=>'application/json-patch+json'}).
396
- to_return(:status => 204)
397
-
398
- result = Flapjack::Diner.update_pagerduty_credentials('23', :password => 'lmno')
399
- req.should have_been_requested
400
- result.should_not be_nil
401
- result.should be_true
402
- end
403
-
404
- it "submits a PATCH request for several sets of pagerduty credentials" do
405
- req = stub_request(:patch, "http://#{server}/pagerduty_credentials/23,87").
406
- with(:body => [{:op => 'replace', :path => '/pagerduty_credentials/0/username', :value => 'hijk'},
407
- {:op => 'replace', :path => '/pagerduty_credentials/0/password', :value => 'lmno'}].to_json,
408
- :headers => {'Content-Type'=>'application/json-patch+json'}).
409
- to_return(:status => 204)
410
-
411
- result = Flapjack::Diner.update_pagerduty_credentials('23', '87', :username => 'hijk', :password => 'lmno')
412
- req.should have_been_requested
413
- result.should_not be_nil
414
- result.should be_true
415
- end
416
-
417
- end
418
-
419
- context 'delete' do
420
- it "submits a DELETE request for one set of pagerduty credentials" do
421
- req = stub_request(:delete, "http://#{server}/pagerduty_credentials/72").
422
- to_return(:status => 204)
423
-
424
- result = Flapjack::Diner.delete_pagerduty_credentials('72')
425
- req.should have_been_requested
426
- result.should_not be_nil
427
- result.should be_true
428
- end
429
-
430
- it "submits a DELETE request for several media" do
431
- req = stub_request(:delete, "http://#{server}/pagerduty_credentials/72,150").
432
- to_return(:status => 204)
433
-
434
- result = Flapjack::Diner.delete_pagerduty_credentials('72', '150')
435
- req.should have_been_requested
436
- result.should_not be_nil
437
- result.should be_true
438
- end
439
- end
440
- end
441
-
442
- context 'notification rules' do
443
-
444
- context 'create' do
445
-
446
- it "submits a POST request for a notification rule" do
447
- data = [{
448
- "entity_tags" => ["database","physical"],
449
- "entities" => ["foo-app-01.example.com"],
450
- "time_restrictions" => nil,
451
- "warning_media" => ["email"],
452
- "critical_media" => ["sms", "email"],
453
- "warning_blackhole" => false,
454
- "critical_blackhole" => false
455
- }]
456
-
457
- req = stub_request(:post, "http://#{server}/contacts/1/notification_rules").
458
- with(:body => {:notification_rules => data}.to_json,
459
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
460
- to_return(:status => 201, :body => response_with_data('notification_rules', data))
461
-
462
-
463
- result = Flapjack::Diner.create_contact_notification_rules(1, data)
464
- req.should have_been_requested
465
- result.should_not be_nil
466
- result.should be_true
467
- end
468
-
469
- it "submits a POST request for several notification rules" do
470
- data = [{
471
- "entity_tags" => ["database","physical"],
472
- "entities" => ["foo-app-01.example.com"],
473
- "time_restrictions" => nil,
474
- "warning_media" => ["email"],
475
- "critical_media" => ["sms", "email"],
476
- "warning_blackhole" => false,
477
- "critical_blackhole" => false
478
- }, {
479
- "entity_tags" => nil,
480
- "entities" => ["foo-app-02.example.com"],
481
- "time_restrictions" => nil,
482
- "warning_media" => ["email"],
483
- "critical_media" => ["sms", "email"],
484
- "warning_blackhole" => true,
485
- "critical_blackhole" => false
486
- }]
487
-
488
- req = stub_request(:post, "http://#{server}/contacts/1/notification_rules").
489
- with(:body => {:notification_rules => data}.to_json,
490
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
491
- to_return(:status => 201, :body => response_with_data('notification_rules', data))
492
-
493
- result = Flapjack::Diner.create_contact_notification_rules(1, data)
494
- req.should have_been_requested
495
- result.should_not be_nil
496
- result.should be_true
497
- end
498
-
499
- end
500
-
501
- context 'read' do
502
- it "submits a GET request for all notification rules" do
503
- req = stub_request(:get, "http://#{server}/notification_rules").
504
- to_return(:body => response_with_data('notification_rules'))
505
-
506
- result = Flapjack::Diner.notification_rules
507
- req.should have_been_requested
508
- result.should_not be_nil
509
- end
510
-
511
- it "submits a GET request for one notification rule" do
512
- req = stub_request(:get, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
513
- to_return(:body => response_with_data('notification_rules'))
514
-
515
- result = Flapjack::Diner.notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543')
516
- req.should have_been_requested
517
- result.should_not be_nil
518
- end
519
-
520
- it "submits a GET request for several media" do
521
- req = stub_request(:get, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
522
- to_return(:body => response_with_data('notification_rules'))
523
-
524
- result = Flapjack::Diner.notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', 'bfd8be61-3d80-4b95-94df-6e77183ce4e3')
525
- req.should have_been_requested
526
- result.should_not be_nil
527
- end
528
- end
529
-
530
- context 'update' do
531
-
532
- it "submits a PATCH request for one notification rule" do
533
- req = stub_request(:patch, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
534
- with(:body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}].to_json,
535
- :headers => {'Content-Type'=>'application/json-patch+json'}).
536
- to_return(:status => 204)
537
-
538
- result = Flapjack::Diner.update_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', :warning_blackhole => false)
539
- req.should have_been_requested
540
- result.should_not be_nil
541
- result.should be_true
542
- end
543
-
544
- it "submits a PATCH request for several notification rules" do
545
- req = stub_request(:patch, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
546
- with(:body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}].to_json,
547
- :headers => {'Content-Type'=>'application/json-patch+json'}).
548
- to_return(:status => 204)
549
-
550
- result = Flapjack::Diner.update_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543',
551
- 'bfd8be61-3d80-4b95-94df-6e77183ce4e3', :warning_blackhole => false)
552
- req.should have_been_requested
553
- result.should_not be_nil
554
- result.should be_true
555
- end
556
-
557
- end
558
-
559
- context 'delete' do
560
- it "submits a DELETE request for a notification rule" do
561
- req = stub_request(:delete, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
562
- to_return(:status => 204)
563
-
564
- result = Flapjack::Diner.delete_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543')
565
- req.should have_been_requested
566
- result.should_not be_nil
567
- result.should be_true
568
- end
569
-
570
- it "submits a DELETE request for several notification rules" do
571
- req = stub_request(:delete, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
572
- to_return(:status => 204)
573
-
574
- result = Flapjack::Diner.delete_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', 'bfd8be61-3d80-4b95-94df-6e77183ce4e3')
575
- req.should have_been_requested
576
- result.should_not be_nil
577
- result.should be_true
578
- end
579
- end
580
- end
581
-
582
- context 'entities' do
583
-
584
- context 'create' do
585
-
586
- it "submits a POST request for an entity" do
587
- data = [{
588
- :name => 'example.org',
589
- :id => '57_example'
590
- }]
591
-
592
- req = stub_request(:post, "http://#{server}/entities").
593
- with(:body => {:entities => data}.to_json,
594
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
595
- to_return(:status => 201, :body => response_with_data('entities', data))
596
-
597
- result = Flapjack::Diner.create_entities(data)
598
- req.should have_been_requested
599
- result.should_not be_nil
600
- result.should be_true
601
- end
602
-
603
- it "submits a POST request for several entities" do
604
- data = [{
605
- :name => 'example.org',
606
- :id => '57_example'
607
- }, {
608
- :name => 'example2.org',
609
- :id => '58'
610
- }]
611
-
612
- req = stub_request(:post, "http://#{server}/entities").
613
- with(:body => {:entities => data}.to_json,
614
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
615
- to_return(:status => 201, :body => response_with_data('entities', data))
616
-
617
- result = Flapjack::Diner.create_entities(data)
618
- req.should have_been_requested
619
- result.should_not be_nil
620
- result.should be_true
621
- end
622
-
623
- context 'scheduled maintenance periods' do
624
-
625
- it "submits a POST request on an entity" do
626
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
627
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72").
628
- with(:body => {:scheduled_maintenances => data}.to_json,
629
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
630
- to_return(:status => 204)
631
-
632
- result = Flapjack::Diner.create_scheduled_maintenances_entities(72, data)
633
- req.should have_been_requested
634
- result.should_not be_nil
635
- result.should be_true
636
- end
637
-
638
- it "submits a POST request on several entities" do
639
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
640
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72,150").
641
- with(:body => {:scheduled_maintenances => data}.to_json,
642
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
643
- to_return(:status => 204)
644
-
645
- result = Flapjack::Diner.create_scheduled_maintenances_entities(72, 150, data)
646
- req.should have_been_requested
647
- result.should_not be_nil
648
- result.should be_true
649
- end
650
-
651
- it "submits a POST request for multiple periods on an entity" do
652
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
653
- {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
654
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72").
655
- with(:body => {:scheduled_maintenances => data}.to_json,
656
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
657
- to_return(:status => 204)
658
-
659
- result = Flapjack::Diner.create_scheduled_maintenances_entities(72, data)
660
- req.should have_been_requested
661
- result.should_not be_nil
662
- result.should be_true
663
- end
664
-
665
- it "submits a POST request for multiple periods on several entities" do
666
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
667
- {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
668
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72,150").
669
- with(:body => {:scheduled_maintenances => data}.to_json,
670
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
671
- to_return(:status => 204)
672
-
673
- result = Flapjack::Diner.create_scheduled_maintenances_entities(72, 150, data)
674
- req.should have_been_requested
675
- result.should_not be_nil
676
- result.should be_true
677
- end
678
-
679
- end
680
-
681
- context 'unscheduled maintenance periods' do
682
-
683
- it "submits a POST request on an entity" do
684
- data = [{:duration => 3600, :summary => 'working'}]
685
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72").
686
- with(:body => {:unscheduled_maintenances => data}.to_json,
687
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
688
- to_return(:status => 204)
689
-
690
- result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, data)
691
- req.should have_been_requested
692
- result.should_not be_nil
693
- result.should be_true
694
- end
695
-
696
- it "submits a POST request on several entities" do
697
- data = [{:duration => 3600, :summary => 'working'}]
698
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72,150").
699
- with(:body => {:unscheduled_maintenances => data}.to_json,
700
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
701
- to_return(:status => 204)
702
-
703
- result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, 150, data)
704
- req.should have_been_requested
705
- result.should_not be_nil
706
- result.should be_true
707
- end
708
-
709
- it "submits a POST request for multiple periods on several entities" do
710
- data = [{:duration => 3600, :summary => 'working'},
711
- {:duration => 3600, :summary => 'more work'}]
712
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72,150").
713
- with(:body => {:unscheduled_maintenances => data}.to_json,
714
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
715
- to_return(:status => 204)
716
-
717
- result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, 150, data)
718
- req.should have_been_requested
719
- result.should_not be_nil
720
- result.should be_true
721
- end
722
-
723
- end
724
-
725
- context 'test notifications' do
726
-
727
- it "submits a POST request for an entity" do
728
- req = stub_request(:post, "http://#{server}/test_notifications/entities/72").
729
- with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
730
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
731
- to_return(:status => 204)
732
-
733
- result = Flapjack::Diner.create_test_notifications_entities(72, [:summary => 'testing'])
734
- req.should have_been_requested
735
- result.should_not be_nil
736
- result.should be_true
737
- end
738
-
739
- it "submits a POST request for several entities" do
740
- req = stub_request(:post, "http://#{server}/test_notifications/entities/72,150").
741
- with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
742
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
743
- to_return(:status => 204)
744
-
745
- result = Flapjack::Diner.create_test_notifications_entities(72, 150, [:summary => 'testing'])
746
- req.should have_been_requested
747
- result.should_not be_nil
748
- result.should be_true
749
- end
750
-
751
- it "submits a POST request for multiple notifications on an entity" do
752
- data = [{:summary => 'testing'}, {:summary => 'another test'}]
753
- req = stub_request(:post, "http://#{server}/test_notifications/entities/72").
754
- with(:body => {:test_notifications => data}.to_json,
755
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
756
- to_return(:status => 204)
757
-
758
- result = Flapjack::Diner.create_test_notifications_entities(72, data)
759
- req.should have_been_requested
760
- result.should_not be_nil
761
- result.should be_true
762
- end
763
-
764
- it "submits a POST request for multiple notifications on several entities" do
765
- data = [{:summary => 'testing'}, {:summary => 'another test'}]
766
- req = stub_request(:post, "http://#{server}/test_notifications/entities/72,150").
767
- with(:body => {:test_notifications => data}.to_json,
768
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
769
- to_return(:status => 204)
770
-
771
- result = Flapjack::Diner.create_test_notifications_entities(72, 150, data)
772
- req.should have_been_requested
773
- result.should_not be_nil
774
- result.should be_true
775
- end
776
-
777
- end
778
-
779
- end
780
-
781
- context 'read' do
782
- it "submits a GET request for all entities" do
783
- req = stub_request(:get, "http://#{server}/entities").
784
- to_return(:body => response_with_data('entities'))
785
-
786
- result = Flapjack::Diner.entities
787
- req.should have_been_requested
788
- result.should_not be_nil
789
- end
790
-
791
- it "submits a GET request for one entity" do
792
- req = stub_request(:get, "http://#{server}/entities/72").
793
- to_return(:body => response_with_data('entities'))
794
-
795
- result = Flapjack::Diner.entities('72')
796
- req.should have_been_requested
797
- result.should_not be_nil
798
- end
799
-
800
- it "submits a GET request for several entities" do
801
- req = stub_request(:get, "http://#{server}/entities/72,150").
802
- to_return(:body => response_with_data('entities'))
803
-
804
- result = Flapjack::Diner.entities('72', '150')
805
- req.should have_been_requested
806
- result.should_not be_nil
807
- end
808
- end
809
-
810
- context 'update' do
811
-
812
- it "submits a PATCH request for an entity" do
813
- req = stub_request(:patch, "http://#{server}/entities/57").
814
- with(:body => [{:op => 'replace', :path => '/entities/0/name', :value => 'example3.com'}].to_json,
815
- :headers => {'Content-Type'=>'application/json-patch+json'}).
816
- to_return(:status => 204)
817
-
818
- result = Flapjack::Diner.update_entities('57', :name => 'example3.com')
819
- req.should have_been_requested
820
- result.should_not be_nil
821
- result.should be_true
822
- end
823
-
824
- it "submits a PATCH request for unscheduled maintenances on an entity" do
825
- req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/entities/72").
826
- with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
827
- :headers => {'Content-Type'=>'application/json-patch+json'}).
828
- to_return(:status => 204)
829
-
830
- result = Flapjack::Diner.update_unscheduled_maintenances_entities('72', :end_time => time)
831
- req.should have_been_requested
832
- result.should_not be_nil
833
- result.should be_true
834
- end
835
-
836
- it "submits a PATCH request for unscheduled maintenances on several entities" do
837
- req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/entities/72,150").
838
- with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
839
- :headers => {'Content-Type'=>'application/json-patch+json'}).
840
- to_return(:status => 204)
841
-
842
- result = Flapjack::Diner.update_unscheduled_maintenances_entities('72', '150', :end_time => time)
843
- req.should have_been_requested
844
- result.should_not be_nil
845
- result.should be_true
846
- end
847
-
848
- end
849
-
850
- context 'delete' do
851
-
852
- it "submits a DELETE request for scheduled maintenances on an entity" do
853
- req = stub_request(:delete, "http://#{server}/scheduled_maintenances/entities/72").
854
- with(:query => {:start_time => time.iso8601}).
855
- to_return(:status => 204)
856
-
857
- result = Flapjack::Diner.delete_scheduled_maintenances_entities('72', :start_time => time.iso8601)
858
- req.should have_been_requested
859
- result.should_not be_nil
860
- result.should be_true
861
- end
862
-
863
- it "submits a DELETE request for scheduled maintenances on several entities" do
864
- req = stub_request(:delete, "http://#{server}/scheduled_maintenances/entities/72,150").
865
- with(:query => {:start_time => time.iso8601}).
866
- to_return(:status => 204)
867
-
868
- result = Flapjack::Diner.delete_scheduled_maintenances_entities('72', '150', :start_time => time.iso8601)
869
- req.should have_been_requested
870
- result.should_not be_nil
871
- result.should be_true
872
- end
873
-
874
- end
875
-
876
- end
877
-
878
- context 'checks' do
879
- context 'create' do
880
-
881
- context 'scheduled maintenance periods' do
882
-
883
- it "submits a POST request on a check" do
884
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
885
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
886
- with(:body => {:scheduled_maintenances => data}.to_json,
887
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
888
- to_return(:status => 204)
889
-
890
- result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', data)
891
- req.should have_been_requested
892
- result.should_not be_nil
893
- result.should be_true
894
- end
895
-
896
- it "submits a POST request on several checks" do
897
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
898
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
899
- with(:body => {:scheduled_maintenances => data}.to_json,
900
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
901
- to_return(:status => 204)
902
-
903
- result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
904
- req.should have_been_requested
905
- result.should_not be_nil
906
- result.should be_true
907
- end
908
-
909
- it "submits a POST request for multiple periods on a check" do
910
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
911
- {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
912
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
913
- with(:body => {:scheduled_maintenances => data}.to_json,
914
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
915
- to_return(:status => 204)
916
-
917
- result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', data)
918
- req.should have_been_requested
919
- result.should_not be_nil
920
- result.should be_true
921
- end
922
-
923
- it "submits a POST request for multiple periods on several checks" do
924
- data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
925
- {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
926
- req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
927
- with(:body => {:scheduled_maintenances => data}.to_json,
928
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
929
- to_return(:status => 204)
930
-
931
- result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
932
- req.should have_been_requested
933
- result.should_not be_nil
934
- result.should be_true
935
- end
936
-
937
- end
938
-
939
- context 'unscheduled maintenance periods' do
940
-
941
- it "submits a POST request on a check" do
942
- data = [{:duration => 3600, :summary => 'working'}]
943
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH").
944
- with(:body => {:unscheduled_maintenances => data}.to_json,
945
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
946
- to_return(:status => 204)
947
-
948
- result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', data)
949
- req.should have_been_requested
950
- result.should_not be_nil
951
- result.should be_true
952
- end
953
-
954
- it "submits a POST request on several checks" do
955
- data = [{:duration => 3600, :summary => 'working'}]
956
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
957
- with(:body => {:unscheduled_maintenances => data}.to_json,
958
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
959
- to_return(:status => 204)
960
-
961
- result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
962
- req.should have_been_requested
963
- result.should_not be_nil
964
- result.should be_true
965
- end
966
-
967
- it "submits a POST request for multiple periods on several checks" do
968
- data = [{:duration => 3600, :summary => 'working'},
969
- {:duration => 3600, :summary => 'more work'}]
970
- req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
971
- with(:body => {:unscheduled_maintenances => data}.to_json,
972
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
973
- to_return(:status => 204)
974
-
975
- result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
976
- req.should have_been_requested
977
- result.should_not be_nil
978
- result.should be_true
979
- end
980
-
981
- end
982
-
983
- context 'test notifications' do
984
-
985
- it "submits a POST request for a check" do
986
- req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH").
987
- with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
988
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
989
- to_return(:status => 204)
990
-
991
- result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', [{:summary => 'testing'}])
992
- req.should have_been_requested
993
- result.should_not be_nil
994
- result.should be_true
995
- end
996
-
997
- it "submits a POST request for several checks" do
998
- req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH,example2.com%3APING").
999
- with(:test_notifications => [{:summary => 'testing'}]).
1000
- to_return(:status => 204)
1001
-
1002
- result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', 'example2.com:PING', [{:summary => 'testing'}])
1003
- req.should have_been_requested
1004
- result.should_not be_nil
1005
- result.should be_true
1006
- end
1007
-
1008
- it "submits a POST request for multiple notifications on a check" do
1009
- data = [{:summary => 'testing'}, {:summary => 'more testing'}]
1010
- req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH").
1011
- with(:body => {:test_notifications => data}.to_json,
1012
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
1013
- to_return(:status => 204)
1014
-
1015
- result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', data)
1016
- req.should have_been_requested
1017
- result.should_not be_nil
1018
- result.should be_true
1019
- end
1020
-
1021
- it "submits a POST request for multiple notifications on several checks" do
1022
- data = [{:summary => 'testing'}, {:summary => 'more testing'}]
1023
- req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH,example2.com%3APING").
1024
- with(:body => {:test_notifications => data}.to_json,
1025
- :headers => {'Content-Type'=>'application/vnd.api+json'}).
1026
- to_return(:status => 204)
1027
-
1028
- result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', 'example2.com:PING', data)
1029
- req.should have_been_requested
1030
- result.should_not be_nil
1031
- result.should be_true
1032
- end
1033
-
1034
- end
1035
-
1036
- end
1037
-
1038
- context 'read' do
1039
- it "submits a GET request for all checks" do
1040
- req = stub_request(:get, "http://#{server}/checks").
1041
- to_return(:body => response_with_data('checks'))
1042
-
1043
- result = Flapjack::Diner.checks
1044
- req.should have_been_requested
1045
- result.should_not be_nil
1046
- end
1047
-
1048
- it "submits a GET request for one check" do
1049
- req = stub_request(:get, "http://#{server}/checks/example.com%3ASSH").
1050
- to_return(:body => response_with_data('checks'))
1051
-
1052
- result = Flapjack::Diner.checks('example.com:SSH')
1053
- req.should have_been_requested
1054
- result.should_not be_nil
1055
- end
1056
-
1057
- it "submits a GET request for several checks" do
1058
- req = stub_request(:get, "http://#{server}/checks/example.com%3ASSH,example2.com%3APING").
1059
- to_return(:body => response_with_data('checks'))
1060
-
1061
- result = Flapjack::Diner.checks('example.com:SSH', 'example2.com:PING')
1062
- req.should have_been_requested
1063
- result.should_not be_nil
1064
- end
1065
- end
1066
-
1067
- context 'update' do
1068
-
1069
- it "submits a PATCH request for a check" do
1070
- req = stub_request(:patch, "http://#{server}/checks/www.example.com%3APING").
1071
- with(:body => [{:op => 'replace', :path => '/checks/0/enabled', :value => false}].to_json,
1072
- :headers => {'Content-Type'=>'application/json-patch+json'}).
1073
- to_return(:status => 204)
1074
-
1075
- result = Flapjack::Diner.update_checks('www.example.com:PING', :enabled => false)
1076
- req.should have_been_requested
1077
- result.should_not be_nil
1078
- result.should be_true
1079
- end
1080
-
1081
- it "submits a PATCH request for unscheduled maintenances on a check" do
1082
- req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH").
1083
- with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
1084
- :headers => {'Content-Type'=>'application/json-patch+json'}).
1085
- to_return(:status => 204)
1086
-
1087
- result = Flapjack::Diner.update_unscheduled_maintenances_checks('example.com:SSH', :end_time => time)
1088
- req.should have_been_requested
1089
- result.should_not be_nil
1090
- result.should be_true
1091
- end
1092
-
1093
- it "submits a PATCH request for unscheduled maintenances on several checks" do
1094
- req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
1095
- with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
1096
- :headers => {'Content-Type'=>'application/json-patch+json'}).
1097
- to_return(:status => 204)
1098
-
1099
- result = Flapjack::Diner.update_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', :end_time => time)
1100
- req.should have_been_requested
1101
- result.should_not be_nil
1102
- result.should be_true
1103
- end
1104
-
1105
- end
1106
-
1107
- context 'delete' do
1108
-
1109
- it "submits a DELETE request for scheduled maintenances on a check" do
1110
- req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
1111
- with(:query => {:start_time => time.iso8601}).
1112
- to_return(:status => 204)
1113
-
1114
- result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => time.iso8601)
1115
- req.should have_been_requested
1116
- result.should_not be_nil
1117
- result.should be_true
1118
- end
1119
-
1120
- it "submits a DELETE request for scheduled maintenances on a check with spaces in the name, percent-encoded" do
1121
- req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ADisk%20C%3A%20Utilisation").
1122
- with(:query => {:start_time => time.iso8601}).
1123
- to_return(:status => 204)
1124
-
1125
- result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:Disk C: Utilisation', :start_time => time.iso8601)
1126
- req.should have_been_requested
1127
- result.should_not be_nil
1128
- result.should be_true
1129
- end
1130
-
1131
- it "submits a DELETE request for scheduled maintenances on several checks" do
1132
- req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
1133
- with(:query => {:start_time => time.iso8601}).
1134
- to_return(:status => 204)
1135
-
1136
- result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', :start_time => time.iso8601)
1137
- req.should have_been_requested
1138
- result.should_not be_nil
1139
- result.should be_true
1140
- end
27
+ context 'keys as strings' do
1141
28
 
29
+ before do
30
+ Flapjack::Diner.return_keys_as_strings = true
31
+ end
32
+
33
+ after do
34
+ Flapjack::Diner.return_keys_as_strings = false
35
+ end
36
+
37
+ it 'can return keys as strings' do
38
+ data = [{
39
+ :id => '21',
40
+ :first_name => 'Ada',
41
+ :last_name => 'Lovelace',
42
+ :email => 'ada@example.com',
43
+ :timezone => 'Europe/London',
44
+ :tags => [ 'legend', 'first computer programmer' ],
45
+ :links => {
46
+ :entities => ['7', '12', '83'],
47
+ :media => ['21_email', '21_sms'],
48
+ :notification_rules => ['30fd36ae-3922-4957-ae3e-c8f6dd27e543']
49
+ }
50
+ }]
51
+
52
+ req = stub_request(:get, "http://#{server}/contacts").to_return(
53
+ :status => 200, :body => response_with_data('contacts', data))
54
+
55
+ result = Flapjack::Diner.contacts
56
+ expect(req).to have_been_requested
57
+ expect(result).not_to be_nil
58
+ expect(result).to be_an_instance_of(Array)
59
+ expect(result.length).to be(1)
60
+ expect(result[0]).to be_an_instance_of(Hash)
61
+ expect(result[0]).to have_key('id')
62
+ expect(result[0]).to have_key('links')
63
+ expect(result[0]['links']).to have_key('entities')
1142
64
  end
1143
- end
1144
-
1145
- context 'reports' do
1146
- context 'read' do
1147
-
1148
- ['status', 'scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
1149
-
1150
- it "submits a GET request for a #{report_type} report on all entities" do
1151
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities").
1152
- to_return(:body => response_with_data("#{report_type}_reports"))
1153
-
1154
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym)
1155
- req.should have_been_requested
1156
- result.should_not be_nil
1157
- end
1158
-
1159
- it "submits a GET request for a #{report_type} report on one entity" do
1160
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72").
1161
- to_return(:body => response_with_data("#{report_type}_reports"))
1162
-
1163
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '72')
1164
- req.should have_been_requested
1165
- result.should_not be_nil
1166
- end
1167
-
1168
- it "submits a GET request for a #{report_type} report on several entities" do
1169
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72,150").
1170
- to_return(:body => response_with_data("#{report_type}_reports"))
1171
-
1172
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '72', '150')
1173
- req.should have_been_requested
1174
- result.should_not be_nil
1175
- end
1176
-
1177
- it "submits a GET request for a #{report_type} report on all checks" do
1178
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks").
1179
- to_return(:body => response_with_data("#{report_type}_reports"))
1180
-
1181
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym)
1182
- req.should have_been_requested
1183
- result.should_not be_nil
1184
- end
1185
-
1186
- it "submits a GET request for a #{report_type} report on one check" do
1187
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH").
1188
- to_return(:body => response_with_data("#{report_type}_reports"))
1189
-
1190
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
1191
- 'example.com:SSH')
1192
- req.should have_been_requested
1193
- result.should_not be_nil
1194
- end
1195
-
1196
- it "submits a GET request for a #{report_type} report on several checks" do
1197
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH,example2.com%3APING").
1198
- to_return(:body => response_with_data("#{report_type}_reports"))
1199
-
1200
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
1201
- 'example.com:SSH', 'example2.com:PING')
1202
- req.should have_been_requested
1203
- result.should_not be_nil
1204
- end
1205
-
1206
- end
1207
65
 
1208
- ['scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
1209
-
1210
- let(:start_time) { Time.now }
1211
- let(:end_time) { start_time + (60 * 60 * 12) }
1212
-
1213
- it "submits a time-limited GET request for a #{report_type} report on all entities" do
1214
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities").
1215
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1216
- to_return(:body => response_with_data("#{report_type}_reports"))
1217
-
1218
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
1219
- :start_time => start_time, :end_time => end_time)
1220
- req.should have_been_requested
1221
- result.should_not be_nil
1222
- end
1223
-
1224
- it "submits a time-limited GET request for a #{report_type} report on one entity" do
1225
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72").
1226
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1227
- to_return(:body => response_with_data("#{report_type}_reports"))
1228
-
1229
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
1230
- '72', :start_time => start_time, :end_time => end_time)
1231
- req.should have_been_requested
1232
- result.should_not be_nil
1233
- end
1234
-
1235
- it "submits a time-limited GET request for a #{report_type} report on several entities" do
1236
- req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72,150").
1237
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1238
- to_return(:body => response_with_data("#{report_type}_reports"))
1239
-
1240
- result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
1241
- '72', '150', :start_time => start_time, :end_time => end_time)
1242
- req.should have_been_requested
1243
- result.should_not be_nil
1244
- end
1245
-
1246
- it "submits a time-limited GET request for a #{report_type} report on all checks" do
1247
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks").
1248
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1249
- to_return(:body => response_with_data("#{report_type}_reports"))
1250
-
1251
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
1252
- :start_time => start_time, :end_time => end_time)
1253
- req.should have_been_requested
1254
- result.should_not be_nil
1255
- end
1256
-
1257
- it "submits a time-limited GET request for a #{report_type} report on one check" do
1258
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH").
1259
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1260
- to_return(:body => response_with_data("#{report_type}_reports"))
1261
-
1262
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
1263
- 'example.com:SSH', :start_time => start_time, :end_time => end_time)
1264
- req.should have_been_requested
1265
- result.should_not be_nil
1266
- end
1267
-
1268
- it "submits a time-limited GET request for a #{report_type} report on several checks" do
1269
- req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH,example2.com%3APING").
1270
- with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
1271
- to_return(:body => response_with_data("#{report_type}_reports"))
1272
-
1273
- result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
1274
- 'example.com:SSH', 'example2.com:PING',
1275
- :start_time => start_time, :end_time => end_time)
1276
- req.should have_been_requested
1277
- result.should_not be_nil
1278
- end
1279
-
1280
- end
1281
-
1282
- end
1283
66
  end
1284
67
 
1285
- context "logging" do
68
+ context 'logging' do
1286
69
 
1287
70
  let(:logger) { double('logger') }
1288
71
 
@@ -1290,30 +73,30 @@ describe Flapjack::Diner do
1290
73
  Flapjack::Diner.logger = logger
1291
74
  end
1292
75
 
1293
- it "logs a GET request without a path" do
76
+ it 'logs a GET request without a path' do
1294
77
  response = response_with_data('entities')
1295
78
  req = stub_request(:get, "http://#{server}/entities").
1296
79
  to_return(:body => response)
1297
80
 
1298
- logger.should_receive(:info).with("GET http://#{server}/entities")
1299
- logger.should_receive(:info).with(" Response Code: 200")
1300
- logger.should_receive(:info).with(" Response Body: #{response}")
81
+ expect(logger).to receive(:info).with("GET http://#{server}/entities")
82
+ expect(logger).to receive(:info).with(' Response Code: 200')
83
+ expect(logger).to receive(:info).with(" Response Body: #{response}")
1301
84
 
1302
85
  result = Flapjack::Diner.entities
1303
- req.should have_been_requested
1304
- result.should_not be_nil
86
+ expect(req).to have_been_requested
87
+ expect(result).not_to be_nil
1305
88
  end
1306
89
 
1307
90
  it "logs a POST request" do
1308
91
  req = stub_request(:post, "http://#{server}/test_notifications/entities/27").
1309
- to_return(:status => 200)
1310
- logger.should_receive(:info).with("POST http://#{server}/test_notifications/entities/27\n" +
1311
- " Params: {:test_notifications=>[{:summary=>\"dealing with it\"}]}")
1312
- logger.should_receive(:info).with(" Response Code: 200")
92
+ to_return(:status => 204)
93
+ expect(logger).to receive(:info).with("POST http://#{server}/test_notifications/entities/27\n" +
94
+ " Body: {:test_notifications=>[{:summary=>\"dealing with it\"}]}")
95
+ expect(logger).to receive(:info).with(' Response Code: 204')
1313
96
 
1314
97
  result = Flapjack::Diner.create_test_notifications_entities(27, [{:summary => 'dealing with it'}])
1315
- req.should have_been_requested
1316
- result.should be_true
98
+ expect(req).to have_been_requested
99
+ expect(result).to be_truthy
1317
100
  end
1318
101
 
1319
102
  it "logs a DELETE request" do
@@ -1321,12 +104,12 @@ describe Flapjack::Diner do
1321
104
  with(:query => {:start_time => time.iso8601}).
1322
105
  to_return(:status => 204)
1323
106
 
1324
- logger.should_receive(:info).with("DELETE http://#{server}/scheduled_maintenances/checks/example.com:SSH?start_time=#{URI.encode_www_form_component(time.iso8601)}")
1325
- logger.should_receive(:info).with(" Response Code: 204")
107
+ expect(logger).to receive(:info).with("DELETE http://#{server}/scheduled_maintenances/checks/example.com:SSH?start_time=#{URI.encode_www_form_component(time.iso8601)}")
108
+ expect(logger).to receive(:info).with(" Response Code: 204")
1326
109
 
1327
110
  result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => time)
1328
- req.should have_been_requested
1329
- result.should be_true
111
+ expect(req).to have_been_requested
112
+ expect(result).to be_truthy
1330
113
  end
1331
114
 
1332
115
  end
@@ -1339,7 +122,7 @@ describe Flapjack::Diner do
1339
122
  expect {
1340
123
  Flapjack::Diner.entities
1341
124
  }.to raise_error
1342
- req.should have_been_requested
125
+ expect(req).to have_been_requested
1343
126
  end
1344
127
 
1345
128
  it "raises an exception on invalid JSON data" do
@@ -1349,7 +132,7 @@ describe Flapjack::Diner do
1349
132
  expect {
1350
133
  Flapjack::Diner.entities
1351
134
  }.to raise_error
1352
- req.should have_been_requested
135
+ expect(req).to have_been_requested
1353
136
  end
1354
137
 
1355
138
  it "raises an exception if a required argument is not provided" do
@@ -1358,7 +141,7 @@ describe Flapjack::Diner do
1358
141
  expect {
1359
142
  Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => nil)
1360
143
  }.to raise_error
1361
- req.should_not have_been_requested
144
+ expect(req).not_to have_been_requested
1362
145
  end
1363
146
 
1364
147
  it "raises an exception if a time argument is provided with the wrong data type" do
@@ -1373,7 +156,7 @@ describe Flapjack::Diner do
1373
156
  Flapjack::Diner.downtime_report_checks('example.com:SSH',
1374
157
  :start_time => start_time, :end_time => end_time)
1375
158
  }.to raise_error
1376
- req.should_not have_been_requested
159
+ expect(req).not_to have_been_requested
1377
160
  end
1378
161
 
1379
162
  end