ibm_watson 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +258 -0
  3. data/bin/console +14 -0
  4. data/bin/setup +8 -0
  5. data/lib/ibm_watson.rb +16 -0
  6. data/lib/ibm_watson/assistant_v1.rb +1997 -0
  7. data/lib/ibm_watson/detailed_response.rb +21 -0
  8. data/lib/ibm_watson/discovery_v1.rb +2039 -0
  9. data/lib/ibm_watson/iam_token_manager.rb +166 -0
  10. data/lib/ibm_watson/language_translator_v3.rb +411 -0
  11. data/lib/ibm_watson/natural_language_classifier_v1.rb +309 -0
  12. data/lib/ibm_watson/natural_language_understanding_v1.rb +297 -0
  13. data/lib/ibm_watson/personality_insights_v3.rb +260 -0
  14. data/lib/ibm_watson/speech_to_text_v1.rb +2153 -0
  15. data/lib/ibm_watson/text_to_speech_v1.rb +716 -0
  16. data/lib/ibm_watson/tone_analyzer_v3.rb +287 -0
  17. data/lib/ibm_watson/version.rb +3 -0
  18. data/lib/ibm_watson/visual_recognition_v3.rb +579 -0
  19. data/lib/ibm_watson/watson_api_exception.rb +41 -0
  20. data/lib/ibm_watson/watson_service.rb +180 -0
  21. data/lib/ibm_watson/websocket/recognize_callback.rb +32 -0
  22. data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +162 -0
  23. data/rakefile +45 -0
  24. data/test/integration/test_assistant_v1.rb +645 -0
  25. data/test/integration/test_discovery_v1.rb +200 -0
  26. data/test/integration/test_iam_assistant_v1.rb +707 -0
  27. data/test/integration/test_language_translator_v3.rb +81 -0
  28. data/test/integration/test_natural_language_classifier_v1.rb +69 -0
  29. data/test/integration/test_natural_language_understanding_v1.rb +98 -0
  30. data/test/integration/test_personality_insights_v3.rb +95 -0
  31. data/test/integration/test_speech_to_text_v1.rb +187 -0
  32. data/test/integration/test_text_to_speech_v1.rb +81 -0
  33. data/test/integration/test_tone_analyzer_v3.rb +72 -0
  34. data/test/integration/test_visual_recognition_v3.rb +64 -0
  35. data/test/test_helper.rb +22 -0
  36. data/test/unit/test_assistant_v1.rb +1598 -0
  37. data/test/unit/test_discovery_v1.rb +1144 -0
  38. data/test/unit/test_iam_token_manager.rb +165 -0
  39. data/test/unit/test_language_translator_v3.rb +461 -0
  40. data/test/unit/test_natural_language_classifier_v1.rb +187 -0
  41. data/test/unit/test_natural_language_understanding_v1.rb +132 -0
  42. data/test/unit/test_personality_insights_v3.rb +172 -0
  43. data/test/unit/test_speech_to_text_v1.rb +755 -0
  44. data/test/unit/test_text_to_speech_v1.rb +336 -0
  45. data/test/unit/test_tone_analyzer_v3.rb +200 -0
  46. data/test/unit/test_vcap_using_personality_insights.rb +150 -0
  47. data/test/unit/test_visual_recognition_v3.rb +345 -0
  48. metadata +302 -0
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative("./../test_helper.rb")
4
+ require("minitest/hooks/test")
5
+
6
+ # Integration tests for the Discovery V1 Service
7
+ class DiscoveryV1Test < Minitest::Test
8
+ include Minitest::Hooks
9
+ attr_accessor :service, :environment_id, :collection_id
10
+ def before_all
11
+ @service = IBMWatson::DiscoveryV1.new(
12
+ username: ENV["DISCOVERY_USERNAME"],
13
+ password: ENV["DISCOVERY_PASSWORD"],
14
+ version: "2018-03-05"
15
+ )
16
+ @environment_id = ENV["DISCOVERY_ENVIRONMENT_ID"]
17
+ @collection_id = ENV["DISCOVERY_COLLECTION_ID"]
18
+ @service.add_default_headers(
19
+ headers: {
20
+ "X-Watson-Learning-Opt-Out" => "1",
21
+ "X-Watson-Test" => "1"
22
+ }
23
+ )
24
+ end
25
+
26
+ def test_environments
27
+ envs = @service.list_environments.result
28
+ refute(envs.nil?)
29
+ env = @service.get_environment(
30
+ environment_id: envs["environments"][0]["environment_id"]
31
+ )
32
+ refute(env.nil?)
33
+ fields = @service.list_fields(
34
+ environment_id: @environment_id,
35
+ collection_ids: [@collection_id]
36
+ )
37
+ refute(fields.nil?)
38
+ end
39
+
40
+ def test_configurations
41
+ configs = @service.list_configurations(
42
+ environment_id: @environment_id
43
+ ).result
44
+ refute(configs.nil?)
45
+
46
+ name = "test" + ("A".."Z").to_a.sample
47
+ new_configuration_id = @service.create_configuration(
48
+ environment_id: @environment_id,
49
+ name: name,
50
+ description: "creating new config for ruby sdk"
51
+ ).result
52
+ new_configuration_id = new_configuration_id["configuration_id"]
53
+ refute(new_configuration_id.nil?)
54
+ @service.get_configuration(
55
+ environment_id: @environment_id,
56
+ configuration_id: new_configuration_id
57
+ )
58
+
59
+ updated_config = @service.update_configuration(
60
+ environment_id: @environment_id,
61
+ configuration_id: new_configuration_id,
62
+ name: "lala"
63
+ ).result
64
+ updated_config = updated_config
65
+ assert_equal("lala", updated_config["name"])
66
+
67
+ deleted_config = @service.delete_configuration(
68
+ environment_id: @environment_id,
69
+ configuration_id: new_configuration_id
70
+ ).result
71
+ deleted_config = deleted_config
72
+ assert_equal("deleted", deleted_config["status"])
73
+ end
74
+
75
+ def test_collections_and_expansions
76
+ skip "Time consuming"
77
+ name = "Example collection for ruby" + ("A".."Z").to_a.sample
78
+ new_collection_id = @service.create_collection(
79
+ environment_id: @environment_id,
80
+ name: name,
81
+ description: "Integration test for ruby sdk"
82
+ ).result
83
+ new_collection_id = new_collection_id["collection_id"]
84
+ refute(new_collection_id.nil?)
85
+
86
+ collection_status = { "status" => "pending" }
87
+ while collection_status["status"] == "pending"
88
+ sleep(1)
89
+ collection_status = @service.get_collection(
90
+ environment_id: @environment_id,
91
+ collection_id: new_collection_id
92
+ ).result
93
+ collection_status = collection_status
94
+ end
95
+ updated_collection = @service.update_collection(
96
+ environment_id: @environment_id,
97
+ collection_id: new_collection_id,
98
+ name: name,
99
+ description: "Updating description"
100
+ ).result
101
+ updated_collection = updated_collection
102
+ assert_equal("Updating description", updated_collection["description"])
103
+
104
+ @service.create_expansions(
105
+ environment_id: @environment_id,
106
+ collection_id: new_collection_id,
107
+ expansions: [
108
+ {
109
+ "input_terms" => ["a"],
110
+ "expanded_terms" => ["aa"]
111
+ }
112
+ ]
113
+ )
114
+ expansions = @service.list_expansions(
115
+ environment_id: @environment_id,
116
+ collection_id: new_collection_id
117
+ ).result
118
+ expansions = expansions
119
+ refute(expansions["expansions"].nil?)
120
+
121
+ @service.delete_expansions(
122
+ environment_id: @environment_id,
123
+ collection_id: new_collection_id
124
+ )
125
+ deleted_collection = @service.delete_collection(
126
+ environment_id: @environment_id,
127
+ collection_id: new_collection_id
128
+ ).result
129
+ deleted_collection = deleted_collection
130
+ assert_equal("deleted", deleted_collection["status"])
131
+ end
132
+
133
+ def test_documents
134
+ skip "Time consuming"
135
+ add_doc = nil
136
+ File.open(Dir.getwd + "/resources/simple.html") do |file_info|
137
+ add_doc = @service.add_document(
138
+ environment_id: @environment_id,
139
+ collection_id: @collection_id,
140
+ file: file_info
141
+ ).result
142
+ end
143
+ add_doc = add_doc
144
+ refute(add_doc["document_id"].nil?)
145
+
146
+ doc_status = { "status" => "processing" }
147
+ while doc_status["status"] == "processing"
148
+ sleep(1)
149
+ doc_status = @service.get_document_status(
150
+ environment_id: @environment_id,
151
+ collection_id: @collection_id,
152
+ document_id: add_doc["document_id"]
153
+ ).result
154
+ doc_status = doc_status
155
+ end
156
+ assert_equal("available", doc_status["status"])
157
+
158
+ update_doc = nil
159
+ File.open(Dir.getwd + "/resources/simple.html") do |file_info|
160
+ update_doc = @service.update_document(
161
+ environment_id: @environment_id,
162
+ collection_id: @collection_id,
163
+ document_id: add_doc["document_id"],
164
+ file: file_info,
165
+ filename: "newname.html"
166
+ ).result
167
+ end
168
+ refute(update_doc.nil?)
169
+
170
+ doc_status = { "status" => "processing" }
171
+ while doc_status["status"] == "processing"
172
+ sleep(1)
173
+ doc_status = @service.get_document_status(
174
+ environment_id: @environment_id,
175
+ collection_id: @collection_id,
176
+ document_id: add_doc["document_id"]
177
+ ).result
178
+ doc_status = doc_status
179
+ end
180
+ assert_equal("available", doc_status["status"])
181
+
182
+ delete_doc = @service.delete_document(
183
+ environment_id: @environment_id,
184
+ collection_id: @collection_id,
185
+ document_id: add_doc["document_id"]
186
+ ).result
187
+ delete_doc = delete_doc
188
+ assert_equal("deleted", delete_doc["status"])
189
+ end
190
+
191
+ def test_queries
192
+ query_results = @service.query(
193
+ environment_id: @environment_id,
194
+ collection_id: @collection_id,
195
+ filter: "extracted_metadata.sha1::9181d244*",
196
+ return_fields: ["extracted_metadata.sha1"]
197
+ ).result
198
+ refute(query_results.nil?)
199
+ end
200
+ end
@@ -0,0 +1,707 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative("./../test_helper.rb")
4
+
5
+ # Integration tests for the Watson Assistant V1 Service
6
+ class IAMAssistantV1Test < Minitest::Test
7
+ def test_create_update_delete_workspace
8
+ service = IBMWatson::AssistantV1.new(
9
+ url: ENV["ASSISTANT_IAM_URL"],
10
+ version: "2018-02-16"
11
+ )
12
+ service._iam_api_key(iam_api_key: ENV["ASSISTANT_IAM_APIKEY"])
13
+ service._iam_api_key(iam_api_key: ENV["ASSISTANT_IAM_APIKEY"])
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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
47
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
66
+ url: ENV["ASSISTANT_IAM_URL"],
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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
83
+ url: ENV["ASSISTANT_IAM_URL"]
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
114
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
133
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
151
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
187
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
207
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
226
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
261
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
281
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
300
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
334
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
354
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
373
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
391
+ url: ENV["ASSISTANT_IAM_URL"],
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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
409
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
437
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
475
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
496
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
516
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
553
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
574
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
594
+ url: ENV["ASSISTANT_IAM_URL"],
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_IAM_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_IAM_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_IAM_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_IAM_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
+ iam_api_key: ENV["ASSISTANT_IAM_APIKEY"],
631
+ url: ENV["ASSISTANT_IAM_URL"],
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?)
644
+ end
645
+
646
+ def test_get_workspace_with_iam_user_pass_params
647
+ service = IBMWatson::AssistantV1.new(
648
+ username: "apikey",
649
+ password: ENV["ASSISTANT_IAM_APIKEY"],
650
+ url: ENV["ASSISTANT_IAM_URL"],
651
+ version: "2018-02-16"
652
+ )
653
+ service.add_default_headers(
654
+ headers: {
655
+ "X-Watson-Learning-Opt-Out" => "1",
656
+ "X-Watson-Test" => "1"
657
+ }
658
+ )
659
+ service_response = service.get_workspace(
660
+ workspace_id: ENV["ASSISTANT_IAM_WORKSPACE_ID"],
661
+ export: false
662
+ )
663
+ assert((200..299).cover?(service_response.status))
664
+ end
665
+
666
+ def test_get_workspace_with_iam_user_pass_non_params
667
+ service = IBMWatson::AssistantV1.new(
668
+ url: ENV["ASSISTANT_IAM_URL"],
669
+ version: "2018-02-16"
670
+ )
671
+ service.add_default_headers(
672
+ headers: {
673
+ "X-Watson-Learning-Opt-Out" => "1",
674
+ "X-Watson-Test" => "1"
675
+ }
676
+ )
677
+ service.username = "apikey"
678
+ service.password = ENV["ASSISTANT_IAM_APIKEY"]
679
+ service_response = service.get_workspace(
680
+ workspace_id: ENV["ASSISTANT_IAM_WORKSPACE_ID"],
681
+ export: false
682
+ )
683
+ assert((200..299).cover?(service_response.status))
684
+ end
685
+
686
+ def test_receive_error
687
+ service = IBMWatson::AssistantV1.new(
688
+ url: ENV["ASSISTANT_IAM_URL"],
689
+ version: "2018-02-16"
690
+ )
691
+ service.add_default_headers(
692
+ headers: {
693
+ "X-Watson-Learning-Opt-Out" => "1",
694
+ "X-Watson-Test" => "1"
695
+ }
696
+ )
697
+ error_received = false
698
+ begin
699
+ service._iam_api_key(iam_api_key: "bogus_api_key")
700
+ service.list_workspaces
701
+ rescue WatsonApiException => e
702
+ assert_equal("Provided API key could not be found", e.info["errorMessage"])
703
+ error_received = true
704
+ end
705
+ assert(error_received)
706
+ end
707
+ end