Skip to content

Commit cc9cc72

Browse files
committed
test(LanguageTransltor): Add integration tests for document translation
1 parent 24d261d commit cc9cc72

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

resources/translation_doc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
How are you?

test/integration/test_language_translator_v3.rb

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def before_all
1717
)
1818
@service.add_default_headers(
1919
headers: {
20-
"X-Watson-Learning-Opt-Out" => "1",
2120
"X-Watson-Test" => "1"
2221
}
2322
)
@@ -59,6 +58,42 @@ def test_identify
5958
refute(service_response.nil?)
6059
end
6160

61+
def test_translate_document
62+
@service = IBMWatson::LanguageTranslatorV3.new(
63+
iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
64+
url: ENV["LANGUAGE_TRANSLATOR_URL"],
65+
version: "2018-05-01"
66+
)
67+
@service.add_default_headers(
68+
headers: {
69+
"X-Watson-Test" => "1"
70+
}
71+
)
72+
73+
File.open(Dir.getwd + "/resources/translation_doc.txt") do |file_info|
74+
service_response = service.translate_document(
75+
file: file_info,
76+
model_id: "en-fr"
77+
).result
78+
refute(service_response.nil?)
79+
end
80+
end
81+
82+
def test_list_documents
83+
@service = IBMWatson::LanguageTranslatorV3.new(
84+
iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
85+
url: ENV["LANGUAGE_TRANSLATOR_URL"],
86+
version: "2018-05-01"
87+
)
88+
@service.add_default_headers(
89+
headers: {
90+
"X-Watson-Test" => "1"
91+
}
92+
)
93+
service_response = service.list_documents.result
94+
refute(service_response.nil?)
95+
end
96+
6297
def test_list_identifiable_languages
6398
service_response = service.list_identifiable_languages.result
6499
refute(service_response.nil?)

test/unit/test_language_translator_v3.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def test_translate_document
525525
assert_equal req.headers["Accept"], "application/json"
526526
assert_match %r{\Amultipart/form-data}, req.headers["Content-Type"]
527527
end
528-
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
528+
file = File.open(Dir.getwd + "/resources/translation_doc.txt")
529529
service.translate_document(file: file, filename: "file")
530530
end
531531

0 commit comments

Comments
 (0)