osvc_ruby 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ require 'core/spec_helper'
2
+
3
+ describe OSvCRuby::Client do
4
+ subject { client }
5
+
6
+ context '#initialize' do
7
+
8
+ it 'should require a block' do
9
+ expect { OSvCRuby::Client.new }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ it 'should raise exception if interface is blank' do
13
+ expect do
14
+ OSvCRuby::Client.new do |config|
15
+ config.interface = ''
16
+ end
17
+ end.to raise_error("Interface cannot be nil or blank")
18
+ end
19
+
20
+ it 'should raise exception if username is blank' do
21
+ expect do
22
+ OSvCRuby::Client.new do |config|
23
+ config.interface = 'test'
24
+ config.username = ''
25
+ end
26
+ end.to raise_error("Username cannot be nil or blank")
27
+ end
28
+
29
+ it 'should raise exception if password is blank' do
30
+ expect do
31
+ OSvCRuby::Client.new do |config|
32
+ config.interface = 'test'
33
+ config.username = 'test_username'
34
+ config.password = ''
35
+ end
36
+ end.to raise_error("Password cannot be nil or blank")
37
+ end
38
+
39
+ it 'should raise exception if no_ssl_verify not a TrueClass nor a FalseClass' do
40
+ expect do
41
+ OSvCRuby::Client.new do |config|
42
+ config.interface = 'test'
43
+ config.username = 'test_username'
44
+ config.password = 'password'
45
+ config.no_ssl_verify = 'true'
46
+ end
47
+ end.to raise_error("The no SSL verification setting must be set to true or false")
48
+ end
49
+
50
+ it 'should raise exception if Connect Version is null' do
51
+ expect do
52
+ OSvCRuby::Client.new do |config|
53
+ config.interface = 'test'
54
+ config.username = 'test_username'
55
+ config.password = 'password'
56
+ config.version = nil
57
+ end
58
+ end.to raise_error("Connect version cannot be null")
59
+ end
60
+
61
+ let(:client){
62
+ OSvCRuby::Client.new do |config|
63
+ config.interface = 'test'
64
+ config.username = 'test_username'
65
+ config.password = 'test_password'
66
+ config.no_ssl_verify = true
67
+ end
68
+ }
69
+
70
+ it 'should create a configuration object' do
71
+
72
+ expect{client}.to_not raise_error
73
+
74
+ end
75
+
76
+ it 'should have interface set to "test" and not "test1"' do
77
+ expect(client.config.interface).to eq('test')
78
+ expect(client.config.interface).not_to eq('test1')
79
+ end
80
+
81
+ it 'should have username set to "test_username" and not "test1_username"' do
82
+ expect(client.config.username).to eq('test_username')
83
+ expect(client.config.username).not_to eq('test1_username')
84
+ end
85
+
86
+ it 'should have password set to "test_password" and not "test1_password"' do
87
+ expect(client.config.password).to eq('test_password')
88
+ expect(client.config.password).not_to eq('test1_password')
89
+ end
90
+
91
+ it 'should have no_ssl set to true and not false' do
92
+ expect(client.config.no_ssl_verify).to eq(true)
93
+ expect(client.config.no_ssl_verify).not_to eq(false)
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ require 'core/spec_helper'
2
+
3
+ describe OSvCRuby::Configuration do
4
+ subject { OSvCRuby::Configuration.new }
5
+ end
@@ -0,0 +1,463 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSvCRuby::Connect do
6
+
7
+ subject { connect }
8
+
9
+ let(:client) {
10
+
11
+ OSvCRuby::Client.new do |config|
12
+
13
+ config.interface = ENV['OSC_SITE']
14
+
15
+ config.username = ENV['OSC_ADMIN']
16
+
17
+ config.password = ENV['OSC_PASSWORD']
18
+
19
+ config.suppress_rules = true
20
+
21
+ config.demo_site = true
22
+
23
+ end
24
+ }
25
+
26
+
27
+ context '#generate_url_and_config' do
28
+
29
+ it 'should take at least a config parameter that is an instance of an OSvCRuby::Client' do
30
+
31
+ expect(client).to be_an(OSvCRuby::Client)
32
+
33
+ expect do
34
+
35
+ OSvCRuby::Connect.generate_url_and_config(client)
36
+
37
+ end.not_to raise_error
38
+ end
39
+
40
+ it 'should take an optional resource_url parameter' do
41
+
42
+ expect do
43
+
44
+ OSvCRuby::Connect.generate_url_and_config(client, 'serviceProducts')
45
+
46
+ end.not_to raise_error
47
+ end
48
+
49
+ it 'should change the final configured url if the resource_url parameter is specified' do
50
+
51
+ test = OSvCRuby::Connect.generate_url_and_config(client, 'serviceProducts')
52
+
53
+ interface = client.config.interface
54
+ if test['site_url'].to_s.match(/custhelp/)
55
+ demo_or_cust = "custhelp"
56
+ else
57
+ demo_or_cust = "rightnowdemo"
58
+ end
59
+ expect(test['site_url']).to eq(URI("https://#{interface}.#{demo_or_cust}.com/services/rest/connect/v1.3/serviceProducts"))
60
+
61
+ expect(test['site_url']).to be_an(URI::HTTPS)
62
+ end
63
+
64
+ it 'should raise an error if client is nil' do
65
+
66
+ expect do
67
+
68
+ client = nil
69
+
70
+ OSvCRuby::Connect.generate_url_and_config(client)
71
+
72
+ end.to raise_error("Client must have some configuration set; please create an instance of OSvCRuby::Client with configuration settings")
73
+
74
+ end
75
+
76
+ it 'should raise an error if client.config is nil' do
77
+
78
+ expect do
79
+
80
+ client.config = nil
81
+
82
+ OSvCRuby::Connect.generate_url_and_config(client)
83
+
84
+ end.to raise_error("Client configuration cannot be nil or blank")
85
+
86
+ end
87
+
88
+ it 'should raise an error if client interface is absent' do
89
+
90
+ expect do
91
+
92
+ client.config.interface = nil
93
+
94
+ OSvCRuby::Connect.generate_url_and_config(client)
95
+
96
+ end.to raise_error("The configured client interface cannot be nil or blank")
97
+
98
+ end
99
+
100
+ it 'should raise an error if client username is absent' do
101
+
102
+ expect do
103
+
104
+ client.config.username = nil
105
+
106
+ OSvCRuby::Connect.generate_url_and_config(client)
107
+
108
+ end.to raise_error("The configured client username cannot be nil or blank")
109
+
110
+ end
111
+
112
+ it 'should raise an error if client password is absent' do
113
+
114
+ expect do
115
+
116
+ client.config.password = nil
117
+
118
+ OSvCRuby::Connect.generate_url_and_config(client)
119
+
120
+ end.to raise_error("The configured client password cannot be nil or blank")
121
+
122
+ end
123
+
124
+
125
+ it 'should create an Hash object with a site_url, username, password properties' do
126
+
127
+ final_config = OSvCRuby::Connect.generate_url_and_config(client)
128
+
129
+ expect(final_config).to be_an(Hash)
130
+
131
+ expect(final_config['site_url']).to be_an(URI::HTTPS)
132
+
133
+ expect(final_config['username']).to eq(ENV['OSC_ADMIN'])
134
+
135
+ expect(final_config['password']).to eq(ENV['OSC_PASSWORD'])
136
+
137
+ end
138
+
139
+ end
140
+
141
+ let(:json_content){
142
+ {:test => 'content'}
143
+ }
144
+
145
+ context '#post_or_patch' do
146
+
147
+ it 'should take at least a config parameter that is an instance of an OSvCRuby::Client', :vcr do
148
+
149
+ expect(client).to be_an(OSvCRuby::Client)
150
+
151
+ expect do
152
+
153
+ OSvCRuby::Connect.post_or_patch(client,'serviceProducts',json_content)
154
+
155
+ end.not_to raise_error
156
+ end
157
+
158
+ it 'should raise an error if client is nil' do
159
+
160
+ expect do
161
+
162
+ client = nil
163
+
164
+ OSvCRuby::Connect.post_or_patch(client,'serviceProducts',json_content)
165
+
166
+ end.to raise_error("Client must have some configuration set; please create an instance of OSvCRuby::Client with configuration settings")
167
+
168
+ end
169
+
170
+ it 'should raise an error if resource_url is nil' do
171
+
172
+ expect do
173
+
174
+ OSvCRuby::Connect.post_or_patch(client, nil, json_content)
175
+
176
+ end.to raise_error("There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to")
177
+
178
+ end
179
+
180
+ it 'should raise an error if json_content is nil' do
181
+
182
+ expect do
183
+
184
+ OSvCRuby::Connect.post_or_patch(client,'serviceProducts')
185
+
186
+ end.to raise_error("There is no json content provided; please specify json content that you would like to send a POST or PATCH request with")
187
+
188
+ end
189
+
190
+ it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body', :vcr do
191
+
192
+ names = []
193
+
194
+ names[0] = {:labelText => 'PRODUCT-TEST', :language => {:id => 1}}
195
+ # names[1] = {:labelText => 'PRODUCT-TEST', :language => {:id => 11}}
196
+
197
+ # parent = {:id => 102}
198
+
199
+ displayOrder = {:id => 4}
200
+
201
+ admin_user_visible_interfaces = []
202
+ admin_user_visible_interfaces[0] = {:id => 1}
203
+
204
+ end_user_visible_interfaces = []
205
+ end_user_visible_interfaces[0] = {:id => 1}
206
+
207
+ new_prod = []
208
+ new_prod[0] = {:names => names,
209
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
210
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
211
+
212
+ test = OSvCRuby::Connect.post_or_patch(client,'serviceProducts',new_prod[0])
213
+
214
+ expect(test).to be_an(Net::HTTPResponse)
215
+
216
+ expect(test.code).to eq("201")
217
+
218
+ expect(test.body).to be_an(String)
219
+
220
+ expect{JSON.parse(test.body)}.not_to raise_error
221
+
222
+ end
223
+
224
+ end
225
+
226
+ context '#post' do
227
+
228
+ it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body', :vcr do
229
+
230
+ names = []
231
+
232
+ names[0] = {:labelText => 'PRODUCT-TEST', :language => {:id => 1}}
233
+ # names[1] = {:labelText => 'PRODUCT-TEST', :language => {:id => 11}}
234
+
235
+ # parent = {:id => 102}
236
+
237
+ displayOrder = {:id => 4}
238
+
239
+ admin_user_visible_interfaces = []
240
+ admin_user_visible_interfaces[0] = {:id => 1}
241
+
242
+ end_user_visible_interfaces = []
243
+ end_user_visible_interfaces[0] = {:id => 1}
244
+
245
+ new_prod = []
246
+ new_prod[0] = {:names => names,
247
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
248
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
249
+
250
+ test = OSvCRuby::Connect.post(client,'serviceProducts',new_prod[0])
251
+
252
+ expect(test).to be_an(Net::HTTPResponse)
253
+
254
+ expect(test.code).to eq("201")
255
+
256
+ expect(test.body).to be_an(String)
257
+
258
+ expect{JSON.parse(test.body)}.not_to raise_error
259
+
260
+ end
261
+
262
+ end
263
+
264
+ context '#patch' do
265
+
266
+ it 'should make a patch request', :vcr do
267
+
268
+ resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST';")
269
+
270
+ product_test = OSvCRuby::Connect.get(client,resource)
271
+
272
+ prod_json = JSON.parse(product_test.body).to_hash
273
+
274
+ product_test_id = prod_json['items'][0]['rows'][0][0].to_i
275
+
276
+ names = []
277
+
278
+ names[0] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 1}}
279
+ # names[1] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 11}}
280
+
281
+ # parent = {:id => 102}
282
+
283
+ displayOrder = {:id => 4}
284
+
285
+ admin_user_visible_interfaces = []
286
+ admin_user_visible_interfaces[0] = {:id => 1}
287
+
288
+ end_user_visible_interfaces = []
289
+ end_user_visible_interfaces[0] = {:id => 1}
290
+
291
+ new_prod = []
292
+ new_prod[0] = {:names => names,
293
+ # :parent => parent,
294
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
295
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
296
+
297
+ test = OSvCRuby::Connect.patch(client,"serviceProducts/#{product_test_id}",new_prod[0])
298
+
299
+ expect(test).to be_an(Net::HTTPResponse)
300
+
301
+ expect(test.body).to eq("")
302
+
303
+ expect(test.code).to eq("200")
304
+
305
+ end
306
+
307
+ end
308
+
309
+
310
+
311
+
312
+ context '#get' do
313
+
314
+ it 'should take at least a config parameter that is an instance of an OSvCRuby::Client', :vcr do
315
+
316
+ expect(client).to be_an(OSvCRuby::Client)
317
+
318
+ expect do
319
+
320
+ OSvCRuby::Connect.get(client)
321
+
322
+ end.not_to raise_error
323
+ end
324
+
325
+
326
+ it 'should raise an error if client is nil' do
327
+
328
+ expect do
329
+
330
+ client = nil
331
+
332
+ OSvCRuby::Connect.get(client)
333
+
334
+ end.to raise_error("Client must have some configuration set; please create an instance of OSvCRuby::Client with configuration settings")
335
+
336
+ end
337
+
338
+ it 'should produce a Net::HTTPResponse', :vcr do
339
+
340
+ test = OSvCRuby::Connect.get(client)
341
+
342
+ expect(test).to be_an(Net::HTTPResponse)
343
+
344
+ end
345
+
346
+ it 'should produce a 200 response code', :vcr do
347
+
348
+ test = OSvCRuby::Connect.get(client)
349
+
350
+ expect(test.code).to eq("200")
351
+
352
+ end
353
+
354
+ it 'should produce a JSON Response from the response body', :vcr do
355
+
356
+ test = OSvCRuby::Connect.get(client)
357
+
358
+ expect(test.body).to be_an(String)
359
+
360
+ expect{JSON.parse(test.body)}.not_to raise_error
361
+ end
362
+
363
+ it 'should bring back a list of service products when specified',:vcr do
364
+ res = OSvCRuby::Connect.get(client,'/serviceProducts?limit=3')
365
+
366
+ expect(res.body).to be_an(String)
367
+ end
368
+
369
+ end
370
+
371
+
372
+ context '#post_or_patch' do
373
+
374
+ it 'should take an optional parameter to allow PATCH request; it should produce a Net::HTTPResponse, should produce a 200 code', :vcr do
375
+
376
+ resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST';")
377
+
378
+ product_test = OSvCRuby::Connect.get(client,resource)
379
+
380
+ prod_json = JSON.parse(product_test.body).to_hash
381
+
382
+ product_test_id = prod_json['items'][0]['rows'][0][0].to_i
383
+
384
+ names = []
385
+
386
+ names[0] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 1}}
387
+ # names[1] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 11}}
388
+
389
+ # parent = {:id => 102}
390
+
391
+ displayOrder = {:id => 4}
392
+
393
+ admin_user_visible_interfaces = []
394
+ admin_user_visible_interfaces[0] = {:id => 1}
395
+
396
+ end_user_visible_interfaces = []
397
+ end_user_visible_interfaces[0] = {:id => 1}
398
+
399
+ new_prod = []
400
+ new_prod[0] = {:names => names,
401
+ # :parent => parent,
402
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
403
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
404
+
405
+ test = OSvCRuby::Connect.post_or_patch(client,"serviceProducts/#{product_test_id}",new_prod[0],true)
406
+
407
+ expect(test).to be_an(Net::HTTPResponse)
408
+
409
+ expect(test.body).to eq("")
410
+
411
+ expect(test.code).to eq("200")
412
+
413
+
414
+ end
415
+
416
+ end
417
+
418
+ context '#delete' do
419
+
420
+ it 'should raise an error if client is nil' do
421
+
422
+ expect do
423
+
424
+ client = nil
425
+
426
+ OSvCRuby::Connect.delete(client)
427
+
428
+ end.to raise_error("Client must have some configuration set; please create an instance of OSvCRuby::Client with configuration settings")
429
+
430
+ end
431
+
432
+ it 'should raise an error if the resource_url is not specified' do
433
+
434
+ expect do
435
+
436
+ OSvCRuby::Connect.delete(client)
437
+
438
+ end.to raise_error("There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to")
439
+
440
+ end
441
+
442
+ it 'it should produce a Net::HTTPResponse, should produce a 200 code', :vcr do
443
+
444
+ q = OSvCRuby::QueryResults.new
445
+ query = "select id from serviceproducts where lookupname = 'PRODUCT-TEST-updated';"
446
+
447
+ product_test_updated = q.query(client,query)
448
+
449
+ test = OSvCRuby::Connect.delete(client,"serviceProducts/#{product_test_updated[0]['id']}")
450
+
451
+ expect(test).to be_an(Net::HTTPResponse)
452
+
453
+ expect(test.body).to eq("")
454
+
455
+ expect(test.code).to eq("200")
456
+
457
+ end
458
+
459
+
460
+
461
+ end
462
+
463
+ end
@@ -0,0 +1,107 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSvCRuby::QueryResultsSet do
6
+
7
+ let(:client) {
8
+
9
+ OSvCRuby::Client.new do |config|
10
+
11
+ config.interface = ENV['OSC_SITE']
12
+
13
+ config.username = ENV['OSC_ADMIN']
14
+
15
+ config.password = ENV['OSC_PASSWORD']
16
+
17
+ config.demo_site = true
18
+
19
+ end
20
+ }
21
+
22
+ let(:query_results_set){
23
+ OSvCRuby::QueryResultsSet.new
24
+ }
25
+
26
+ let(:table){ "answers" }
27
+ let(:nested_attributes){
28
+ [
29
+ "accessLevels.namedIDList.*",
30
+ "answerType.*",
31
+ "assignedTo.account.*",
32
+ "assignedTo.staffGroup.*",
33
+ "banner.*",
34
+ "banner.importanceFlag.*",
35
+ "banner.updatedByAccount.*",
36
+ "categories.categoriesList.*",
37
+ "commonAttachments.fileAttachmentList.*",
38
+ "commonAttachments.fileAttachmentList.names.labelList.labelText",
39
+ "commonAttachments.fileAttachmentList.names.labelList.language.*",
40
+ "fileAttachments.fileAttachmentList.*",
41
+ "guidedAssistance.*",
42
+ "language.*",
43
+ "notes.noteList.*",
44
+ "positionInList.*",
45
+ "products.productsList.*",
46
+ "relatedAnswers.answerRelatedAnswerList.*",
47
+ "relatedAnswers.answerRelatedAnswerList.toAnswer.*",
48
+ "siblingAnswers.*",
49
+ "statusWithType.statusType.*",
50
+ "updatedByAccount.*",
51
+ "customFields.c.*"
52
+ ]
53
+ }
54
+
55
+
56
+ context "#query_set" do
57
+
58
+ it 'should expect client is an instance of OSvCRuby::Client class and raise an error if does not' do
59
+
60
+ expect(client).to be_an(OSvCRuby::Client)
61
+
62
+ client = nil
63
+
64
+ expect{query_results_set.query_set(client,'describe')}.to raise_error('Client must have some configuration set; please create an instance of OSvCRuby::Client with configuration settings')
65
+
66
+ end
67
+
68
+
69
+ ## TO DO
70
+
71
+ # it 'should expect a hash with a key and query value set' do
72
+
73
+ # expect(client).to be_an(OSvCRuby::Client)
74
+
75
+ # expect{query_results_set.query_set(client,"")}.to raise_error("A query must be specified when using the 'query' method")
76
+
77
+ # end
78
+
79
+
80
+ it 'should return results in set of OSvCRuby::QueryResults',:vcr do
81
+
82
+ expect(query_results_set.query_set(client,{key:"answers", query:"select * from answers LIMIT 2"},
83
+ {key:"incidents", query:"describe incidents"})).to be_a(Struct)
84
+
85
+
86
+ end
87
+
88
+ it 'should be able to manipulate and assign results data',:vcr do
89
+
90
+ test = query_results_set.query_set(client, {key:"incidents", query:"select * from incidents limit 10"},
91
+ {key:"serviceCategories", query:"describe serviceCategories"})
92
+ expect(test.incidents).to be_an(Array)
93
+ expect(test.incidents.first).to be_a(Hash)
94
+ expect(test.incidents.first['id']).to be_a(Integer)
95
+ expect(test.serviceCategories).to be_an(Array)
96
+
97
+
98
+ end
99
+
100
+ it 'should be able to take multiple queries', :vcr do
101
+ answer_attrs = nested_attributes.map { |attr| {key: attr, query: "SELECT #{attr} FROM #{table} WHERE ID = 1"} }
102
+ test = query_results_set.query_set(client,*answer_attrs)
103
+ end
104
+
105
+ end
106
+
107
+ end