ibm_watson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +258 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ibm_watson.rb +16 -0
- data/lib/ibm_watson/assistant_v1.rb +1997 -0
- data/lib/ibm_watson/detailed_response.rb +21 -0
- data/lib/ibm_watson/discovery_v1.rb +2039 -0
- data/lib/ibm_watson/iam_token_manager.rb +166 -0
- data/lib/ibm_watson/language_translator_v3.rb +411 -0
- data/lib/ibm_watson/natural_language_classifier_v1.rb +309 -0
- data/lib/ibm_watson/natural_language_understanding_v1.rb +297 -0
- data/lib/ibm_watson/personality_insights_v3.rb +260 -0
- data/lib/ibm_watson/speech_to_text_v1.rb +2153 -0
- data/lib/ibm_watson/text_to_speech_v1.rb +716 -0
- data/lib/ibm_watson/tone_analyzer_v3.rb +287 -0
- data/lib/ibm_watson/version.rb +3 -0
- data/lib/ibm_watson/visual_recognition_v3.rb +579 -0
- data/lib/ibm_watson/watson_api_exception.rb +41 -0
- data/lib/ibm_watson/watson_service.rb +180 -0
- data/lib/ibm_watson/websocket/recognize_callback.rb +32 -0
- data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +162 -0
- data/rakefile +45 -0
- data/test/integration/test_assistant_v1.rb +645 -0
- data/test/integration/test_discovery_v1.rb +200 -0
- data/test/integration/test_iam_assistant_v1.rb +707 -0
- data/test/integration/test_language_translator_v3.rb +81 -0
- data/test/integration/test_natural_language_classifier_v1.rb +69 -0
- data/test/integration/test_natural_language_understanding_v1.rb +98 -0
- data/test/integration/test_personality_insights_v3.rb +95 -0
- data/test/integration/test_speech_to_text_v1.rb +187 -0
- data/test/integration/test_text_to_speech_v1.rb +81 -0
- data/test/integration/test_tone_analyzer_v3.rb +72 -0
- data/test/integration/test_visual_recognition_v3.rb +64 -0
- data/test/test_helper.rb +22 -0
- data/test/unit/test_assistant_v1.rb +1598 -0
- data/test/unit/test_discovery_v1.rb +1144 -0
- data/test/unit/test_iam_token_manager.rb +165 -0
- data/test/unit/test_language_translator_v3.rb +461 -0
- data/test/unit/test_natural_language_classifier_v1.rb +187 -0
- data/test/unit/test_natural_language_understanding_v1.rb +132 -0
- data/test/unit/test_personality_insights_v3.rb +172 -0
- data/test/unit/test_speech_to_text_v1.rb +755 -0
- data/test/unit/test_text_to_speech_v1.rb +336 -0
- data/test/unit/test_tone_analyzer_v3.rb +200 -0
- data/test/unit/test_vcap_using_personality_insights.rb +150 -0
- data/test/unit/test_visual_recognition_v3.rb +345 -0
- metadata +302 -0
@@ -0,0 +1,1144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require("json")
|
4
|
+
require_relative("./../test_helper.rb")
|
5
|
+
require("webmock/minitest")
|
6
|
+
require("stringio")
|
7
|
+
|
8
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
9
|
+
|
10
|
+
# Unit tests for the Discovery V1 Service
|
11
|
+
class DiscoveryV1Test < Minitest::Test
|
12
|
+
def test_environments
|
13
|
+
discovery_response_body = {
|
14
|
+
"environments" => [
|
15
|
+
{
|
16
|
+
"environment_id" => "string",
|
17
|
+
"name" => "envname",
|
18
|
+
"description" => "",
|
19
|
+
"created" => "2016-11-20T01:03:17.645Z",
|
20
|
+
"updated" => "2016-11-20T01:03:17.645Z",
|
21
|
+
"status" => "status",
|
22
|
+
"index_capacity" => {
|
23
|
+
"disk_usage" => {
|
24
|
+
"used_bytes" => 0,
|
25
|
+
"total_bytes" => 0,
|
26
|
+
"used" => "string",
|
27
|
+
"total" => "string",
|
28
|
+
"percent_used" => 0
|
29
|
+
},
|
30
|
+
"memory_usage" => {
|
31
|
+
"used_bytes" => 0,
|
32
|
+
"total_bytes" => 0,
|
33
|
+
"used" => "string",
|
34
|
+
"total" => "string",
|
35
|
+
"percent_used" => 0
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments?version=2018-03-05")
|
42
|
+
.with(
|
43
|
+
headers: {
|
44
|
+
"Accept" => "application/json",
|
45
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
46
|
+
"Host" => "gateway.watsonplatform.net"
|
47
|
+
}
|
48
|
+
).to_return(status: 200, body: discovery_response_body.to_json, headers: { "Content-Type" => "application/json" })
|
49
|
+
service = IBMWatson::DiscoveryV1.new(
|
50
|
+
username: "username",
|
51
|
+
password: "password",
|
52
|
+
version: "2018-03-05"
|
53
|
+
)
|
54
|
+
service_response = service.list_environments
|
55
|
+
assert_equal(discovery_response_body, service_response.result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_get_environment
|
59
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid?version=2018-03-05")
|
60
|
+
.with(
|
61
|
+
headers: {
|
62
|
+
"Accept" => "application/json",
|
63
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
64
|
+
"Host" => "gateway.watsonplatform.net"
|
65
|
+
}
|
66
|
+
).to_return(status: 200, body: { "resulting_key" => true }.to_json, headers: { "Content-Type" => "application/json" })
|
67
|
+
service = IBMWatson::DiscoveryV1.new(
|
68
|
+
username: "username",
|
69
|
+
password: "password",
|
70
|
+
version: "2018-03-05"
|
71
|
+
)
|
72
|
+
service_response = service.get_environment(
|
73
|
+
environment_id: "envid"
|
74
|
+
)
|
75
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_create_environment
|
79
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments?version=2018-03-05")
|
80
|
+
.with(
|
81
|
+
body: "{\"name\":\"my name\",\"description\":\"my description\"}",
|
82
|
+
headers: {
|
83
|
+
"Accept" => "application/json",
|
84
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
85
|
+
"Content-Type" => "application/json",
|
86
|
+
"Host" => "gateway.watsonplatform.net"
|
87
|
+
}
|
88
|
+
).to_return(status: 200, body: { "resulting_key" => true }.to_json, headers: { "Content-Type" => "application/json" })
|
89
|
+
service = IBMWatson::DiscoveryV1.new(
|
90
|
+
username: "username",
|
91
|
+
password: "password",
|
92
|
+
version: "2018-03-05"
|
93
|
+
)
|
94
|
+
service_response = service.create_environment(
|
95
|
+
name: "my name",
|
96
|
+
description: "my description"
|
97
|
+
)
|
98
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_update_environment
|
102
|
+
stub_request(:put, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid?version=2018-03-05")
|
103
|
+
.with(
|
104
|
+
body: "{\"name\":\"hello\",\"description\":\"new\"}",
|
105
|
+
headers: {
|
106
|
+
"Accept" => "application/json",
|
107
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
108
|
+
"Content-Type" => "application/json",
|
109
|
+
"Host" => "gateway.watsonplatform.net"
|
110
|
+
}
|
111
|
+
).to_return(status: 200, body: { "resulting_key" => true }.to_json, headers: { "Content-Type" => "application/json" })
|
112
|
+
service = IBMWatson::DiscoveryV1.new(
|
113
|
+
username: "username",
|
114
|
+
password: "password",
|
115
|
+
version: "2018-03-05"
|
116
|
+
)
|
117
|
+
service_response = service.update_environment(
|
118
|
+
environment_id: "envid",
|
119
|
+
name: "hello",
|
120
|
+
description: "new"
|
121
|
+
)
|
122
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_delete_environment
|
126
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid?version=2018-03-05")
|
127
|
+
.with(
|
128
|
+
headers: {
|
129
|
+
"Accept" => "application/json",
|
130
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
131
|
+
"Host" => "gateway.watsonplatform.net"
|
132
|
+
}
|
133
|
+
).to_return(status: 200, body: { "resulting_key" => true }.to_json, headers: { "Content-Type" => "application/json" })
|
134
|
+
service = IBMWatson::DiscoveryV1.new(
|
135
|
+
username: "username",
|
136
|
+
password: "password",
|
137
|
+
version: "2018-03-05"
|
138
|
+
)
|
139
|
+
service_response = service.delete_environment(
|
140
|
+
environment_id: "envid"
|
141
|
+
)
|
142
|
+
assert_equal({ "resulting_key" => true }, service_response.result)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_collections
|
146
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections?version=2018-03-05")
|
147
|
+
.with(
|
148
|
+
headers: {
|
149
|
+
"Accept" => "application/json",
|
150
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
151
|
+
"Host" => "gateway.watsonplatform.net"
|
152
|
+
}
|
153
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
154
|
+
service = IBMWatson::DiscoveryV1.new(
|
155
|
+
username: "username",
|
156
|
+
password: "password",
|
157
|
+
version: "2018-03-05"
|
158
|
+
)
|
159
|
+
service_response = service.list_collections(
|
160
|
+
environment_id: "envid"
|
161
|
+
)
|
162
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_collection
|
166
|
+
service = IBMWatson::DiscoveryV1.new(
|
167
|
+
username: "username",
|
168
|
+
password: "password",
|
169
|
+
version: "2018-03-05"
|
170
|
+
)
|
171
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections?version=2018-03-05")
|
172
|
+
.with(
|
173
|
+
body: "{\"name\":\"name\",\"description\":\"\",\"configuration_id\":\"confid\",\"language\":\"\"}",
|
174
|
+
headers: {
|
175
|
+
"Accept" => "application/json",
|
176
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
177
|
+
"Content-Type" => "application/json",
|
178
|
+
"Host" => "gateway.watsonplatform.net"
|
179
|
+
}
|
180
|
+
).to_return(status: 200, body: { "body" => "create" }.to_json, headers: { "Content-Type" => "application/json" })
|
181
|
+
service_response = service.create_collection(
|
182
|
+
environment_id: "envid",
|
183
|
+
name: "name",
|
184
|
+
description: "",
|
185
|
+
language: "",
|
186
|
+
configuration_id: "confid"
|
187
|
+
)
|
188
|
+
assert_equal({ "body" => "create" }, service_response.result)
|
189
|
+
|
190
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections?version=2018-03-05")
|
191
|
+
.with(
|
192
|
+
body: "{\"name\":\"name\",\"description\":\"\",\"language\":\"es\"}",
|
193
|
+
headers: {
|
194
|
+
"Accept" => "application/json",
|
195
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
196
|
+
"Content-Type" => "application/json",
|
197
|
+
"Host" => "gateway.watsonplatform.net"
|
198
|
+
}
|
199
|
+
).to_return(status: 200, body: { "body" => "create" }.to_json, headers: { "Content-Type" => "application/json" })
|
200
|
+
service_response = service.create_collection(
|
201
|
+
environment_id: "envid",
|
202
|
+
name: "name",
|
203
|
+
language: "es",
|
204
|
+
description: ""
|
205
|
+
)
|
206
|
+
assert_equal({ "body" => "create" }, service_response.result)
|
207
|
+
|
208
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid?version=2018-03-05")
|
209
|
+
.with(
|
210
|
+
headers: {
|
211
|
+
"Accept" => "application/json",
|
212
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
213
|
+
"Host" => "gateway.watsonplatform.net"
|
214
|
+
}
|
215
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
216
|
+
service_response = service.get_collection(
|
217
|
+
environment_id: "envid",
|
218
|
+
collection_id: "collid"
|
219
|
+
)
|
220
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
221
|
+
|
222
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid?version=2018-03-05")
|
223
|
+
.with(
|
224
|
+
headers: {
|
225
|
+
"Accept" => "application/json",
|
226
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
227
|
+
"Host" => "gateway.watsonplatform.net"
|
228
|
+
}
|
229
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
230
|
+
service_response = service.delete_collection(
|
231
|
+
environment_id: "envid",
|
232
|
+
collection_id: "collid"
|
233
|
+
)
|
234
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
235
|
+
|
236
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/fields?version=2018-03-05")
|
237
|
+
.with(
|
238
|
+
headers: {
|
239
|
+
"Accept" => "application/json",
|
240
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
241
|
+
"Host" => "gateway.watsonplatform.net"
|
242
|
+
}
|
243
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
244
|
+
service_response = service.list_collection_fields(
|
245
|
+
environment_id: "envid",
|
246
|
+
collection_id: "collid"
|
247
|
+
)
|
248
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_query
|
252
|
+
service = IBMWatson::DiscoveryV1.new(
|
253
|
+
username: "username",
|
254
|
+
password: "password",
|
255
|
+
version: "2018-03-05"
|
256
|
+
)
|
257
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/query?count=10&version=2018-03-05")
|
258
|
+
.with(
|
259
|
+
headers: {
|
260
|
+
"Accept" => "application/json",
|
261
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
262
|
+
"Host" => "gateway.watsonplatform.net"
|
263
|
+
}
|
264
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
265
|
+
service_response = service.query(
|
266
|
+
environment_id: "envid",
|
267
|
+
collection_id: "collid",
|
268
|
+
count: 10
|
269
|
+
)
|
270
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_query_relations
|
274
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/query_relations?version=2018-03-05")
|
275
|
+
.with(
|
276
|
+
body: "{\"count\":10}",
|
277
|
+
headers: {
|
278
|
+
"Accept" => "application/json",
|
279
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
280
|
+
"Content-Type" => "application/json",
|
281
|
+
"Host" => "gateway.watsonplatform.net"
|
282
|
+
}
|
283
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
284
|
+
service = IBMWatson::DiscoveryV1.new(
|
285
|
+
username: "username",
|
286
|
+
password: "password",
|
287
|
+
version: "2018-03-05"
|
288
|
+
)
|
289
|
+
service_response = service.query_relations(
|
290
|
+
environment_id: "envid",
|
291
|
+
collection_id: "collid",
|
292
|
+
count: 10
|
293
|
+
)
|
294
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_query_entities
|
298
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/query_entities?version=2018-03-05")
|
299
|
+
.with(
|
300
|
+
body: "{\"count\":10}",
|
301
|
+
headers: {
|
302
|
+
"Accept" => "application/json",
|
303
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
304
|
+
"Content-Type" => "application/json",
|
305
|
+
"Host" => "gateway.watsonplatform.net"
|
306
|
+
}
|
307
|
+
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
308
|
+
service = IBMWatson::DiscoveryV1.new(
|
309
|
+
username: "username",
|
310
|
+
password: "password",
|
311
|
+
version: "2018-03-05"
|
312
|
+
)
|
313
|
+
service_response = service.query_entities(
|
314
|
+
environment_id: "envid",
|
315
|
+
collection_id: "collid",
|
316
|
+
count: 10
|
317
|
+
)
|
318
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_configs
|
322
|
+
results = {
|
323
|
+
"configurations" => [
|
324
|
+
{
|
325
|
+
"name" => "Default Configuration",
|
326
|
+
"configuration_id" => "confid"
|
327
|
+
}
|
328
|
+
]
|
329
|
+
}
|
330
|
+
service = IBMWatson::DiscoveryV1.new(
|
331
|
+
username: "username",
|
332
|
+
password: "password",
|
333
|
+
version: "2018-03-05"
|
334
|
+
)
|
335
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/configurations?version=2018-03-05")
|
336
|
+
.with(
|
337
|
+
headers: {
|
338
|
+
"Accept" => "application/json",
|
339
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
340
|
+
"Host" => "gateway.watsonplatform.net"
|
341
|
+
}
|
342
|
+
).to_return(status: 200, body: results.to_json, headers: { "Content-Type" => "application/json" })
|
343
|
+
service_response = service.list_configurations(
|
344
|
+
environment_id: "envid"
|
345
|
+
)
|
346
|
+
assert_equal(results, service_response.result)
|
347
|
+
|
348
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/configurations/confid?version=2018-03-05")
|
349
|
+
.with(
|
350
|
+
headers: {
|
351
|
+
"Accept" => "application/json",
|
352
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
353
|
+
"Host" => "gateway.watsonplatform.net"
|
354
|
+
}
|
355
|
+
).to_return(status: 200, body: results["configurations"][0].to_json, headers: { "Content-Type" => "application/json" })
|
356
|
+
service_response = service.get_configuration(
|
357
|
+
environment_id: "envid",
|
358
|
+
configuration_id: "confid"
|
359
|
+
)
|
360
|
+
assert_equal(results["configurations"][0], service_response.result)
|
361
|
+
|
362
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/configurations?version=2018-03-05")
|
363
|
+
.with(
|
364
|
+
body: "{\"name\":\"my name\"}",
|
365
|
+
headers: {
|
366
|
+
"Accept" => "application/json",
|
367
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
368
|
+
"Content-Type" => "application/json",
|
369
|
+
"Host" => "gateway.watsonplatform.net"
|
370
|
+
}
|
371
|
+
).to_return(status: 200, body: results["configurations"][0].to_json, headers: { "Content-Type" => "application/json" })
|
372
|
+
service_response = service.create_configuration(
|
373
|
+
environment_id: "envid",
|
374
|
+
name: "my name"
|
375
|
+
)
|
376
|
+
assert_equal(results["configurations"][0], service_response.result)
|
377
|
+
|
378
|
+
stub_request(:put, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/configurations/confid?version=2018-03-05")
|
379
|
+
.with(
|
380
|
+
body: "{\"name\":\"my new name\"}",
|
381
|
+
headers: {
|
382
|
+
"Accept" => "application/json",
|
383
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
384
|
+
"Content-Type" => "application/json",
|
385
|
+
"Host" => "gateway.watsonplatform.net"
|
386
|
+
}
|
387
|
+
).to_return(status: 200, body: results["configurations"][0].to_json, headers: { "Content-Type" => "application/json" })
|
388
|
+
service_response = service.update_configuration(
|
389
|
+
environment_id: "envid",
|
390
|
+
configuration_id: "confid",
|
391
|
+
name: "my new name"
|
392
|
+
)
|
393
|
+
assert_equal(results["configurations"][0], service_response.result)
|
394
|
+
|
395
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/configurations/confid?version=2018-03-05")
|
396
|
+
.with(
|
397
|
+
headers: {
|
398
|
+
"Accept" => "application/json",
|
399
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
400
|
+
"Host" => "gateway.watsonplatform.net"
|
401
|
+
}
|
402
|
+
).to_return(status: 200, body: { "deleted" => "bogus -- ok" }.to_json, headers: { "Content-Type" => "application/json" })
|
403
|
+
service_response = service.delete_configuration(
|
404
|
+
environment_id: "envid",
|
405
|
+
configuration_id: "confid"
|
406
|
+
)
|
407
|
+
assert_equal({ "deleted" => "bogus -- ok" }, service_response.result)
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_document
|
411
|
+
service = IBMWatson::DiscoveryV1.new(
|
412
|
+
username: "username",
|
413
|
+
password: "password",
|
414
|
+
version: "2018-03-05"
|
415
|
+
)
|
416
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/preview?configuration_id=bogus&version=2018-03-05")
|
417
|
+
.with(
|
418
|
+
headers: {
|
419
|
+
"Accept" => "application/json",
|
420
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
421
|
+
"Host" => "gateway.watsonplatform.net"
|
422
|
+
}
|
423
|
+
).to_return(status: 200, body: { configurations: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
424
|
+
File.open(Dir.getwd + "/resources/simple.html") do |file_info|
|
425
|
+
service_response = service.test_configuration_in_environment(
|
426
|
+
environment_id: "envid",
|
427
|
+
configuration_id: "bogus",
|
428
|
+
file: file_info,
|
429
|
+
filename: "simple.html"
|
430
|
+
)
|
431
|
+
refute(service_response.nil?)
|
432
|
+
|
433
|
+
service_response = service.test_configuration_in_environment(
|
434
|
+
environment_id: "envid",
|
435
|
+
configuration_id: "bogus",
|
436
|
+
file: "file_info"
|
437
|
+
)
|
438
|
+
refute(service_response.nil?)
|
439
|
+
|
440
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/preview?version=2018-03-05")
|
441
|
+
.with(
|
442
|
+
headers: {
|
443
|
+
"Accept" => "application/json",
|
444
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
445
|
+
"Host" => "gateway.watsonplatform.net"
|
446
|
+
}
|
447
|
+
).to_return(status: 200, body: { configurations: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
448
|
+
service_response = service.test_configuration_in_environment(
|
449
|
+
environment_id: "envid",
|
450
|
+
file: file_info
|
451
|
+
)
|
452
|
+
refute(service_response.nil?)
|
453
|
+
end
|
454
|
+
doc_status = {
|
455
|
+
"document_id" => "45556e23-f2b1-449d-8f27-489b514000ff",
|
456
|
+
"configuration_id" => "2e079259-7dd2-40a9-998f-3e716f5a7b88",
|
457
|
+
"created" => "2016-06-16T10:56:54.957Z",
|
458
|
+
"updated" => "2017-05-16T13:56:54.957Z",
|
459
|
+
"status" => "available",
|
460
|
+
"status_description" => "Document is successfully ingested and indexed with no warnings",
|
461
|
+
"notices" => []
|
462
|
+
}
|
463
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/documents?version=2018-03-05")
|
464
|
+
.with(
|
465
|
+
headers: {
|
466
|
+
"Accept" => "application/json",
|
467
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
468
|
+
"Host" => "gateway.watsonplatform.net"
|
469
|
+
}
|
470
|
+
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
471
|
+
File.open(Dir.getwd + "/resources/simple.html") do |file_info|
|
472
|
+
service_response = service.add_document(
|
473
|
+
environment_id: "envid",
|
474
|
+
collection_id: "collid",
|
475
|
+
file: file_info
|
476
|
+
)
|
477
|
+
refute(service_response.nil?)
|
478
|
+
end
|
479
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/documents/docid?version=2018-03-05")
|
480
|
+
.with(
|
481
|
+
headers: {
|
482
|
+
"Accept" => "application/json",
|
483
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
484
|
+
"Host" => "gateway.watsonplatform.net"
|
485
|
+
}
|
486
|
+
).to_return(status: 200, body: doc_status.to_json, headers: { "Content-Type" => "application/json" })
|
487
|
+
service_response = service.get_document_status(
|
488
|
+
environment_id: "envid",
|
489
|
+
collection_id: "collid",
|
490
|
+
document_id: "docid"
|
491
|
+
)
|
492
|
+
assert_equal(doc_status, service_response.result)
|
493
|
+
|
494
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/documents/docid?version=2018-03-05")
|
495
|
+
.with(
|
496
|
+
headers: {
|
497
|
+
"Accept" => "application/json",
|
498
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
499
|
+
"Host" => "gateway.watsonplatform.net"
|
500
|
+
}
|
501
|
+
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
502
|
+
service_response = service.update_document(
|
503
|
+
environment_id: "envid",
|
504
|
+
collection_id: "collid",
|
505
|
+
document_id: "docid",
|
506
|
+
file: "file",
|
507
|
+
filename: "file.name"
|
508
|
+
)
|
509
|
+
assert_equal({ "body" => [] }, service_response.result)
|
510
|
+
|
511
|
+
service_response = service.update_document(
|
512
|
+
environment_id: "envid",
|
513
|
+
collection_id: "collid",
|
514
|
+
document_id: "docid",
|
515
|
+
file: "file"
|
516
|
+
)
|
517
|
+
assert_equal({ "body" => [] }, service_response.result)
|
518
|
+
|
519
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/documents/docid?version=2018-03-05")
|
520
|
+
.with(
|
521
|
+
headers: {
|
522
|
+
"Accept" => "application/json",
|
523
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
524
|
+
"Host" => "gateway.watsonplatform.net"
|
525
|
+
}
|
526
|
+
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
527
|
+
service_response = service.delete_document(
|
528
|
+
environment_id: "envid",
|
529
|
+
collection_id: "collid",
|
530
|
+
document_id: "docid"
|
531
|
+
)
|
532
|
+
assert_equal({ "body" => [] }, service_response.result)
|
533
|
+
|
534
|
+
service_response = service.add_document(
|
535
|
+
environment_id: "envid",
|
536
|
+
collection_id: "collid",
|
537
|
+
file: "my string of file",
|
538
|
+
filename: "file.txt"
|
539
|
+
)
|
540
|
+
refute(service_response.nil?)
|
541
|
+
|
542
|
+
service_response = service.add_document(
|
543
|
+
environment_id: "envid",
|
544
|
+
collection_id: "collid",
|
545
|
+
file: StringIO.new("<h1>my string of file</h1>"),
|
546
|
+
filename: "file.html",
|
547
|
+
file_content_type: "application/html"
|
548
|
+
)
|
549
|
+
refute(service_response.nil?)
|
550
|
+
|
551
|
+
service_response = service.add_document(
|
552
|
+
environment_id: "envid",
|
553
|
+
collection_id: "collid",
|
554
|
+
file: StringIO.new("<h1>my string of file</h1>"),
|
555
|
+
filename: "file.html",
|
556
|
+
file_content_type: "application/html",
|
557
|
+
metadata: StringIO.new({ stuff: "woot!" }.to_json)
|
558
|
+
)
|
559
|
+
refute(service_response.nil?)
|
560
|
+
end
|
561
|
+
|
562
|
+
def test_delete_all_training_data
|
563
|
+
service = IBMWatson::DiscoveryV1.new(
|
564
|
+
username: "username",
|
565
|
+
password: "password",
|
566
|
+
version: "2018-03-05"
|
567
|
+
)
|
568
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data?version=2018-03-05")
|
569
|
+
.with(
|
570
|
+
headers: {
|
571
|
+
"Accept" => "application/json",
|
572
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
573
|
+
"Host" => "gateway.watsonplatform.net"
|
574
|
+
}
|
575
|
+
).to_return(status: 204, body: "", headers: {})
|
576
|
+
service_response = service.delete_all_training_data(
|
577
|
+
environment_id: "envid",
|
578
|
+
collection_id: "collid"
|
579
|
+
)
|
580
|
+
assert_nil(service_response)
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_list_training_data
|
584
|
+
service = IBMWatson::DiscoveryV1.new(
|
585
|
+
username: "username",
|
586
|
+
password: "password",
|
587
|
+
version: "2018-03-05"
|
588
|
+
)
|
589
|
+
mock_response = {
|
590
|
+
"environment_id" => "string",
|
591
|
+
"collection_id" => "string",
|
592
|
+
"queries" => [
|
593
|
+
{
|
594
|
+
"query_id" => "string",
|
595
|
+
"natural_language_query" => "string",
|
596
|
+
"filter" => "string",
|
597
|
+
"examples" => [
|
598
|
+
{
|
599
|
+
"document_id" => "string",
|
600
|
+
"cross_reference" => "string",
|
601
|
+
"relevance" => 0
|
602
|
+
}
|
603
|
+
]
|
604
|
+
}
|
605
|
+
]
|
606
|
+
}
|
607
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data?version=2018-03-05")
|
608
|
+
.with(
|
609
|
+
headers: {
|
610
|
+
"Accept" => "application/json",
|
611
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
612
|
+
"Host" => "gateway.watsonplatform.net"
|
613
|
+
}
|
614
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
615
|
+
service_response = service.list_training_data(
|
616
|
+
environment_id: "envid",
|
617
|
+
collection_id: "collid"
|
618
|
+
)
|
619
|
+
assert_equal(mock_response, service_response.result)
|
620
|
+
end
|
621
|
+
|
622
|
+
def test_add_training_data
|
623
|
+
natural_language_query = "why is the sky blue"
|
624
|
+
filter = "text:meteorology"
|
625
|
+
examples = [
|
626
|
+
{
|
627
|
+
"document_id" => "54f95ac0-3e4f-4756-bea6-7a67b2713c81",
|
628
|
+
"relevance" => 1
|
629
|
+
},
|
630
|
+
{
|
631
|
+
"document_id" => "01bcca32-7300-4c9f-8d32-33ed7ea643da",
|
632
|
+
"cross_reference" => "my_id_field:1463",
|
633
|
+
"relevance" => 5
|
634
|
+
}
|
635
|
+
]
|
636
|
+
mock_response = {
|
637
|
+
"query_id" => "string",
|
638
|
+
"natural_language_query" => "string",
|
639
|
+
"filter" => "string",
|
640
|
+
"examples" => [
|
641
|
+
{
|
642
|
+
"document_id" => "string",
|
643
|
+
"cross_reference" => "string",
|
644
|
+
"relevance" => 0
|
645
|
+
}
|
646
|
+
]
|
647
|
+
}
|
648
|
+
service = IBMWatson::DiscoveryV1.new(
|
649
|
+
username: "username",
|
650
|
+
password: "password",
|
651
|
+
version: "2018-03-05"
|
652
|
+
)
|
653
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data?version=2018-03-05")
|
654
|
+
.with(
|
655
|
+
body: "{\"natural_language_query\":\"why is the sky blue\",\"filter\":\"text:meteorology\",\"examples\":[{\"document_id\":\"54f95ac0-3e4f-4756-bea6-7a67b2713c81\",\"relevance\":1},{\"document_id\":\"01bcca32-7300-4c9f-8d32-33ed7ea643da\",\"cross_reference\":\"my_id_field:1463\",\"relevance\":5}]}",
|
656
|
+
headers: {
|
657
|
+
"Accept" => "application/json",
|
658
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
659
|
+
"Content-Type" => "application/json",
|
660
|
+
"Host" => "gateway.watsonplatform.net"
|
661
|
+
}
|
662
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
663
|
+
service_response = service.add_training_data(
|
664
|
+
environment_id: "envid",
|
665
|
+
collection_id: "collid",
|
666
|
+
natural_language_query: natural_language_query,
|
667
|
+
filter: filter,
|
668
|
+
examples: examples
|
669
|
+
)
|
670
|
+
assert_equal(mock_response, service_response.result)
|
671
|
+
end
|
672
|
+
|
673
|
+
def test_delete_training_data
|
674
|
+
service = IBMWatson::DiscoveryV1.new(
|
675
|
+
username: "username",
|
676
|
+
password: "password",
|
677
|
+
version: "2018-03-05"
|
678
|
+
)
|
679
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid?version=2018-03-05")
|
680
|
+
.with(
|
681
|
+
headers: {
|
682
|
+
"Accept" => "application/json",
|
683
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
684
|
+
"Host" => "gateway.watsonplatform.net"
|
685
|
+
}
|
686
|
+
).to_return(status: 200, body: "", headers: {})
|
687
|
+
service_response = service.delete_training_data(
|
688
|
+
environment_id: "envid",
|
689
|
+
collection_id: "collid",
|
690
|
+
query_id: "queryid"
|
691
|
+
)
|
692
|
+
assert_nil(service_response)
|
693
|
+
end
|
694
|
+
|
695
|
+
def test_get_training_data
|
696
|
+
mock_response = {
|
697
|
+
"query_id" => "string",
|
698
|
+
"natural_language_query" => "string",
|
699
|
+
"filter" => "string",
|
700
|
+
"examples" => [
|
701
|
+
{
|
702
|
+
"document_id" => "string",
|
703
|
+
"cross_reference" => "string",
|
704
|
+
"relevance" => 0
|
705
|
+
}
|
706
|
+
]
|
707
|
+
}
|
708
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid?version=2018-03-05")
|
709
|
+
.with(
|
710
|
+
headers: {
|
711
|
+
"Accept" => "application/json",
|
712
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
713
|
+
"Host" => "gateway.watsonplatform.net"
|
714
|
+
}
|
715
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
716
|
+
service = IBMWatson::DiscoveryV1.new(
|
717
|
+
username: "username",
|
718
|
+
password: "password",
|
719
|
+
version: "2018-03-05"
|
720
|
+
)
|
721
|
+
service_response = service.get_training_data(
|
722
|
+
environment_id: "envid",
|
723
|
+
collection_id: "collid",
|
724
|
+
query_id: "queryid"
|
725
|
+
)
|
726
|
+
assert_equal(mock_response, service_response.result)
|
727
|
+
end
|
728
|
+
|
729
|
+
def test_create_training_example
|
730
|
+
document_id = "string"
|
731
|
+
relevance = 0
|
732
|
+
cross_reference = "string"
|
733
|
+
mock_response = {
|
734
|
+
"document_id" => "string",
|
735
|
+
"cross_reference" => "string",
|
736
|
+
"relevance" => 0
|
737
|
+
}
|
738
|
+
service = IBMWatson::DiscoveryV1.new(
|
739
|
+
username: "username",
|
740
|
+
password: "password",
|
741
|
+
version: "2018-03-05"
|
742
|
+
)
|
743
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid/examples?version=2018-03-05")
|
744
|
+
.with(
|
745
|
+
body: "{\"document_id\":\"string\",\"cross_reference\":\"string\",\"relevance\":0}",
|
746
|
+
headers: {
|
747
|
+
"Accept" => "application/json",
|
748
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
749
|
+
"Content-Type" => "application/json",
|
750
|
+
"Host" => "gateway.watsonplatform.net"
|
751
|
+
}
|
752
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
753
|
+
service_response = service.create_training_example(
|
754
|
+
environment_id: "envid",
|
755
|
+
collection_id: "collid",
|
756
|
+
query_id: "queryid",
|
757
|
+
document_id: document_id,
|
758
|
+
relevance: relevance,
|
759
|
+
cross_reference: cross_reference
|
760
|
+
)
|
761
|
+
assert_equal(mock_response, service_response.result)
|
762
|
+
end
|
763
|
+
|
764
|
+
def test_delete_training_example
|
765
|
+
service = IBMWatson::DiscoveryV1.new(
|
766
|
+
username: "username",
|
767
|
+
password: "password",
|
768
|
+
version: "2018-03-05"
|
769
|
+
)
|
770
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid/examples/exampleid?version=2018-03-05")
|
771
|
+
.with(
|
772
|
+
headers: {
|
773
|
+
"Accept" => "application/json",
|
774
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
775
|
+
"Host" => "gateway.watsonplatform.net"
|
776
|
+
}
|
777
|
+
).to_return(status: 204, body: "", headers: {})
|
778
|
+
service_response = service.delete_training_example(
|
779
|
+
environment_id: "envid",
|
780
|
+
collection_id: "collid",
|
781
|
+
query_id: "queryid",
|
782
|
+
example_id: "exampleid"
|
783
|
+
)
|
784
|
+
assert_nil(service_response)
|
785
|
+
end
|
786
|
+
|
787
|
+
def test_get_training_example
|
788
|
+
mock_response = {
|
789
|
+
"document_id" => "string",
|
790
|
+
"cross_reference" => "string",
|
791
|
+
"relevance" => 0
|
792
|
+
}
|
793
|
+
service = IBMWatson::DiscoveryV1.new(
|
794
|
+
username: "username",
|
795
|
+
password: "password",
|
796
|
+
version: "2018-03-05"
|
797
|
+
)
|
798
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid/examples/exampleid?version=2018-03-05")
|
799
|
+
.with(
|
800
|
+
headers: {
|
801
|
+
"Accept" => "application/json",
|
802
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
803
|
+
"Host" => "gateway.watsonplatform.net"
|
804
|
+
}
|
805
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
806
|
+
service_response = service.get_training_example(
|
807
|
+
environment_id: "envid",
|
808
|
+
collection_id: "collid",
|
809
|
+
query_id: "queryid",
|
810
|
+
example_id: "exampleid"
|
811
|
+
)
|
812
|
+
assert_equal(mock_response, service_response.result)
|
813
|
+
end
|
814
|
+
|
815
|
+
def test_update_training_example
|
816
|
+
relevance = 0
|
817
|
+
cross_reference = "string"
|
818
|
+
mock_response = {
|
819
|
+
"document_id" => "string",
|
820
|
+
"cross_reference" => "string",
|
821
|
+
"relevance" => 0
|
822
|
+
}
|
823
|
+
service = IBMWatson::DiscoveryV1.new(
|
824
|
+
username: "username",
|
825
|
+
password: "password",
|
826
|
+
version: "2018-03-05"
|
827
|
+
)
|
828
|
+
stub_request(:put, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid/examples/exampleid?version=2018-03-05")
|
829
|
+
.with(
|
830
|
+
body: "{\"cross_reference\":\"string\",\"relevance\":0}",
|
831
|
+
headers: {
|
832
|
+
"Accept" => "application/json",
|
833
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
834
|
+
"Content-Type" => "application/json",
|
835
|
+
"Host" => "gateway.watsonplatform.net"
|
836
|
+
}
|
837
|
+
).to_return(status: 200, body: mock_response.to_json, headers: { "Content-Type" => "application/json" })
|
838
|
+
service_response = service.update_training_example(
|
839
|
+
environment_id: "envid",
|
840
|
+
collection_id: "collid",
|
841
|
+
query_id: "queryid",
|
842
|
+
example_id: "exampleid",
|
843
|
+
relevance: relevance,
|
844
|
+
cross_reference: cross_reference
|
845
|
+
)
|
846
|
+
assert_equal(mock_response, service_response.result)
|
847
|
+
end
|
848
|
+
|
849
|
+
def test_expansions
|
850
|
+
service = IBMWatson::DiscoveryV1.new(
|
851
|
+
username: "username",
|
852
|
+
password: "password",
|
853
|
+
version: "2018-03-05"
|
854
|
+
)
|
855
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/expansions?version=2018-03-05")
|
856
|
+
.with(
|
857
|
+
headers: {
|
858
|
+
"Accept" => "application/json",
|
859
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
860
|
+
"Host" => "gateway.watsonplatform.net"
|
861
|
+
}
|
862
|
+
).to_return(status: 200, body: { expansions: "results" }.to_json, headers: { "Content-Type" => "application/json" })
|
863
|
+
service_response = service.list_expansions(
|
864
|
+
environment_id: "envid",
|
865
|
+
collection_id: "collid"
|
866
|
+
)
|
867
|
+
assert_equal({ "expansions" => "results" }, service_response.result)
|
868
|
+
|
869
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/expansions?version=2018-03-05")
|
870
|
+
.with(
|
871
|
+
body: "{\"expansions\":[{\"input_terms\":\"dumb\",\"expanded_terms\":\"dumb2\"}]}",
|
872
|
+
headers: {
|
873
|
+
"Accept" => "application/json",
|
874
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
875
|
+
"Content-Type" => "application/json",
|
876
|
+
"Host" => "gateway.watsonplatform.net"
|
877
|
+
}
|
878
|
+
).to_return(status: 200, body: { expansions: "success" }.to_json, headers: { "Content-Type" => "application/json" })
|
879
|
+
service_response = service.create_expansions(
|
880
|
+
environment_id: "envid",
|
881
|
+
collection_id: "collid",
|
882
|
+
expansions: [
|
883
|
+
{
|
884
|
+
"input_terms" => "dumb",
|
885
|
+
"expanded_terms" => "dumb2"
|
886
|
+
}
|
887
|
+
]
|
888
|
+
)
|
889
|
+
assert_equal({ "expansions" => "success" }, service_response.result)
|
890
|
+
|
891
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/expansions?version=2018-03-05")
|
892
|
+
.with(
|
893
|
+
headers: {
|
894
|
+
"Accept" => "application/json",
|
895
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
896
|
+
"Host" => "gateway.watsonplatform.net"
|
897
|
+
}
|
898
|
+
).to_return(status: 200, body: { description: "success" }.to_json, headers: { "Content-Type" => "application/json" })
|
899
|
+
service_response = service.delete_expansions(
|
900
|
+
environment_id: "envid",
|
901
|
+
collection_id: "collid"
|
902
|
+
)
|
903
|
+
assert_nil(service_response)
|
904
|
+
end
|
905
|
+
|
906
|
+
def test_delete_user_data
|
907
|
+
service = IBMWatson::DiscoveryV1.new(
|
908
|
+
username: "username",
|
909
|
+
password: "password",
|
910
|
+
version: "2018-03-05"
|
911
|
+
)
|
912
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/user_data?customer_id=id&version=2018-03-05")
|
913
|
+
.with(
|
914
|
+
headers: {
|
915
|
+
"Accept" => "application/json",
|
916
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
917
|
+
"Host" => "gateway.watsonplatform.net"
|
918
|
+
}
|
919
|
+
).to_return(status: 200, body: "", headers: {})
|
920
|
+
service_response = service.delete_user_data(
|
921
|
+
customer_id: "id"
|
922
|
+
)
|
923
|
+
assert_nil(service_response)
|
924
|
+
end
|
925
|
+
|
926
|
+
def test_query_notices
|
927
|
+
service = IBMWatson::DiscoveryV1.new(
|
928
|
+
username: "username",
|
929
|
+
password: "password",
|
930
|
+
version: "2018-03-05"
|
931
|
+
)
|
932
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/notices?version=2018-03-05")
|
933
|
+
.with(
|
934
|
+
headers: {
|
935
|
+
"Accept" => "application/json",
|
936
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
937
|
+
"Host" => "gateway.watsonplatform.net"
|
938
|
+
}
|
939
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
940
|
+
service_response = service.query_notices(
|
941
|
+
environment_id: "envid",
|
942
|
+
collection_id: "collid"
|
943
|
+
)
|
944
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
945
|
+
end
|
946
|
+
|
947
|
+
def test_federated_query
|
948
|
+
service = IBMWatson::DiscoveryV1.new(
|
949
|
+
username: "username",
|
950
|
+
password: "password",
|
951
|
+
version: "2018-03-05"
|
952
|
+
)
|
953
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/query?collection_ids=collid&version=2018-03-05")
|
954
|
+
.with(
|
955
|
+
headers: {
|
956
|
+
"Accept" => "application/json",
|
957
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
958
|
+
"Host" => "gateway.watsonplatform.net"
|
959
|
+
}
|
960
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
961
|
+
service_response = service.federated_query(
|
962
|
+
environment_id: "envid",
|
963
|
+
collection_ids: ["collid"]
|
964
|
+
)
|
965
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
966
|
+
end
|
967
|
+
|
968
|
+
def test_federated_query_notices
|
969
|
+
service = IBMWatson::DiscoveryV1.new(
|
970
|
+
username: "username",
|
971
|
+
password: "password",
|
972
|
+
version: "2018-03-05"
|
973
|
+
)
|
974
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/notices?collection_ids=collid&version=2018-03-05")
|
975
|
+
.with(
|
976
|
+
headers: {
|
977
|
+
"Accept" => "application/json",
|
978
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
979
|
+
"Host" => "gateway.watsonplatform.net"
|
980
|
+
}
|
981
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
982
|
+
service_response = service.federated_query_notices(
|
983
|
+
environment_id: "envid",
|
984
|
+
collection_ids: ["collid"]
|
985
|
+
)
|
986
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
987
|
+
end
|
988
|
+
|
989
|
+
def test_list_training_examples
|
990
|
+
service = IBMWatson::DiscoveryV1.new(
|
991
|
+
username: "username",
|
992
|
+
password: "password",
|
993
|
+
version: "2018-03-05"
|
994
|
+
)
|
995
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/training_data/queryid/examples?version=2018-03-05")
|
996
|
+
.with(
|
997
|
+
headers: {
|
998
|
+
"Accept" => "application/json",
|
999
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1000
|
+
"Host" => "gateway.watsonplatform.net"
|
1001
|
+
}
|
1002
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1003
|
+
service_response = service.list_training_examples(
|
1004
|
+
environment_id: "envid",
|
1005
|
+
collection_id: "collid",
|
1006
|
+
query_id: "queryid"
|
1007
|
+
)
|
1008
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
def test_list_credentials
|
1012
|
+
service = IBMWatson::DiscoveryV1.new(
|
1013
|
+
username: "username",
|
1014
|
+
password: "password",
|
1015
|
+
version: "2018-03-05"
|
1016
|
+
)
|
1017
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/credentials?version=2018-03-05")
|
1018
|
+
.with(
|
1019
|
+
headers: {
|
1020
|
+
"Accept" => "application/json",
|
1021
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1022
|
+
"Host" => "gateway.watsonplatform.net"
|
1023
|
+
}
|
1024
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1025
|
+
service_response = service.list_credentials(
|
1026
|
+
environment_id: "envid"
|
1027
|
+
)
|
1028
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def test_create_credentials
|
1032
|
+
service = IBMWatson::DiscoveryV1.new(
|
1033
|
+
username: "username",
|
1034
|
+
password: "password",
|
1035
|
+
version: "2018-03-05"
|
1036
|
+
)
|
1037
|
+
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/credentials?version=2018-03-05")
|
1038
|
+
.with(
|
1039
|
+
body: "{\"source_type\":\"salesforce\"}",
|
1040
|
+
headers: {
|
1041
|
+
"Accept" => "application/json",
|
1042
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1043
|
+
"Content-Type" => "application/json",
|
1044
|
+
"Host" => "gateway.watsonplatform.net"
|
1045
|
+
}
|
1046
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1047
|
+
service_response = service.create_credentials(
|
1048
|
+
environment_id: "envid",
|
1049
|
+
source_type: "salesforce"
|
1050
|
+
)
|
1051
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
def test_get_credentials
|
1055
|
+
service = IBMWatson::DiscoveryV1.new(
|
1056
|
+
username: "username",
|
1057
|
+
password: "password",
|
1058
|
+
version: "2018-03-05"
|
1059
|
+
)
|
1060
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/credentials/credid?version=2018-03-05")
|
1061
|
+
.with(
|
1062
|
+
headers: {
|
1063
|
+
"Accept" => "application/json",
|
1064
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1065
|
+
"Host" => "gateway.watsonplatform.net"
|
1066
|
+
}
|
1067
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1068
|
+
service_response = service.get_credentials(
|
1069
|
+
environment_id: "envid",
|
1070
|
+
credential_id: "credid"
|
1071
|
+
)
|
1072
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
def test_update_credentials
|
1076
|
+
service = IBMWatson::DiscoveryV1.new(
|
1077
|
+
username: "username",
|
1078
|
+
password: "password",
|
1079
|
+
version: "2018-03-05"
|
1080
|
+
)
|
1081
|
+
stub_request(:put, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/credentials/credid?version=2018-03-05")
|
1082
|
+
.with(
|
1083
|
+
body: "{\"source_type\":\"salesforce\"}",
|
1084
|
+
headers: {
|
1085
|
+
"Accept" => "application/json",
|
1086
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1087
|
+
"Content-Type" => "application/json",
|
1088
|
+
"Host" => "gateway.watsonplatform.net"
|
1089
|
+
}
|
1090
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1091
|
+
service_response = service.update_credentials(
|
1092
|
+
environment_id: "envid",
|
1093
|
+
credential_id: "credid",
|
1094
|
+
source_type: "salesforce"
|
1095
|
+
)
|
1096
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
def test_delete_credentials
|
1100
|
+
service = IBMWatson::DiscoveryV1.new(
|
1101
|
+
username: "username",
|
1102
|
+
password: "password",
|
1103
|
+
version: "2018-03-05"
|
1104
|
+
)
|
1105
|
+
stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/credentials/credid?version=2018-03-05")
|
1106
|
+
.with(
|
1107
|
+
headers: {
|
1108
|
+
"Accept" => "application/json",
|
1109
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1110
|
+
"Host" => "gateway.watsonplatform.net"
|
1111
|
+
}
|
1112
|
+
).to_return(status: 200, body: { "deleted" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1113
|
+
service_response = service.delete_credentials(
|
1114
|
+
environment_id: "envid",
|
1115
|
+
credential_id: "credid"
|
1116
|
+
)
|
1117
|
+
assert_equal({ "deleted" => "true" }, service_response.result)
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
def test_update_collection
|
1121
|
+
service = IBMWatson::DiscoveryV1.new(
|
1122
|
+
username: "username",
|
1123
|
+
password: "password",
|
1124
|
+
version: "2018-03-05"
|
1125
|
+
)
|
1126
|
+
stub_request(:put, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid?version=2018-03-05")
|
1127
|
+
.with(
|
1128
|
+
body: "{\"name\":\"name\",\"description\":\"updated description\"}",
|
1129
|
+
headers: {
|
1130
|
+
"Accept" => "application/json",
|
1131
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1132
|
+
"Content-Type" => "application/json",
|
1133
|
+
"Host" => "gateway.watsonplatform.net"
|
1134
|
+
}
|
1135
|
+
).to_return(status: 200, body: { "updated" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1136
|
+
service_response = service.update_collection(
|
1137
|
+
environment_id: "envid",
|
1138
|
+
collection_id: "collid",
|
1139
|
+
name: "name",
|
1140
|
+
description: "updated description"
|
1141
|
+
)
|
1142
|
+
assert_equal({ "updated" => "true" }, service_response.result)
|
1143
|
+
end
|
1144
|
+
end
|