ibm_watson 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,198 +3,201 @@
3
3
  require_relative("./../test_helper.rb")
4
4
  require("minitest/hooks/test")
5
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
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
- 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
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
- 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
42
+ def test_configurations
43
+ configs = @service.list_configurations(
44
+ environment_id: @environment_id
45
+ ).result
46
+ refute(configs.nil?)
74
47
 
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(
48
+ name = "test" + ("A".."Z").to_a.sample
49
+ new_configuration_id = @service.create_configuration(
90
50
  environment_id: @environment_id,
91
- collection_id: new_collection_id
51
+ name: name,
52
+ description: "creating new config for ruby sdk"
92
53
  ).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
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
- 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(
61
+ updated_config = @service.update_configuration(
138
62
  environment_id: @environment_id,
139
- collection_id: @collection_id,
140
- file: file_info
63
+ configuration_id: new_configuration_id,
64
+ name: "lala"
141
65
  ).result
142
- end
143
- add_doc = add_doc
144
- refute(add_doc["document_id"].nil?)
66
+ updated_config = updated_config
67
+ assert_equal("lala", updated_config["name"])
145
68
 
146
- doc_status = { "status" => "processing" }
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
- collection_id: @collection_id,
152
- document_id: add_doc["document_id"]
71
+ configuration_id: new_configuration_id
153
72
  ).result
154
- doc_status = doc_status
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
- update_doc = nil
159
- File.open(Dir.getwd + "/resources/simple.html") do |file_info|
160
- update_doc = @service.update_document(
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
- collection_id: @collection_id,
163
- document_id: add_doc["document_id"],
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
- doc_status = { "status" => "processing" }
171
- while doc_status["status"] == "processing"
172
- sleep(1)
173
- doc_status = @service.get_document_status(
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
- doc_status = doc_status
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
- 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?)
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