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.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/bin/console +1 -0
- data/lib/ibm_watson/iam_token_manager.rb +7 -7
- data/lib/ibm_watson/version.rb +3 -1
- data/lib/ibm_watson/watson_service.rb +2 -2
- data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +3 -3
- data/rakefile +1 -1
- data/test/integration/test_assistant_v1.rb +640 -638
- data/test/integration/test_discovery_v1.rb +173 -170
- data/test/integration/test_iam_assistant_v1.rb +674 -672
- data/test/integration/test_language_translator_v3.rb +68 -66
- data/test/integration/test_natural_language_classifier_v1.rb +57 -55
- data/test/integration/test_natural_language_understanding_v1.rb +89 -87
- data/test/integration/test_personality_insights_v3.rb +87 -85
- data/test/integration/test_speech_to_text_v1.rb +143 -142
- data/test/integration/test_text_to_speech_v1.rb +71 -69
- data/test/integration/test_tone_analyzer_v3.rb +65 -63
- data/test/integration/test_visual_recognition_v3.rb +53 -51
- data/test/test_helper.rb +0 -1
- metadata +4 -18
@@ -3,198 +3,201 @@
|
|
3
3
|
require_relative("./../test_helper.rb")
|
4
4
|
require("minitest/hooks/test")
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
6
|
+
unless ENV["DISCOVERY_USERNAME"].nil? || ENV["DISCOVERY_PASSWORD"].nil?
|
7
|
+
# Integration tests for the Discovery V1 Service
|
8
|
+
class DiscoveryV1Test < Minitest::Test
|
9
|
+
include Minitest::Hooks
|
10
|
+
attr_accessor :service, :environment_id, :collection_id
|
11
|
+
|
12
|
+
def before_all
|
13
|
+
@service = IBMWatson::DiscoveryV1.new(
|
14
|
+
username: ENV["DISCOVERY_USERNAME"],
|
15
|
+
password: ENV["DISCOVERY_PASSWORD"],
|
16
|
+
version: "2018-03-05"
|
17
|
+
)
|
18
|
+
@environment_id = ENV["DISCOVERY_ENVIRONMENT_ID"]
|
19
|
+
@collection_id = ENV["DISCOVERY_COLLECTION_ID"]
|
20
|
+
@service.add_default_headers(
|
21
|
+
headers: {
|
22
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
23
|
+
"X-Watson-Test" => "1"
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
def test_environments
|
29
|
+
envs = @service.list_environments.result
|
30
|
+
refute(envs.nil?)
|
31
|
+
env = @service.get_environment(
|
32
|
+
environment_id: envs["environments"][0]["environment_id"]
|
33
|
+
)
|
34
|
+
refute(env.nil?)
|
35
|
+
fields = @service.list_fields(
|
36
|
+
environment_id: @environment_id,
|
37
|
+
collection_ids: [@collection_id]
|
38
|
+
)
|
39
|
+
refute(fields.nil?)
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
42
|
+
def test_configurations
|
43
|
+
configs = @service.list_configurations(
|
44
|
+
environment_id: @environment_id
|
45
|
+
).result
|
46
|
+
refute(configs.nil?)
|
74
47
|
|
75
|
-
|
76
|
-
|
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(
|
48
|
+
name = "test" + ("A".."Z").to_a.sample
|
49
|
+
new_configuration_id = @service.create_configuration(
|
90
50
|
environment_id: @environment_id,
|
91
|
-
|
51
|
+
name: name,
|
52
|
+
description: "creating new config for ruby sdk"
|
92
53
|
).result
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
54
|
+
new_configuration_id = new_configuration_id["configuration_id"]
|
55
|
+
refute(new_configuration_id.nil?)
|
56
|
+
@service.get_configuration(
|
57
|
+
environment_id: @environment_id,
|
58
|
+
configuration_id: new_configuration_id
|
59
|
+
)
|
132
60
|
|
133
|
-
|
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(
|
61
|
+
updated_config = @service.update_configuration(
|
138
62
|
environment_id: @environment_id,
|
139
|
-
|
140
|
-
|
63
|
+
configuration_id: new_configuration_id,
|
64
|
+
name: "lala"
|
141
65
|
).result
|
142
|
-
|
143
|
-
|
144
|
-
refute(add_doc["document_id"].nil?)
|
66
|
+
updated_config = updated_config
|
67
|
+
assert_equal("lala", updated_config["name"])
|
145
68
|
|
146
|
-
|
147
|
-
while doc_status["status"] == "processing"
|
148
|
-
sleep(1)
|
149
|
-
doc_status = @service.get_document_status(
|
69
|
+
deleted_config = @service.delete_configuration(
|
150
70
|
environment_id: @environment_id,
|
151
|
-
|
152
|
-
document_id: add_doc["document_id"]
|
71
|
+
configuration_id: new_configuration_id
|
153
72
|
).result
|
154
|
-
|
73
|
+
deleted_config = deleted_config
|
74
|
+
assert_equal("deleted", deleted_config["status"])
|
155
75
|
end
|
156
|
-
assert_equal("available", doc_status["status"])
|
157
76
|
|
158
|
-
|
159
|
-
|
160
|
-
|
77
|
+
def test_collections_and_expansions
|
78
|
+
skip "Time consuming"
|
79
|
+
name = "Example collection for ruby" + ("A".."Z").to_a.sample
|
80
|
+
new_collection_id = @service.create_collection(
|
161
81
|
environment_id: @environment_id,
|
162
|
-
|
163
|
-
|
164
|
-
file: file_info,
|
165
|
-
filename: "newname.html"
|
82
|
+
name: name,
|
83
|
+
description: "Integration test for ruby sdk"
|
166
84
|
).result
|
85
|
+
new_collection_id = new_collection_id["collection_id"]
|
86
|
+
refute(new_collection_id.nil?)
|
87
|
+
|
88
|
+
collection_status = { "status" => "pending" }
|
89
|
+
while collection_status["status"] == "pending"
|
90
|
+
sleep(1)
|
91
|
+
collection_status = @service.get_collection(
|
92
|
+
environment_id: @environment_id,
|
93
|
+
collection_id: new_collection_id
|
94
|
+
).result
|
95
|
+
collection_status = collection_status
|
96
|
+
end
|
97
|
+
updated_collection = @service.update_collection(
|
98
|
+
environment_id: @environment_id,
|
99
|
+
collection_id: new_collection_id,
|
100
|
+
name: name,
|
101
|
+
description: "Updating description"
|
102
|
+
).result
|
103
|
+
updated_collection = updated_collection
|
104
|
+
assert_equal("Updating description", updated_collection["description"])
|
105
|
+
|
106
|
+
@service.create_expansions(
|
107
|
+
environment_id: @environment_id,
|
108
|
+
collection_id: new_collection_id,
|
109
|
+
expansions: [
|
110
|
+
{
|
111
|
+
"input_terms" => ["a"],
|
112
|
+
"expanded_terms" => ["aa"]
|
113
|
+
}
|
114
|
+
]
|
115
|
+
)
|
116
|
+
expansions = @service.list_expansions(
|
117
|
+
environment_id: @environment_id,
|
118
|
+
collection_id: new_collection_id
|
119
|
+
).result
|
120
|
+
expansions = expansions
|
121
|
+
refute(expansions["expansions"].nil?)
|
122
|
+
|
123
|
+
@service.delete_expansions(
|
124
|
+
environment_id: @environment_id,
|
125
|
+
collection_id: new_collection_id
|
126
|
+
)
|
127
|
+
deleted_collection = @service.delete_collection(
|
128
|
+
environment_id: @environment_id,
|
129
|
+
collection_id: new_collection_id
|
130
|
+
).result
|
131
|
+
deleted_collection = deleted_collection
|
132
|
+
assert_equal("deleted", deleted_collection["status"])
|
167
133
|
end
|
168
|
-
refute(update_doc.nil?)
|
169
134
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
135
|
+
def test_documents
|
136
|
+
skip "Time consuming"
|
137
|
+
add_doc = nil
|
138
|
+
File.open(Dir.getwd + "/resources/simple.html") do |file_info|
|
139
|
+
add_doc = @service.add_document(
|
140
|
+
environment_id: @environment_id,
|
141
|
+
collection_id: @collection_id,
|
142
|
+
file: file_info
|
143
|
+
).result
|
144
|
+
end
|
145
|
+
add_doc = add_doc
|
146
|
+
refute(add_doc["document_id"].nil?)
|
147
|
+
|
148
|
+
doc_status = { "status" => "processing" }
|
149
|
+
while doc_status["status"] == "processing"
|
150
|
+
sleep(1)
|
151
|
+
doc_status = @service.get_document_status(
|
152
|
+
environment_id: @environment_id,
|
153
|
+
collection_id: @collection_id,
|
154
|
+
document_id: add_doc["document_id"]
|
155
|
+
).result
|
156
|
+
doc_status = doc_status
|
157
|
+
end
|
158
|
+
assert_equal("available", doc_status["status"])
|
159
|
+
|
160
|
+
update_doc = nil
|
161
|
+
File.open(Dir.getwd + "/resources/simple.html") do |file_info|
|
162
|
+
update_doc = @service.update_document(
|
163
|
+
environment_id: @environment_id,
|
164
|
+
collection_id: @collection_id,
|
165
|
+
document_id: add_doc["document_id"],
|
166
|
+
file: file_info,
|
167
|
+
filename: "newname.html"
|
168
|
+
).result
|
169
|
+
end
|
170
|
+
refute(update_doc.nil?)
|
171
|
+
|
172
|
+
doc_status = { "status" => "processing" }
|
173
|
+
while doc_status["status"] == "processing"
|
174
|
+
sleep(1)
|
175
|
+
doc_status = @service.get_document_status(
|
176
|
+
environment_id: @environment_id,
|
177
|
+
collection_id: @collection_id,
|
178
|
+
document_id: add_doc["document_id"]
|
179
|
+
).result
|
180
|
+
doc_status = doc_status
|
181
|
+
end
|
182
|
+
assert_equal("available", doc_status["status"])
|
183
|
+
|
184
|
+
delete_doc = @service.delete_document(
|
174
185
|
environment_id: @environment_id,
|
175
186
|
collection_id: @collection_id,
|
176
187
|
document_id: add_doc["document_id"]
|
177
188
|
).result
|
178
|
-
|
189
|
+
delete_doc = delete_doc
|
190
|
+
assert_equal("deleted", delete_doc["status"])
|
179
191
|
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
192
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
193
|
+
def test_queries
|
194
|
+
query_results = @service.query(
|
195
|
+
environment_id: @environment_id,
|
196
|
+
collection_id: @collection_id,
|
197
|
+
filter: "extracted_metadata.sha1::9181d244*",
|
198
|
+
return_fields: ["extracted_metadata.sha1"]
|
199
|
+
).result
|
200
|
+
refute(query_results.nil?)
|
201
|
+
end
|
199
202
|
end
|
200
203
|
end
|