ibm_watson 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,237 @@
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 DiscoveryV2Test < Minitest::Test
12
+ include Minitest::Hooks
13
+ attr_accessor :service
14
+ def before_all
15
+ authenticator = IBMWatson::Authenticators::NoAuthAuthenticator.new
16
+ @service = IBMWatson::DiscoveryV2.new(
17
+ version: "2018-03-05",
18
+ authenticator: authenticator,
19
+ service_url: "https://gateway.watsonplatform.net/discovery/api"
20
+ )
21
+ end
22
+
23
+ def test_collections
24
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/collections?version=2018-03-05")
25
+ .with(
26
+ headers: {
27
+ "Accept" => "application/json",
28
+ "Host" => "gateway.watsonplatform.net"
29
+ }
30
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
31
+ service_response = service.list_collections(
32
+ project_id: "project"
33
+ )
34
+ assert_equal({ "body" => "hello" }, service_response.result)
35
+ end
36
+
37
+ def test_query
38
+ stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/query?version=2018-03-05")
39
+ .with(
40
+ body: "{\"count\":10}",
41
+ headers: {
42
+ "Accept" => "application/json",
43
+ "Host" => "gateway.watsonplatform.net"
44
+ }
45
+ ).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
46
+ service_response = service.query(
47
+ project_id: "project",
48
+ count: 10
49
+ )
50
+ assert_equal({ "body" => "hello" }, service_response.result)
51
+ end
52
+
53
+ def test_get_autocompletion
54
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/autocompletion?prefix=hi&version=2018-03-05")
55
+ .with(
56
+ headers: {
57
+ "Accept" => "application/json",
58
+ "Host" => "gateway.watsonplatform.net"
59
+ }
60
+ ).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
61
+ service_response = service.get_autocompletion(
62
+ project_id: "project",
63
+ prefix: "hi"
64
+ )
65
+ assert_equal({ "received" => "true" }, service_response.result)
66
+ end
67
+
68
+ def test_query_notices
69
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/notices?version=2018-03-05")
70
+ .with(
71
+ headers: {
72
+ "Accept" => "application/json",
73
+ "Host" => "gateway.watsonplatform.net"
74
+ }
75
+ ).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
76
+ service_response = service.query_notices(
77
+ project_id: "project"
78
+ )
79
+ assert_equal({ "received" => "true" }, service_response.result)
80
+ end
81
+
82
+ def test_list_fields
83
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/fields?collection_ids=collid&version=2018-03-05")
84
+ .with(
85
+ headers: {
86
+ "Accept" => "application/json",
87
+ "Host" => "gateway.watsonplatform.net"
88
+ }
89
+ ).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
90
+ service_response = service.list_fields(
91
+ project_id: "project",
92
+ collection_ids: ["collid"]
93
+ )
94
+ assert_equal({ "received" => "true" }, service_response.result)
95
+ end
96
+
97
+ def test_get_component_settings
98
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/component_settings?version=2018-03-05")
99
+ .with(
100
+ headers: {
101
+ "Accept" => "application/json",
102
+ "Host" => "gateway.watsonplatform.net"
103
+ }
104
+ ).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
105
+ service_response = service.get_component_settings(
106
+ project_id: "project"
107
+ )
108
+ assert_equal({ "received" => "true" }, service_response.result)
109
+ end
110
+
111
+ def test_add_document
112
+ stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/collections/collid/documents?version=2018-03-05")
113
+ .with(
114
+ headers: {
115
+ "Accept" => "application/json",
116
+ "Host" => "gateway.watsonplatform.net"
117
+ }
118
+ ).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
119
+ File.open(Dir.getwd + "/resources/simple.html") do |file_info|
120
+ service_response = service.add_document(
121
+ project_id: "project",
122
+ collection_id: "collid",
123
+ file: file_info
124
+ )
125
+ refute(service_response.nil?)
126
+ end
127
+ end
128
+
129
+ def test_update_document
130
+ stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/collections/collid/documents/docid?version=2018-03-05")
131
+ .with(
132
+ headers: {
133
+ "Accept" => "application/json",
134
+ "Host" => "gateway.watsonplatform.net"
135
+ }
136
+ ).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
137
+ service_response = service.update_document(
138
+ project_id: "project",
139
+ collection_id: "collid",
140
+ document_id: "docid",
141
+ file: "file",
142
+ filename: "file.name"
143
+ )
144
+ assert_equal({ "body" => [] }, service_response.result)
145
+ end
146
+
147
+ def test_delete_document
148
+ stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/collections/collid/documents/docid?version=2018-03-05")
149
+ .with(
150
+ headers: {
151
+ "Accept" => "application/json",
152
+ "Host" => "gateway.watsonplatform.net"
153
+ }
154
+ ).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
155
+ service_response = service.delete_document(
156
+ project_id: "project",
157
+ collection_id: "collid",
158
+ document_id: "docid"
159
+ )
160
+ assert_equal({ "body" => [] }, service_response.result)
161
+ end
162
+
163
+ def test_list_training_queries
164
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
165
+ .with(
166
+ headers: {
167
+ "Accept" => "application/json",
168
+ "Host" => "gateway.watsonplatform.net"
169
+ }
170
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
171
+ service_response = service.list_training_queries(
172
+ project_id: "project"
173
+ )
174
+ assert_equal({ "body" => "hello" }, service_response.result)
175
+ end
176
+
177
+ def test_delete_training_queries
178
+ stub_request(:delete, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
179
+ .with(
180
+ headers: {
181
+ "Host" => "gateway.watsonplatform.net"
182
+ }
183
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
184
+ service_response = service.delete_training_queries(
185
+ project_id: "project"
186
+ )
187
+ assert_nil(service_response)
188
+ end
189
+
190
+ def test_create_training_query
191
+ stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
192
+ .with(
193
+ headers: {
194
+ "Accept" => "application/json",
195
+ "Host" => "gateway.watsonplatform.net"
196
+ }
197
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
198
+ service_response = service.create_training_query(
199
+ project_id: "project",
200
+ natural_language_query: "query",
201
+ examples: []
202
+ )
203
+ assert_equal({ "body" => "hello" }, service_response.result)
204
+ end
205
+
206
+ def test_get_training_query
207
+ stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
208
+ .with(
209
+ headers: {
210
+ "Accept" => "application/json",
211
+ "Host" => "gateway.watsonplatform.net"
212
+ }
213
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
214
+ service_response = service.get_training_query(
215
+ project_id: "project",
216
+ query_id: "queryid"
217
+ )
218
+ assert_equal({ "body" => "hello" }, service_response.result)
219
+ end
220
+
221
+ def test_update_training_query
222
+ stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
223
+ .with(
224
+ headers: {
225
+ "Accept" => "application/json",
226
+ "Host" => "gateway.watsonplatform.net"
227
+ }
228
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
229
+ service_response = service.update_training_query(
230
+ project_id: "project",
231
+ query_id: "queryid",
232
+ natural_language_query: "query",
233
+ examples: []
234
+ )
235
+ assert_equal({ "body" => "hello" }, service_response.result)
236
+ end
237
+ end
@@ -8,14 +8,17 @@ WebMock.disable_net_connect!(allow_localhost: true)
8
8
 
9
9
  # Unit tests for the Visual Recognition V3 Service
10
10
  class VisualRecognitionV4Test < Minitest::Test
11
- def test_analyze
12
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
13
- bearer_token: "bogus_access_token"
14
- )
15
- service = IBMWatson::VisualRecognitionV4.new(
11
+ include Minitest::Hooks
12
+ attr_accessor :service
13
+ def before_all
14
+ authenticator = IBMWatson::Authenticators::NoAuthAuthenticator.new
15
+ @service = IBMWatson::VisualRecognitionV4.new(
16
16
  version: "2018-03-19",
17
17
  authenticator: authenticator
18
18
  )
19
+ end
20
+
21
+ def test_analyze
19
22
  file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
20
23
  stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/analyze?version=2018-03-19").with do |req|
21
24
  assert_equal(req.headers["Accept"], "application/json")
@@ -37,13 +40,6 @@ class VisualRecognitionV4Test < Minitest::Test
37
40
  end
38
41
 
39
42
  def test_analyze_url
40
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
41
- bearer_token: "bogus_access_token"
42
- )
43
- service = IBMWatson::VisualRecognitionV4.new(
44
- version: "2018-03-19",
45
- authenticator: authenticator
46
- )
47
43
  stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/analyze?version=2018-03-19").with do |req|
48
44
  assert_equal(req.headers["Accept"], "application/json")
49
45
  assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
@@ -59,13 +55,6 @@ class VisualRecognitionV4Test < Minitest::Test
59
55
  end
60
56
 
61
57
  def test_create_collection
62
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
63
- bearer_token: "bogus_access_token"
64
- )
65
- service = IBMWatson::VisualRecognitionV4.new(
66
- version: "2018-03-19",
67
- authenticator: authenticator
68
- )
69
58
  response = {
70
59
  "collection_id" => "collid",
71
60
  "name" => "Dog Breeds",
@@ -82,22 +71,17 @@ class VisualRecognitionV4Test < Minitest::Test
82
71
  .with(
83
72
  headers: {
84
73
  "Accept" => "application/json",
85
- "Host" => "gateway.watsonplatform.net",
86
- "Authorization" => "Bearer bogus_access_token"
74
+ "Host" => "gateway.watsonplatform.net"
87
75
  }
88
76
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
89
- service_response = service.create_collection
77
+ service_response = service.create_collection(
78
+ name: "my-collection",
79
+ description: "A description of my collection"
80
+ )
90
81
  assert_equal(response, service_response.result)
91
82
  end
92
83
 
93
84
  def test_list_collections
94
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
95
- bearer_token: "bogus_access_token"
96
- )
97
- service = IBMWatson::VisualRecognitionV4.new(
98
- version: "2018-03-19",
99
- authenticator: authenticator
100
- )
101
85
  response = {
102
86
  "collections" => []
103
87
  }
@@ -105,8 +89,7 @@ class VisualRecognitionV4Test < Minitest::Test
105
89
  .with(
106
90
  headers: {
107
91
  "Accept" => "application/json",
108
- "Host" => "gateway.watsonplatform.net",
109
- "Authorization" => "Bearer bogus_access_token"
92
+ "Host" => "gateway.watsonplatform.net"
110
93
  }
111
94
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
112
95
  service_response = service.list_collections
@@ -114,13 +97,6 @@ class VisualRecognitionV4Test < Minitest::Test
114
97
  end
115
98
 
116
99
  def test_get_collection
117
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
118
- bearer_token: "bogus_access_token"
119
- )
120
- service = IBMWatson::VisualRecognitionV4.new(
121
- version: "2018-03-19",
122
- authenticator: authenticator
123
- )
124
100
  response = {
125
101
  "collection_id" => "collid",
126
102
  "name" => "Dog Breeds",
@@ -137,8 +113,7 @@ class VisualRecognitionV4Test < Minitest::Test
137
113
  .with(
138
114
  headers: {
139
115
  "Accept" => "application/json",
140
- "Host" => "gateway.watsonplatform.net",
141
- "Authorization" => "Bearer bogus_access_token"
116
+ "Host" => "gateway.watsonplatform.net"
142
117
  }
143
118
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
144
119
  service_response = service.get_collection(
@@ -148,13 +123,6 @@ class VisualRecognitionV4Test < Minitest::Test
148
123
  end
149
124
 
150
125
  def test_update_collection
151
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
152
- bearer_token: "bogus_access_token"
153
- )
154
- service = IBMWatson::VisualRecognitionV4.new(
155
- version: "2018-03-19",
156
- authenticator: authenticator
157
- )
158
126
  response = {
159
127
  "collection_id" => "collid",
160
128
  "name" => "Dog Breeds",
@@ -171,8 +139,7 @@ class VisualRecognitionV4Test < Minitest::Test
171
139
  .with(
172
140
  headers: {
173
141
  "Accept" => "application/json",
174
- "Host" => "gateway.watsonplatform.net",
175
- "Authorization" => "Bearer bogus_access_token"
142
+ "Host" => "gateway.watsonplatform.net"
176
143
  }
177
144
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
178
145
  service_response = service.update_collection(
@@ -182,20 +149,12 @@ class VisualRecognitionV4Test < Minitest::Test
182
149
  end
183
150
 
184
151
  def test_delete_collection
185
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
186
- bearer_token: "bogus_access_token"
187
- )
188
- service = IBMWatson::VisualRecognitionV4.new(
189
- version: "2018-03-19",
190
- authenticator: authenticator
191
- )
192
152
  response = {}
193
153
  stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid?version=2018-03-19")
194
154
  .with(
195
155
  headers: {
196
156
  "Accept" => "application/json",
197
- "Host" => "gateway.watsonplatform.net",
198
- "Authorization" => "Bearer bogus_access_token"
157
+ "Host" => "gateway.watsonplatform.net"
199
158
  }
200
159
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
201
160
  service_response = service.delete_collection(
@@ -205,13 +164,6 @@ class VisualRecognitionV4Test < Minitest::Test
205
164
  end
206
165
 
207
166
  def test_add_images
208
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
209
- bearer_token: "bogus_access_token"
210
- )
211
- service = IBMWatson::VisualRecognitionV4.new(
212
- version: "2018-03-19",
213
- authenticator: authenticator
214
- )
215
167
  response = {
216
168
  "collection_id" => "collid"
217
169
  }
@@ -220,8 +172,7 @@ class VisualRecognitionV4Test < Minitest::Test
220
172
  .with(
221
173
  headers: {
222
174
  "Accept" => "application/json",
223
- "Host" => "gateway.watsonplatform.net",
224
- "Authorization" => "Bearer bogus_access_token"
175
+ "Host" => "gateway.watsonplatform.net"
225
176
  }
226
177
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
227
178
  service_response = service.add_images(
@@ -238,13 +189,6 @@ class VisualRecognitionV4Test < Minitest::Test
238
189
  end
239
190
 
240
191
  def test_list_images
241
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
242
- bearer_token: "bogus_access_token"
243
- )
244
- service = IBMWatson::VisualRecognitionV4.new(
245
- version: "2018-03-19",
246
- authenticator: authenticator
247
- )
248
192
  response = {
249
193
  "collections" => []
250
194
  }
@@ -252,8 +196,7 @@ class VisualRecognitionV4Test < Minitest::Test
252
196
  .with(
253
197
  headers: {
254
198
  "Accept" => "application/json",
255
- "Host" => "gateway.watsonplatform.net",
256
- "Authorization" => "Bearer bogus_access_token"
199
+ "Host" => "gateway.watsonplatform.net"
257
200
  }
258
201
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
259
202
  service_response = service.list_images(
@@ -263,13 +206,6 @@ class VisualRecognitionV4Test < Minitest::Test
263
206
  end
264
207
 
265
208
  def test_get_image_details
266
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
267
- bearer_token: "bogus_access_token"
268
- )
269
- service = IBMWatson::VisualRecognitionV4.new(
270
- version: "2018-03-19",
271
- authenticator: authenticator
272
- )
273
209
  response = {
274
210
  "collection_id" => "collid"
275
211
  }
@@ -277,8 +213,7 @@ class VisualRecognitionV4Test < Minitest::Test
277
213
  .with(
278
214
  headers: {
279
215
  "Accept" => "application/json",
280
- "Host" => "gateway.watsonplatform.net",
281
- "Authorization" => "Bearer bogus_access_token"
216
+ "Host" => "gateway.watsonplatform.net"
282
217
  }
283
218
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
284
219
  service_response = service.get_image_details(
@@ -289,20 +224,12 @@ class VisualRecognitionV4Test < Minitest::Test
289
224
  end
290
225
 
291
226
  def test_delete_image
292
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
293
- bearer_token: "bogus_access_token"
294
- )
295
- service = IBMWatson::VisualRecognitionV4.new(
296
- version: "2018-03-19",
297
- authenticator: authenticator
298
- )
299
227
  response = {}
300
228
  stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid?version=2018-03-19")
301
229
  .with(
302
230
  headers: {
303
231
  "Accept" => "application/json",
304
- "Host" => "gateway.watsonplatform.net",
305
- "Authorization" => "Bearer bogus_access_token"
232
+ "Host" => "gateway.watsonplatform.net"
306
233
  }
307
234
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
308
235
  service_response = service.delete_image(
@@ -313,21 +240,13 @@ class VisualRecognitionV4Test < Minitest::Test
313
240
  end
314
241
 
315
242
  def test_get_jpeg_image
316
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
317
- bearer_token: "bogus_access_token"
318
- )
319
- service = IBMWatson::VisualRecognitionV4.new(
320
- version: "2018-03-19",
321
- authenticator: authenticator
322
- )
323
243
  response = {
324
244
  "collection_id" => "collid"
325
245
  }
326
246
  stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid/jpeg?version=2018-03-19")
327
247
  .with(
328
248
  headers: {
329
- "Host" => "gateway.watsonplatform.net",
330
- "Authorization" => "Bearer bogus_access_token"
249
+ "Host" => "gateway.watsonplatform.net"
331
250
  }
332
251
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
333
252
  service_response = service.get_jpeg_image(
@@ -338,21 +257,13 @@ class VisualRecognitionV4Test < Minitest::Test
338
257
  end
339
258
 
340
259
  def test_train
341
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
342
- bearer_token: "bogus_access_token"
343
- )
344
- service = IBMWatson::VisualRecognitionV4.new(
345
- version: "2018-03-19",
346
- authenticator: authenticator
347
- )
348
260
  response = {
349
261
  "collection_id" => "collid"
350
262
  }
351
263
  stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/train?version=2018-03-19")
352
264
  .with(
353
265
  headers: {
354
- "Host" => "gateway.watsonplatform.net",
355
- "Authorization" => "Bearer bogus_access_token"
266
+ "Host" => "gateway.watsonplatform.net"
356
267
  }
357
268
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
358
269
  service_response = service.train(
@@ -362,13 +273,6 @@ class VisualRecognitionV4Test < Minitest::Test
362
273
  end
363
274
 
364
275
  def test_add_image_training_data
365
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
366
- bearer_token: "bogus_access_token"
367
- )
368
- service = IBMWatson::VisualRecognitionV4.new(
369
- version: "2018-03-19",
370
- authenticator: authenticator
371
- )
372
276
  response = {
373
277
  "collection_id" => "collid"
374
278
  }
@@ -376,32 +280,34 @@ class VisualRecognitionV4Test < Minitest::Test
376
280
  .with(
377
281
  headers: {
378
282
  "Accept" => "application/json",
379
- "Host" => "gateway.watsonplatform.net",
380
- "Authorization" => "Bearer bogus_access_token"
283
+ "Host" => "gateway.watsonplatform.net"
381
284
  }
382
285
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
383
286
  service_response = service.add_image_training_data(
384
287
  collection_id: "collid",
385
- image_id: "imageid"
288
+ image_id: "imageid",
289
+ objects: [
290
+ {
291
+ object: "2018-Fit",
292
+ location: {
293
+ top: 5,
294
+ left: 13,
295
+ width: 760,
296
+ height: 419
297
+ }
298
+ }
299
+ ]
386
300
  )
387
301
  assert_equal(response, service_response.result)
388
302
  end
389
303
 
390
304
  def test_delete_user_data
391
- authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
392
- bearer_token: "bogus_access_token"
393
- )
394
- service = IBMWatson::VisualRecognitionV4.new(
395
- version: "2018-03-19",
396
- authenticator: authenticator
397
- )
398
305
  response = {}
399
306
  stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/user_data?version=2018-03-19&customer_id=customer")
400
307
  .with(
401
308
  headers: {
402
309
  "Accept" => "application/json",
403
- "Host" => "gateway.watsonplatform.net",
404
- "Authorization" => "Bearer bogus_access_token"
310
+ "Host" => "gateway.watsonplatform.net"
405
311
  }
406
312
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
407
313
  service_response = service.delete_user_data(
@@ -409,4 +315,21 @@ class VisualRecognitionV4Test < Minitest::Test
409
315
  )
410
316
  assert_nil(service_response)
411
317
  end
318
+
319
+ def test_get_training_usage
320
+ response = {
321
+ "usage" => "usage"
322
+ }
323
+ stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/training_usage?end_time=end&start_time=start&version=2018-03-19")
324
+ .with(
325
+ headers: {
326
+ "Host" => "gateway.watsonplatform.net"
327
+ }
328
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
329
+ service_response = service.get_training_usage(
330
+ start_time: "start",
331
+ end_time: "end"
332
+ )
333
+ assert_equal(response, service_response.result)
334
+ end
412
335
  end