Skip to content

Commit 3779e7c

Browse files
maxnussbaumGERMAN ATTANASIO RUIZ
authored andcommitted
test(visual recognition): Add more tests for visual recognition
1 parent 9863630 commit 3779e7c

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

test/unit/test_visual_recognition_v3.rb

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
class VisualRecognitionV3Test < Minitest::Test
1111
def test_get_classifier
1212
service = WatsonAPIs::VisualRecognitionV3.new(
13-
version: "2018-03-19",
14-
iam_access_token: "bogus_access_token"
13+
version: "2018-03-19"
1514
)
15+
service._iam_access_token(iam_access_token: "bogus_access_token")
16+
service._iam_access_token(iam_access_token: "bogus_access_token")
1617
response = {
1718
"classifier_id" => "bogusnumber",
1819
"name" => "Dog Breeds",
@@ -120,6 +121,15 @@ def test_create_classifier
120121
negative_examples: trucks
121122
)
122123
assert_equal(response, service_response.body)
124+
125+
service_response = service.create_classifier(
126+
name: "Cars vs Trucks",
127+
classname_positive_examples: "cars",
128+
classname_positive_examples_filename: "cars",
129+
negative_examples: "trucks",
130+
negative_examples_filename: "trucks"
131+
)
132+
assert_equal(response, service_response.body)
123133
end
124134

125135
def test_update_classifier
@@ -143,13 +153,23 @@ def test_update_classifier
143153
.with(
144154
headers: {
145155
"Accept" => "application/json",
146-
"Content-Type" => "application/x-www-form-urlencoded",
147156
"Host" => "gateway.watsonplatform.net",
148157
"Authorization" => "Bearer bogus_access_token"
149158
}
150159
).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
151160
service_response = service.update_classifier(
152-
classifier_id: "bogusid"
161+
classifier_id: "bogusid",
162+
classname_positive_examples: "positive examples classname",
163+
negative_examples: "negative examples"
164+
)
165+
assert_equal(response, service_response.body)
166+
167+
service_response = service.update_classifier(
168+
classifier_id: "bogusid",
169+
classname_positive_examples: "positive examples file",
170+
classname_positive_examples_filename: "positive_filename",
171+
negative_examples: "negative examples",
172+
negative_examples_filename: "negative_filename"
153173
)
154174
assert_equal(response, service_response.body)
155175
end
@@ -213,7 +233,13 @@ def test_classify
213233

214234
image_file = File.open(Dir.getwd + "/resources/test.jpg")
215235
service_response = service.classify(
216-
images_file: image_file
236+
images_file: image_file,
237+
images_filename: "test.jpg"
238+
)
239+
assert_equal(response, service_response.body)
240+
241+
service_response = service.classify(
242+
images_file: "image_file"
217243
)
218244
assert_equal(response, service_response.body)
219245
end
@@ -271,7 +297,13 @@ def test_detect_faces
271297

272298
image_file = File.open(Dir.getwd + "/resources/test.jpg")
273299
service_response = service.detect_faces(
274-
images_file: image_file
300+
images_file: image_file,
301+
images_filename: "test.jpg"
302+
)
303+
assert_equal(response, service_response.body)
304+
305+
service_response = service.detect_faces(
306+
images_file: "image_file"
275307
)
276308
assert_equal(response, service_response.body)
277309
end
@@ -294,4 +326,20 @@ def test_delete_user_data
294326
)
295327
assert_nil(service_response)
296328
end
329+
330+
def test_get_core_ml_model
331+
service = WatsonAPIs::VisualRecognitionV3.new(
332+
version: "2018-03-19",
333+
iam_access_token: "bogus_access_token"
334+
)
335+
stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers/classifierid/core_ml_model?version=2018-03-19")
336+
.with(
337+
headers: {
338+
"Authorization" => "Bearer bogus_access_token",
339+
"Host" => "gateway.watsonplatform.net"
340+
}
341+
).to_return(status: 200, body: "ml_model", headers: {})
342+
service_response = service.get_core_ml_model(classifier_id: "classifierid")
343+
assert_equal("ml_model", service_response.body)
344+
end
297345
end

0 commit comments

Comments
 (0)