ibm_watson 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,643 +3,645 @@
3
3
  require_relative("./../test_helper.rb")
4
4
  SimpleCov.command_name "test:integration"
5
5
 
6
- # Integration tests for the Watson Assistant V1 Service
7
- class AssistantV1Test < Minitest::Test
8
- def test_create_update_delete_workspace
9
- service = IBMWatson::AssistantV1.new(
10
- username: ENV["ASSISTANT_USERNAME"],
11
- password: ENV["ASSISTANT_PASSWORD"],
12
- version: "2018-02-16"
13
- )
14
- service.add_default_headers(
15
- headers: {
16
- "X-Watson-Learning-Opt-Out" => "1",
17
- "X-Watson-Test" => "1"
18
- }
19
- )
20
- service_response = service.create_workspace(
21
- name: "Pizza app",
22
- description: "Pizza app",
23
- language: "en",
24
- metadata: {}
25
- )
26
- workspace_id = service_response.result["workspace_id"]
27
- assert((200..299).cover?(service_response.status))
28
-
29
- service_response = service.update_workspace(
30
- workspace_id: workspace_id,
31
- name: "Pizza app",
32
- description: "Pizza app",
33
- language: "en",
34
- metadata: {}
35
- )
36
- assert((200..299).cover?(service_response.status))
37
-
38
- service_response = service.delete_workspace(
39
- workspace_id: workspace_id
40
- )
41
- assert(service_response.nil?)
42
- end
43
-
44
- def test_get_workspace
45
- service = IBMWatson::AssistantV1.new(
46
- username: ENV["ASSISTANT_USERNAME"],
47
- password: ENV["ASSISTANT_PASSWORD"],
48
- version: "2018-02-16"
49
- )
50
- service.add_default_headers(
51
- headers: {
52
- "X-Watson-Learning-Opt-Out" => "1",
53
- "X-Watson-Test" => "1"
54
- }
55
- )
56
- service_response = service.get_workspace(
57
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
58
- export: false
59
- )
60
- assert((200..299).cover?(service_response.status))
61
- end
62
-
63
- def test_list_workspaces
64
- service = IBMWatson::AssistantV1.new(
65
- username: ENV["ASSISTANT_USERNAME"],
66
- password: ENV["ASSISTANT_PASSWORD"],
67
- version: "2018-02-16"
68
- )
69
- service.add_default_headers(
70
- headers: {
71
- "X-Watson-Learning-Opt-Out" => "1",
72
- "X-Watson-Test" => "1"
73
- }
74
- )
75
- service_response = service.list_workspaces
76
- assert((200..299).cover?(service_response.status))
77
- end
78
-
79
- def test_create_update_delete_counterexample
80
- service = IBMWatson::AssistantV1.new(
81
- version: "2018-02-16",
82
- username: ENV["ASSISTANT_USERNAME"],
83
- password: ENV["ASSISTANT_PASSWORD"]
84
- )
85
- service.add_default_headers(
86
- headers: {
87
- "X-Watson-Learning-Opt-Out" => "1",
88
- "X-Watson-Test" => "1"
89
- }
90
- )
91
- service_response = service.create_counterexample(
92
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
93
- text: "I want a large pizza please."
94
- )
95
- assert((200..299).cover?(service_response.status))
96
-
97
- service_response = service.update_counterexample(
98
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
99
- text: "I want a large pizza please.",
100
- new_text: "I want a large pizza please."
101
- )
102
- assert((200..299).cover?(service_response.status))
103
-
104
- service_response = service.delete_counterexample(
105
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
106
- text: "I want a large pizza please."
107
- )
108
- assert(service_response.nil?)
109
- end
110
-
111
- def test_get_counterexample
112
- service = IBMWatson::AssistantV1.new(
113
- username: ENV["ASSISTANT_USERNAME"],
114
- password: ENV["ASSISTANT_PASSWORD"],
115
- version: "2018-02-16"
116
- )
117
- service.add_default_headers(
118
- headers: {
119
- "X-Watson-Learning-Opt-Out" => "1",
120
- "X-Watson-Test" => "1"
121
- }
122
- )
123
- service_response = service.get_counterexample(
124
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
125
- text: "what is your nickname"
126
- )
127
- assert((200..299).cover?(service_response.status))
128
- end
129
-
130
- def test_list_counterexamples
131
- service = IBMWatson::AssistantV1.new(
132
- username: ENV["ASSISTANT_USERNAME"],
133
- password: ENV["ASSISTANT_PASSWORD"],
134
- version: "2018-02-16"
135
- )
136
- service.add_default_headers(
137
- headers: {
138
- "X-Watson-Learning-Opt-Out" => "1",
139
- "X-Watson-Test" => "1"
140
- }
141
- )
142
- service_response = service.list_counterexamples(
143
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
144
- )
145
- assert((200..299).cover?(service_response.status))
146
- end
147
-
148
- def test_create_update_delete_entity
149
- service = IBMWatson::AssistantV1.new(
150
- username: ENV["ASSISTANT_USERNAME"],
151
- password: ENV["ASSISTANT_PASSWORD"],
152
- version: "2018-02-16"
153
- )
154
- service.add_default_headers(
155
- headers: {
156
- "X-Watson-Learning-Opt-Out" => "1",
157
- "X-Watson-Test" => "1"
158
- }
159
- )
160
- service_response = service.create_entity(
161
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
162
- entity: "pizza_toppings",
163
- description: "Tasty pizza toppings",
164
- metadata: { "property" => "value" },
165
- values: nil,
166
- fuzzy_match: nil
167
- )
168
- assert((200..299).cover?(service_response.status))
169
-
170
- service_response = service.update_entity(
171
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
172
- entity: "pizza_toppings",
173
- new_entity: "pizza_toppings"
174
- )
175
- assert((200..299).cover?(service_response.status))
176
-
177
- service_response = service.delete_entity(
178
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
179
- entity: "pizza_toppings"
180
- )
181
- assert(service_response.nil?)
182
- end
183
-
184
- def test_get_entity
185
- service = IBMWatson::AssistantV1.new(
186
- username: ENV["ASSISTANT_USERNAME"],
187
- password: ENV["ASSISTANT_PASSWORD"],
188
- version: "2018-02-16"
189
- )
190
- service.add_default_headers(
191
- headers: {
192
- "X-Watson-Learning-Opt-Out" => "1",
193
- "X-Watson-Test" => "1"
194
- }
195
- )
196
- service_response = service.get_entity(
197
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
198
- entity: "holiday",
199
- export: true
200
- )
201
- assert((200..299).cover?(service_response.status))
202
- end
203
-
204
- def test_list_entities
205
- service = IBMWatson::AssistantV1.new(
206
- username: ENV["ASSISTANT_USERNAME"],
207
- password: ENV["ASSISTANT_PASSWORD"],
208
- version: "2018-02-16"
209
- )
210
- service.add_default_headers(
211
- headers: {
212
- "X-Watson-Learning-Opt-Out" => "1",
213
- "X-Watson-Test" => "1"
214
- }
215
- )
216
- service_response = service.list_entities(
217
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
218
- export: true
219
- )
220
- assert((200..299).cover?(service_response.status))
221
- end
222
-
223
- def test_create_update_delete_example
224
- service = IBMWatson::AssistantV1.new(
225
- username: ENV["ASSISTANT_USERNAME"],
226
- password: ENV["ASSISTANT_PASSWORD"],
227
- version: "2018-02-16"
228
- )
229
- service.add_default_headers(
230
- headers: {
231
- "X-Watson-Learning-Opt-Out" => "1",
232
- "X-Watson-Test" => "1"
233
- }
234
- )
235
- service_response = service.create_example(
236
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
237
- intent: "Cancel",
238
- text: "Gimme a pizza with pepperoni"
239
- )
240
- assert((200..299).cover?(service_response.status))
241
-
242
- service_response = service.update_example(
243
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
244
- intent: "Cancel",
245
- text: "Gimme a pizza with pepperoni",
246
- new_text: "Gimme a pizza with pepperoni"
247
- )
248
- assert((200..299).cover?(service_response.status))
249
-
250
- service_response = service.delete_example(
251
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
252
- intent: "Cancel",
253
- text: "Gimme a pizza with pepperoni"
254
- )
255
- assert(service_response.nil?)
256
- end
257
-
258
- def test_get_example
259
- service = IBMWatson::AssistantV1.new(
260
- username: ENV["ASSISTANT_USERNAME"],
261
- password: ENV["ASSISTANT_PASSWORD"],
262
- version: "2018-02-16"
263
- )
264
- service.add_default_headers(
265
- headers: {
266
- "X-Watson-Learning-Opt-Out" => "1",
267
- "X-Watson-Test" => "1"
268
- }
269
- )
270
- service_response = service.get_example(
271
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
272
- intent: "Cancel",
273
- text: "forget it"
274
- )
275
- assert((200..299).cover?(service_response.status))
276
- end
277
-
278
- def test_list_examples
279
- service = IBMWatson::AssistantV1.new(
280
- username: ENV["ASSISTANT_USERNAME"],
281
- password: ENV["ASSISTANT_PASSWORD"],
282
- version: "2018-02-16"
283
- )
284
- service.add_default_headers(
285
- headers: {
286
- "X-Watson-Learning-Opt-Out" => "1",
287
- "X-Watson-Test" => "1"
288
- }
289
- )
290
- service_response = service.list_examples(
291
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
292
- intent: "Cancel"
293
- )
294
- assert((200..299).cover?(service_response.status))
295
- end
296
-
297
- def test_create_update_delete_intent
298
- service = IBMWatson::AssistantV1.new(
299
- username: ENV["ASSISTANT_USERNAME"],
300
- password: ENV["ASSISTANT_PASSWORD"],
301
- version: "2018-02-16"
302
- )
303
- service.add_default_headers(
304
- headers: {
305
- "X-Watson-Learning-Opt-Out" => "1",
306
- "X-Watson-Test" => "1"
307
- }
308
- )
309
- service_response = service.create_intent(
310
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
311
- intent: "pizza_order",
312
- description: "User wants to start a new pizza order"
313
- )
314
- assert((200..299).cover?(service_response.status))
315
-
316
- service_response = service.update_intent(
317
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
318
- intent: "pizza_order",
319
- new_intent: "pizza_order",
320
- new_description: "User wants to start a new pizza order"
321
- )
322
- assert((200..299).cover?(service_response.status))
323
-
324
- service_response = service.delete_intent(
325
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
326
- intent: "pizza_order"
327
- )
328
- assert(service_response.nil?)
329
- end
330
-
331
- def test_get_intent
332
- service = IBMWatson::AssistantV1.new(
333
- username: ENV["ASSISTANT_USERNAME"],
334
- password: ENV["ASSISTANT_PASSWORD"],
335
- version: "2018-02-16"
336
- )
337
- service.add_default_headers(
338
- headers: {
339
- "X-Watson-Learning-Opt-Out" => "1",
340
- "X-Watson-Test" => "1"
341
- }
342
- )
343
- service_response = service.get_intent(
344
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
345
- intent: "Cancel",
346
- export: false
347
- )
348
- assert((200..299).cover?(service_response.status))
349
- end
350
-
351
- def test_list_intents
352
- service = IBMWatson::AssistantV1.new(
353
- username: ENV["ASSISTANT_USERNAME"],
354
- password: ENV["ASSISTANT_PASSWORD"],
355
- version: "2018-02-16"
356
- )
357
- service.add_default_headers(
358
- headers: {
359
- "X-Watson-Learning-Opt-Out" => "1",
360
- "X-Watson-Test" => "1"
361
- }
362
- )
363
- service_response = service.list_intents(
364
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
365
- export: false
366
- )
367
- assert((200..299).cover?(service_response.status))
368
- end
369
-
370
- def test_list_logs
371
- service = IBMWatson::AssistantV1.new(
372
- username: ENV["ASSISTANT_USERNAME"],
373
- password: ENV["ASSISTANT_PASSWORD"],
374
- version: "2018-02-16"
375
- )
376
- service.add_default_headers(
377
- headers: {
378
- "X-Watson-Learning-Opt-Out" => "1",
379
- "X-Watson-Test" => "1"
380
- }
381
- )
382
- service_response = service.list_logs(
383
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
384
- )
385
- assert((200..299).cover?(service_response.status))
386
- end
387
-
388
- def test_list_all_logs
389
- service = IBMWatson::AssistantV1.new(
390
- username: ENV["ASSISTANT_USERNAME"],
391
- password: ENV["ASSISTANT_PASSWORD"],
392
- version: "2018-02-16"
393
- )
394
- service.add_default_headers(
395
- headers: {
396
- "X-Watson-Learning-Opt-Out" => "1",
397
- "X-Watson-Test" => "1"
398
- }
399
- )
400
- service_response = service.list_all_logs(
401
- filter: "language::en,request.context.metadata.deployment::deployment_1"
402
- )
403
- assert((200..299).cover?(service_response.status))
404
- end
405
-
406
- def test_message
407
- service = IBMWatson::AssistantV1.new(
408
- username: ENV["ASSISTANT_USERNAME"],
409
- password: ENV["ASSISTANT_PASSWORD"],
410
- version: "2018-02-16"
411
- )
412
- service.add_default_headers(
413
- headers: {
414
- "X-Watson-Learning-Opt-Out" => "1",
415
- "X-Watson-Test" => "1"
416
- }
417
- )
418
- service_response = service.message(
419
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
420
- input: { "text" => "Turn on the lights" },
421
- context: nil
422
- )
423
- assert((200..299).cover?(service_response.status))
424
-
425
- context = service_response.result["context"]
426
- service_response = service.message(
427
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
428
- input: { "text" => "Turn on the lights" },
429
- context: context
430
- )
431
- assert((200..299).cover?(service_response.status))
432
- end
433
-
434
- def test_create_update_delete_synonym
435
- service = IBMWatson::AssistantV1.new(
436
- username: ENV["ASSISTANT_USERNAME"],
437
- password: ENV["ASSISTANT_PASSWORD"],
438
- version: "2018-02-16"
439
- )
440
- service.add_default_headers(
441
- headers: {
442
- "X-Watson-Learning-Opt-Out" => "1",
443
- "X-Watson-Test" => "1"
444
- }
445
- )
446
- service_response = service.create_synonym(
447
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
448
- entity: "holiday",
449
- value: "labor day",
450
- synonym: "a"
451
- )
452
- assert((200..299).cover?(service_response.status))
453
-
454
- service_response = service.update_synonym(
455
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
456
- entity: "holiday",
457
- value: "labor day",
458
- synonym: "a",
459
- new_synonym: "a"
460
- )
461
- assert((200..299).cover?(service_response.status))
462
-
463
- service_response = service.delete_synonym(
464
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
465
- entity: "holiday",
466
- value: "labor day",
467
- synonym: "a"
468
- )
469
- assert(service_response.nil?)
470
- end
471
-
472
- def test_get_synonym
473
- service = IBMWatson::AssistantV1.new(
474
- username: ENV["ASSISTANT_USERNAME"],
475
- password: ENV["ASSISTANT_PASSWORD"],
476
- version: "2018-02-16"
477
- )
478
- service.add_default_headers(
479
- headers: {
480
- "X-Watson-Learning-Opt-Out" => "1",
481
- "X-Watson-Test" => "1"
482
- }
483
- )
484
- service_response = service.get_synonym(
485
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
486
- entity: "holiday",
487
- value: "thanksgiving",
488
- synonym: "turkey day"
489
- )
490
- assert((200..299).cover?(service_response.status))
491
- end
492
-
493
- def test_list_synonyms
494
- service = IBMWatson::AssistantV1.new(
495
- username: ENV["ASSISTANT_USERNAME"],
496
- password: ENV["ASSISTANT_PASSWORD"],
497
- version: "2018-02-16"
498
- )
499
- service.add_default_headers(
500
- headers: {
501
- "X-Watson-Learning-Opt-Out" => "1",
502
- "X-Watson-Test" => "1"
503
- }
504
- )
505
- service_response = service.list_synonyms(
506
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
507
- entity: "holiday",
508
- value: "new years eve"
509
- )
510
- assert((200..299).cover?(service_response.status))
511
- end
512
-
513
- def test_create_update_delete_value
514
- service = IBMWatson::AssistantV1.new(
515
- username: ENV["ASSISTANT_USERNAME"],
516
- password: ENV["ASSISTANT_PASSWORD"],
517
- version: "2018-02-16"
518
- )
519
- service.add_default_headers(
520
- headers: {
521
- "X-Watson-Learning-Opt-Out" => "1",
522
- "X-Watson-Test" => "1"
523
- }
524
- )
525
- service_response = service.create_value(
526
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
527
- entity: "holiday",
528
- value: "aeiou"
529
- )
530
- assert((200..299).cover?(service_response.status))
531
-
532
- service_response = service.update_value(
533
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
534
- entity: "holiday",
535
- value: "aeiou",
536
- new_value: "BBQ sauce",
537
- new_metadata: { "code" => 1422 },
538
- new_synonyms: nil
539
- )
540
- assert((200..299).cover?(service_response.status))
541
-
542
- service_response = service.delete_value(
543
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
544
- entity: "holiday",
545
- value: "BBQ sauce"
546
- )
547
- assert(service_response.nil?)
548
- end
549
-
550
- def test_get_value
551
- service = IBMWatson::AssistantV1.new(
552
- username: ENV["ASSISTANT_USERNAME"],
553
- password: ENV["ASSISTANT_PASSWORD"],
554
- version: "2018-02-16"
555
- )
556
- service.add_default_headers(
557
- headers: {
558
- "X-Watson-Learning-Opt-Out" => "1",
559
- "X-Watson-Test" => "1"
560
- }
561
- )
562
- service_response = service.get_value(
563
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
564
- entity: "holiday",
565
- value: "christmas",
566
- export: true
567
- )
568
- assert((200..299).cover?(service_response.status))
569
- end
570
-
571
- def test_list_values
572
- service = IBMWatson::AssistantV1.new(
573
- username: ENV["ASSISTANT_USERNAME"],
574
- password: ENV["ASSISTANT_PASSWORD"],
575
- version: "2018-02-16"
576
- )
577
- service.add_default_headers(
578
- headers: {
579
- "X-Watson-Learning-Opt-Out" => "1",
580
- "X-Watson-Test" => "1"
581
- }
582
- )
583
- service_response = service.list_values(
584
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
585
- entity: "holiday",
586
- export: true
587
- )
588
- assert((200..299).cover?(service_response.status))
589
- end
590
-
591
- def test_dialog_nodes
592
- service = IBMWatson::AssistantV1.new(
593
- username: ENV["ASSISTANT_USERNAME"],
594
- password: ENV["ASSISTANT_PASSWORD"],
595
- version: "2018-02-16"
596
- )
597
- service.add_default_headers(
598
- headers: {
599
- "X-Watson-Learning-Opt-Out" => "1",
600
- "X-Watson-Test" => "1"
601
- }
602
- )
603
-
604
- service_response = service.create_dialog_node(
605
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
606
- dialog_node: "location-done"
607
- )
608
- assert((200..299).cover?(service_response.status))
609
-
610
- service_response = service.delete_dialog_node(
611
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
612
- dialog_node: "location-done"
613
- )
614
- assert(service_response.nil?)
615
-
616
- service_response = service.get_dialog_node(
617
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
618
- dialog_node: "Hours of Operation"
619
- )
620
- assert((200..299).cover?(service_response.status))
621
-
622
- service_response = service.list_dialog_nodes(
623
- workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
624
- )
625
- assert((200..299).cover?(service_response.status))
626
- end
627
-
628
- def test_delete_user_data
629
- service = IBMWatson::AssistantV1.new(
630
- username: ENV["ASSISTANT_USERNAME"],
631
- password: ENV["ASSISTANT_PASSWORD"],
632
- version: "2018-02-16"
633
- )
634
- service.add_default_headers(
635
- headers: {
636
- "X-Watson-Learning-Opt-Out" => "1",
637
- "X-Watson-Test" => "1"
638
- }
639
- )
640
- service_response = service.delete_user_data(
641
- customer_id: "id"
642
- )
643
- assert(service_response.nil?)
6
+ unless ENV["ASSISTANT_USERNAME"].nil? || ENV["ASSISTANT_PASSWORD"].nil?
7
+ # Integration tests for the Watson Assistant V1 Service
8
+ class AssistantV1Test < Minitest::Test
9
+ def test_create_update_delete_workspace
10
+ service = IBMWatson::AssistantV1.new(
11
+ username: ENV["ASSISTANT_USERNAME"],
12
+ password: ENV["ASSISTANT_PASSWORD"],
13
+ version: "2018-02-16"
14
+ )
15
+ service.add_default_headers(
16
+ headers: {
17
+ "X-Watson-Learning-Opt-Out" => "1",
18
+ "X-Watson-Test" => "1"
19
+ }
20
+ )
21
+ service_response = service.create_workspace(
22
+ name: "Pizza app",
23
+ description: "Pizza app",
24
+ language: "en",
25
+ metadata: {}
26
+ )
27
+ workspace_id = service_response.result["workspace_id"]
28
+ assert((200..299).cover?(service_response.status))
29
+
30
+ service_response = service.update_workspace(
31
+ workspace_id: workspace_id,
32
+ name: "Pizza app",
33
+ description: "Pizza app",
34
+ language: "en",
35
+ metadata: {}
36
+ )
37
+ assert((200..299).cover?(service_response.status))
38
+
39
+ service_response = service.delete_workspace(
40
+ workspace_id: workspace_id
41
+ )
42
+ assert(service_response.nil?)
43
+ end
44
+
45
+ def test_get_workspace
46
+ service = IBMWatson::AssistantV1.new(
47
+ username: ENV["ASSISTANT_USERNAME"],
48
+ password: ENV["ASSISTANT_PASSWORD"],
49
+ version: "2018-02-16"
50
+ )
51
+ service.add_default_headers(
52
+ headers: {
53
+ "X-Watson-Learning-Opt-Out" => "1",
54
+ "X-Watson-Test" => "1"
55
+ }
56
+ )
57
+ service_response = service.get_workspace(
58
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
59
+ export: false
60
+ )
61
+ assert((200..299).cover?(service_response.status))
62
+ end
63
+
64
+ def test_list_workspaces
65
+ service = IBMWatson::AssistantV1.new(
66
+ username: ENV["ASSISTANT_USERNAME"],
67
+ password: ENV["ASSISTANT_PASSWORD"],
68
+ version: "2018-02-16"
69
+ )
70
+ service.add_default_headers(
71
+ headers: {
72
+ "X-Watson-Learning-Opt-Out" => "1",
73
+ "X-Watson-Test" => "1"
74
+ }
75
+ )
76
+ service_response = service.list_workspaces
77
+ assert((200..299).cover?(service_response.status))
78
+ end
79
+
80
+ def test_create_update_delete_counterexample
81
+ service = IBMWatson::AssistantV1.new(
82
+ version: "2018-02-16",
83
+ username: ENV["ASSISTANT_USERNAME"],
84
+ password: ENV["ASSISTANT_PASSWORD"]
85
+ )
86
+ service.add_default_headers(
87
+ headers: {
88
+ "X-Watson-Learning-Opt-Out" => "1",
89
+ "X-Watson-Test" => "1"
90
+ }
91
+ )
92
+ service_response = service.create_counterexample(
93
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
94
+ text: "I want a large pizza please."
95
+ )
96
+ assert((200..299).cover?(service_response.status))
97
+
98
+ service_response = service.update_counterexample(
99
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
100
+ text: "I want a large pizza please.",
101
+ new_text: "I want a large pizza please."
102
+ )
103
+ assert((200..299).cover?(service_response.status))
104
+
105
+ service_response = service.delete_counterexample(
106
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
107
+ text: "I want a large pizza please."
108
+ )
109
+ assert(service_response.nil?)
110
+ end
111
+
112
+ def test_get_counterexample
113
+ service = IBMWatson::AssistantV1.new(
114
+ username: ENV["ASSISTANT_USERNAME"],
115
+ password: ENV["ASSISTANT_PASSWORD"],
116
+ version: "2018-02-16"
117
+ )
118
+ service.add_default_headers(
119
+ headers: {
120
+ "X-Watson-Learning-Opt-Out" => "1",
121
+ "X-Watson-Test" => "1"
122
+ }
123
+ )
124
+ service_response = service.get_counterexample(
125
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
126
+ text: "what is your nickname"
127
+ )
128
+ assert((200..299).cover?(service_response.status))
129
+ end
130
+
131
+ def test_list_counterexamples
132
+ service = IBMWatson::AssistantV1.new(
133
+ username: ENV["ASSISTANT_USERNAME"],
134
+ password: ENV["ASSISTANT_PASSWORD"],
135
+ version: "2018-02-16"
136
+ )
137
+ service.add_default_headers(
138
+ headers: {
139
+ "X-Watson-Learning-Opt-Out" => "1",
140
+ "X-Watson-Test" => "1"
141
+ }
142
+ )
143
+ service_response = service.list_counterexamples(
144
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
145
+ )
146
+ assert((200..299).cover?(service_response.status))
147
+ end
148
+
149
+ def test_create_update_delete_entity
150
+ service = IBMWatson::AssistantV1.new(
151
+ username: ENV["ASSISTANT_USERNAME"],
152
+ password: ENV["ASSISTANT_PASSWORD"],
153
+ version: "2018-02-16"
154
+ )
155
+ service.add_default_headers(
156
+ headers: {
157
+ "X-Watson-Learning-Opt-Out" => "1",
158
+ "X-Watson-Test" => "1"
159
+ }
160
+ )
161
+ service_response = service.create_entity(
162
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
163
+ entity: "pizza_toppings",
164
+ description: "Tasty pizza toppings",
165
+ metadata: { "property" => "value" },
166
+ values: nil,
167
+ fuzzy_match: nil
168
+ )
169
+ assert((200..299).cover?(service_response.status))
170
+
171
+ service_response = service.update_entity(
172
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
173
+ entity: "pizza_toppings",
174
+ new_entity: "pizza_toppings"
175
+ )
176
+ assert((200..299).cover?(service_response.status))
177
+
178
+ service_response = service.delete_entity(
179
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
180
+ entity: "pizza_toppings"
181
+ )
182
+ assert(service_response.nil?)
183
+ end
184
+
185
+ def test_get_entity
186
+ service = IBMWatson::AssistantV1.new(
187
+ username: ENV["ASSISTANT_USERNAME"],
188
+ password: ENV["ASSISTANT_PASSWORD"],
189
+ version: "2018-02-16"
190
+ )
191
+ service.add_default_headers(
192
+ headers: {
193
+ "X-Watson-Learning-Opt-Out" => "1",
194
+ "X-Watson-Test" => "1"
195
+ }
196
+ )
197
+ service_response = service.get_entity(
198
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
199
+ entity: "holiday",
200
+ export: true
201
+ )
202
+ assert((200..299).cover?(service_response.status))
203
+ end
204
+
205
+ def test_list_entities
206
+ service = IBMWatson::AssistantV1.new(
207
+ username: ENV["ASSISTANT_USERNAME"],
208
+ password: ENV["ASSISTANT_PASSWORD"],
209
+ version: "2018-02-16"
210
+ )
211
+ service.add_default_headers(
212
+ headers: {
213
+ "X-Watson-Learning-Opt-Out" => "1",
214
+ "X-Watson-Test" => "1"
215
+ }
216
+ )
217
+ service_response = service.list_entities(
218
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
219
+ export: true
220
+ )
221
+ assert((200..299).cover?(service_response.status))
222
+ end
223
+
224
+ def test_create_update_delete_example
225
+ service = IBMWatson::AssistantV1.new(
226
+ username: ENV["ASSISTANT_USERNAME"],
227
+ password: ENV["ASSISTANT_PASSWORD"],
228
+ version: "2018-02-16"
229
+ )
230
+ service.add_default_headers(
231
+ headers: {
232
+ "X-Watson-Learning-Opt-Out" => "1",
233
+ "X-Watson-Test" => "1"
234
+ }
235
+ )
236
+ service_response = service.create_example(
237
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
238
+ intent: "Cancel",
239
+ text: "Gimme a pizza with pepperoni"
240
+ )
241
+ assert((200..299).cover?(service_response.status))
242
+
243
+ service_response = service.update_example(
244
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
245
+ intent: "Cancel",
246
+ text: "Gimme a pizza with pepperoni",
247
+ new_text: "Gimme a pizza with pepperoni"
248
+ )
249
+ assert((200..299).cover?(service_response.status))
250
+
251
+ service_response = service.delete_example(
252
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
253
+ intent: "Cancel",
254
+ text: "Gimme a pizza with pepperoni"
255
+ )
256
+ assert(service_response.nil?)
257
+ end
258
+
259
+ def test_get_example
260
+ service = IBMWatson::AssistantV1.new(
261
+ username: ENV["ASSISTANT_USERNAME"],
262
+ password: ENV["ASSISTANT_PASSWORD"],
263
+ version: "2018-02-16"
264
+ )
265
+ service.add_default_headers(
266
+ headers: {
267
+ "X-Watson-Learning-Opt-Out" => "1",
268
+ "X-Watson-Test" => "1"
269
+ }
270
+ )
271
+ service_response = service.get_example(
272
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
273
+ intent: "Cancel",
274
+ text: "forget it"
275
+ )
276
+ assert((200..299).cover?(service_response.status))
277
+ end
278
+
279
+ def test_list_examples
280
+ service = IBMWatson::AssistantV1.new(
281
+ username: ENV["ASSISTANT_USERNAME"],
282
+ password: ENV["ASSISTANT_PASSWORD"],
283
+ version: "2018-02-16"
284
+ )
285
+ service.add_default_headers(
286
+ headers: {
287
+ "X-Watson-Learning-Opt-Out" => "1",
288
+ "X-Watson-Test" => "1"
289
+ }
290
+ )
291
+ service_response = service.list_examples(
292
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
293
+ intent: "Cancel"
294
+ )
295
+ assert((200..299).cover?(service_response.status))
296
+ end
297
+
298
+ def test_create_update_delete_intent
299
+ service = IBMWatson::AssistantV1.new(
300
+ username: ENV["ASSISTANT_USERNAME"],
301
+ password: ENV["ASSISTANT_PASSWORD"],
302
+ version: "2018-02-16"
303
+ )
304
+ service.add_default_headers(
305
+ headers: {
306
+ "X-Watson-Learning-Opt-Out" => "1",
307
+ "X-Watson-Test" => "1"
308
+ }
309
+ )
310
+ service_response = service.create_intent(
311
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
312
+ intent: "pizza_order",
313
+ description: "User wants to start a new pizza order"
314
+ )
315
+ assert((200..299).cover?(service_response.status))
316
+
317
+ service_response = service.update_intent(
318
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
319
+ intent: "pizza_order",
320
+ new_intent: "pizza_order",
321
+ new_description: "User wants to start a new pizza order"
322
+ )
323
+ assert((200..299).cover?(service_response.status))
324
+
325
+ service_response = service.delete_intent(
326
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
327
+ intent: "pizza_order"
328
+ )
329
+ assert(service_response.nil?)
330
+ end
331
+
332
+ def test_get_intent
333
+ service = IBMWatson::AssistantV1.new(
334
+ username: ENV["ASSISTANT_USERNAME"],
335
+ password: ENV["ASSISTANT_PASSWORD"],
336
+ version: "2018-02-16"
337
+ )
338
+ service.add_default_headers(
339
+ headers: {
340
+ "X-Watson-Learning-Opt-Out" => "1",
341
+ "X-Watson-Test" => "1"
342
+ }
343
+ )
344
+ service_response = service.get_intent(
345
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
346
+ intent: "Cancel",
347
+ export: false
348
+ )
349
+ assert((200..299).cover?(service_response.status))
350
+ end
351
+
352
+ def test_list_intents
353
+ service = IBMWatson::AssistantV1.new(
354
+ username: ENV["ASSISTANT_USERNAME"],
355
+ password: ENV["ASSISTANT_PASSWORD"],
356
+ version: "2018-02-16"
357
+ )
358
+ service.add_default_headers(
359
+ headers: {
360
+ "X-Watson-Learning-Opt-Out" => "1",
361
+ "X-Watson-Test" => "1"
362
+ }
363
+ )
364
+ service_response = service.list_intents(
365
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
366
+ export: false
367
+ )
368
+ assert((200..299).cover?(service_response.status))
369
+ end
370
+
371
+ def test_list_logs
372
+ service = IBMWatson::AssistantV1.new(
373
+ username: ENV["ASSISTANT_USERNAME"],
374
+ password: ENV["ASSISTANT_PASSWORD"],
375
+ version: "2018-02-16"
376
+ )
377
+ service.add_default_headers(
378
+ headers: {
379
+ "X-Watson-Learning-Opt-Out" => "1",
380
+ "X-Watson-Test" => "1"
381
+ }
382
+ )
383
+ service_response = service.list_logs(
384
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
385
+ )
386
+ assert((200..299).cover?(service_response.status))
387
+ end
388
+
389
+ def test_list_all_logs
390
+ service = IBMWatson::AssistantV1.new(
391
+ username: ENV["ASSISTANT_USERNAME"],
392
+ password: ENV["ASSISTANT_PASSWORD"],
393
+ version: "2018-02-16"
394
+ )
395
+ service.add_default_headers(
396
+ headers: {
397
+ "X-Watson-Learning-Opt-Out" => "1",
398
+ "X-Watson-Test" => "1"
399
+ }
400
+ )
401
+ service_response = service.list_all_logs(
402
+ filter: "language::en,request.context.metadata.deployment::deployment_1"
403
+ )
404
+ assert((200..299).cover?(service_response.status))
405
+ end
406
+
407
+ def test_message
408
+ service = IBMWatson::AssistantV1.new(
409
+ username: ENV["ASSISTANT_USERNAME"],
410
+ password: ENV["ASSISTANT_PASSWORD"],
411
+ version: "2018-02-16"
412
+ )
413
+ service.add_default_headers(
414
+ headers: {
415
+ "X-Watson-Learning-Opt-Out" => "1",
416
+ "X-Watson-Test" => "1"
417
+ }
418
+ )
419
+ service_response = service.message(
420
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
421
+ input: { "text" => "Turn on the lights" },
422
+ context: nil
423
+ )
424
+ assert((200..299).cover?(service_response.status))
425
+
426
+ context = service_response.result["context"]
427
+ service_response = service.message(
428
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
429
+ input: { "text" => "Turn on the lights" },
430
+ context: context
431
+ )
432
+ assert((200..299).cover?(service_response.status))
433
+ end
434
+
435
+ def test_create_update_delete_synonym
436
+ service = IBMWatson::AssistantV1.new(
437
+ username: ENV["ASSISTANT_USERNAME"],
438
+ password: ENV["ASSISTANT_PASSWORD"],
439
+ version: "2018-02-16"
440
+ )
441
+ service.add_default_headers(
442
+ headers: {
443
+ "X-Watson-Learning-Opt-Out" => "1",
444
+ "X-Watson-Test" => "1"
445
+ }
446
+ )
447
+ service_response = service.create_synonym(
448
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
449
+ entity: "holiday",
450
+ value: "labor day",
451
+ synonym: "a"
452
+ )
453
+ assert((200..299).cover?(service_response.status))
454
+
455
+ service_response = service.update_synonym(
456
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
457
+ entity: "holiday",
458
+ value: "labor day",
459
+ synonym: "a",
460
+ new_synonym: "a"
461
+ )
462
+ assert((200..299).cover?(service_response.status))
463
+
464
+ service_response = service.delete_synonym(
465
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
466
+ entity: "holiday",
467
+ value: "labor day",
468
+ synonym: "a"
469
+ )
470
+ assert(service_response.nil?)
471
+ end
472
+
473
+ def test_get_synonym
474
+ service = IBMWatson::AssistantV1.new(
475
+ username: ENV["ASSISTANT_USERNAME"],
476
+ password: ENV["ASSISTANT_PASSWORD"],
477
+ version: "2018-02-16"
478
+ )
479
+ service.add_default_headers(
480
+ headers: {
481
+ "X-Watson-Learning-Opt-Out" => "1",
482
+ "X-Watson-Test" => "1"
483
+ }
484
+ )
485
+ service_response = service.get_synonym(
486
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
487
+ entity: "holiday",
488
+ value: "thanksgiving",
489
+ synonym: "turkey day"
490
+ )
491
+ assert((200..299).cover?(service_response.status))
492
+ end
493
+
494
+ def test_list_synonyms
495
+ service = IBMWatson::AssistantV1.new(
496
+ username: ENV["ASSISTANT_USERNAME"],
497
+ password: ENV["ASSISTANT_PASSWORD"],
498
+ version: "2018-02-16"
499
+ )
500
+ service.add_default_headers(
501
+ headers: {
502
+ "X-Watson-Learning-Opt-Out" => "1",
503
+ "X-Watson-Test" => "1"
504
+ }
505
+ )
506
+ service_response = service.list_synonyms(
507
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
508
+ entity: "holiday",
509
+ value: "new years eve"
510
+ )
511
+ assert((200..299).cover?(service_response.status))
512
+ end
513
+
514
+ def test_create_update_delete_value
515
+ service = IBMWatson::AssistantV1.new(
516
+ username: ENV["ASSISTANT_USERNAME"],
517
+ password: ENV["ASSISTANT_PASSWORD"],
518
+ version: "2018-02-16"
519
+ )
520
+ service.add_default_headers(
521
+ headers: {
522
+ "X-Watson-Learning-Opt-Out" => "1",
523
+ "X-Watson-Test" => "1"
524
+ }
525
+ )
526
+ service_response = service.create_value(
527
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
528
+ entity: "holiday",
529
+ value: "aeiou"
530
+ )
531
+ assert((200..299).cover?(service_response.status))
532
+
533
+ service_response = service.update_value(
534
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
535
+ entity: "holiday",
536
+ value: "aeiou",
537
+ new_value: "BBQ sauce",
538
+ new_metadata: { "code" => 1422 },
539
+ new_synonyms: nil
540
+ )
541
+ assert((200..299).cover?(service_response.status))
542
+
543
+ service_response = service.delete_value(
544
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
545
+ entity: "holiday",
546
+ value: "BBQ sauce"
547
+ )
548
+ assert(service_response.nil?)
549
+ end
550
+
551
+ def test_get_value
552
+ service = IBMWatson::AssistantV1.new(
553
+ username: ENV["ASSISTANT_USERNAME"],
554
+ password: ENV["ASSISTANT_PASSWORD"],
555
+ version: "2018-02-16"
556
+ )
557
+ service.add_default_headers(
558
+ headers: {
559
+ "X-Watson-Learning-Opt-Out" => "1",
560
+ "X-Watson-Test" => "1"
561
+ }
562
+ )
563
+ service_response = service.get_value(
564
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
565
+ entity: "holiday",
566
+ value: "christmas",
567
+ export: true
568
+ )
569
+ assert((200..299).cover?(service_response.status))
570
+ end
571
+
572
+ def test_list_values
573
+ service = IBMWatson::AssistantV1.new(
574
+ username: ENV["ASSISTANT_USERNAME"],
575
+ password: ENV["ASSISTANT_PASSWORD"],
576
+ version: "2018-02-16"
577
+ )
578
+ service.add_default_headers(
579
+ headers: {
580
+ "X-Watson-Learning-Opt-Out" => "1",
581
+ "X-Watson-Test" => "1"
582
+ }
583
+ )
584
+ service_response = service.list_values(
585
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
586
+ entity: "holiday",
587
+ export: true
588
+ )
589
+ assert((200..299).cover?(service_response.status))
590
+ end
591
+
592
+ def test_dialog_nodes
593
+ service = IBMWatson::AssistantV1.new(
594
+ username: ENV["ASSISTANT_USERNAME"],
595
+ password: ENV["ASSISTANT_PASSWORD"],
596
+ version: "2018-02-16"
597
+ )
598
+ service.add_default_headers(
599
+ headers: {
600
+ "X-Watson-Learning-Opt-Out" => "1",
601
+ "X-Watson-Test" => "1"
602
+ }
603
+ )
604
+
605
+ service_response = service.create_dialog_node(
606
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
607
+ dialog_node: "location-done"
608
+ )
609
+ assert((200..299).cover?(service_response.status))
610
+
611
+ service_response = service.delete_dialog_node(
612
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
613
+ dialog_node: "location-done"
614
+ )
615
+ assert(service_response.nil?)
616
+
617
+ service_response = service.get_dialog_node(
618
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
619
+ dialog_node: "Hours of Operation"
620
+ )
621
+ assert((200..299).cover?(service_response.status))
622
+
623
+ service_response = service.list_dialog_nodes(
624
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
625
+ )
626
+ assert((200..299).cover?(service_response.status))
627
+ end
628
+
629
+ def test_delete_user_data
630
+ service = IBMWatson::AssistantV1.new(
631
+ username: ENV["ASSISTANT_USERNAME"],
632
+ password: ENV["ASSISTANT_PASSWORD"],
633
+ version: "2018-02-16"
634
+ )
635
+ service.add_default_headers(
636
+ headers: {
637
+ "X-Watson-Learning-Opt-Out" => "1",
638
+ "X-Watson-Test" => "1"
639
+ }
640
+ )
641
+ service_response = service.delete_user_data(
642
+ customer_id: "id"
643
+ )
644
+ assert(service_response.nil?)
645
+ end
644
646
  end
645
647
  end