Skip to content

Commit 1cef126

Browse files
committed
test: update tests for new auth methods
1 parent 222eafe commit 1cef126

29 files changed

Lines changed: 1030 additions & 522 deletions

resources/vcap-testing.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"personality_insights": [
2+
"sample_service": [
33
{
44
"credentials": {
55
"password": "password",
66
"url": "https://gateway.watsonplatform.net/personality-insights/api",
77
"username": "username"
88
},
9-
"label": "personality_insights",
10-
"name": "personality-insights-service",
9+
"label": "personality",
10+
"name": "personality",
1111
"plan": "standard",
1212
"tags": [
1313
"watson",

test/integration/test_assistant_v1.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
require_relative("./../test_helper.rb")
44
SimpleCov.command_name "test:integration"
55
require("minitest/hooks/test")
6+
require("ibm_cloud_sdk_core")
67

78
if !ENV["ASSISTANT_APIKEY"].nil? && !ENV["ASSISTANT_URL"].nil?
89
# Integration tests for the Watson Assistant V1 Service
910
class AssistantV1Test < Minitest::Test
1011
include Minitest::Hooks
1112
attr_accessor :service
1213
def before_all
14+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
15+
apikey: ENV["ASSISTANT_APIKEY"],
16+
version: "2018-02-16"
17+
)
1318
@service = IBMWatson::AssistantV1.new(
14-
iam_apikey: ENV["ASSISTANT_APIKEY"],
19+
version: "2018-02-16",
1520
url: ENV["ASSISTANT_URL"],
16-
version: "2018-02-16"
21+
authenticator: authenticator
1722
)
1823
@service.add_default_headers(
1924
headers: {
@@ -51,8 +56,7 @@ def test_create_update_delete_workspace
5156

5257
def test_get_workspace
5358
service_response = service.get_workspace(
54-
workspace_id: ENV["ASSISTANT_WORKSPACE_ID"],
55-
export: false
59+
workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
5660
)
5761
assert((200..299).cover?(service_response.status))
5862
end

test/integration/test_assistant_v2.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
require_relative("./../test_helper.rb")
44
SimpleCov.command_name "test:integration"
5+
require("minitest/hooks/test")
6+
require("ibm_cloud_sdk_core")
57

68
if !ENV["ASSISTANT_APIKEY"].nil? && !ENV["ASSISTANT_URL"].nil?
79
# Integration tests for the Watson Assistant V2 Service
810
class AssistantV2Test < Minitest::Test
911
include Minitest::Hooks
1012
attr_accessor :service
1113
def before_all
14+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
15+
apikey: ENV["ASSISTANT_APIKEY"]
16+
)
1217
@service = IBMWatson::AssistantV2.new(
1318
version: "2018-12-31",
14-
iam_apikey: ENV["ASSISTANT_APIKEY"],
19+
authenticator: authenticator,
1520
url: ENV["ASSISTANT_URL"],
1621
assistant_id: ENV["ASSISTANT_ASSISTANT_ID"]
1722
)

test/integration/test_compare_comply_v1.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require_relative("./../test_helper.rb")
44
require("minitest/hooks/test")
5+
require("ibm_cloud_sdk_core")
56

67
if !ENV["COMPARE_COMPLY_APIKEY"].nil?
78
# Integration tests for the Discovery V1 Service
@@ -10,9 +11,12 @@ class CompareComplyV1Test < Minitest::Test
1011
attr_accessor :service, :environment_id, :collection_id
1112

1213
def before_all
14+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
15+
apikey: ENV["ASSISTANT_APIKEY"]
16+
)
1317
@service = IBMWatson::CompareComplyV1.new(
14-
iam_apikey: ENV["COMPARE_COMPLY_APIKEY"],
15-
version: "2018-10-15"
18+
version: "2018-10-15",
19+
authenticator: authenticator
1620
)
1721
@service.add_default_headers(
1822
headers: {

test/integration/test_discovery_v1.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ class DiscoveryV1Test < Minitest::Test
1010
attr_accessor :service, :environment_id, :collection_id
1111

1212
def before_all
13+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
14+
apikey: ENV["DISCOVERY_APIKEY"]
15+
)
1316
@service = IBMWatson::DiscoveryV1.new(
14-
iam_apikey: ENV["DISCOVERY_APIKEY"],
17+
authenticator: authenticator,
1518
url: ENV["DISCOVERY_URL"],
1619
version: "2018-03-05"
1720
)

test/integration/test_language_translator_v3.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ class LanguageTranslatorV3Test < Minitest::Test
1010
include Minitest::Hooks
1111
attr_accessor :service
1212
def before_all
13+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
14+
apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"]
15+
)
1316
@service = IBMWatson::LanguageTranslatorV3.new(
14-
iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
17+
authenticator: authenticator,
1518
url: ENV["LANGUAGE_TRANSLATOR_URL"],
1619
version: "2018-05-01"
1720
)
@@ -59,11 +62,6 @@ def test_identify
5962
end
6063

6164
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-
)
6765
@service.add_default_headers(
6866
headers: {
6967
"X-Watson-Test" => "1"
@@ -81,16 +79,6 @@ def test_translate_document
8179
end
8280

8381
def test_list_documents
84-
@service = IBMWatson::LanguageTranslatorV3.new(
85-
iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
86-
url: ENV["LANGUAGE_TRANSLATOR_URL"],
87-
version: "2018-05-01"
88-
)
89-
@service.add_default_headers(
90-
headers: {
91-
"X-Watson-Test" => "1"
92-
}
93-
)
9482
service_response = service.list_documents.result
9583
refute(service_response.nil?)
9684
end

test/integration/test_natural_language_classifier_v1.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ class NaturalLanguageClassifierV1Test < Minitest::Test
1010
include Minitest::Hooks
1111
attr_accessor :service
1212
def before_all
13+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
14+
apikey: ENV["NATURAL_LANGUAGE_CLASSIFIER_APIKEY"]
15+
)
1316
@service = IBMWatson::NaturalLanguageClassifierV1.new(
14-
iam_apikey: ENV["NATURAL_LANGUAGE_CLASSIFIER_APIKEY"],
17+
authenticator: authenticator,
1518
url: ENV["NATURAL_LANGUAGE_CLASSIFIER_URL"]
1619
)
1720
@service.add_default_headers(

test/integration/test_natural_language_understanding_v1.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ class NaturalLanguageUnderstandingV1Test < Minitest::Test
99
include Minitest::Hooks
1010
attr_accessor :service
1111
def before_all
12+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
13+
apikey: ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"]
14+
)
1215
@service = IBMWatson::NaturalLanguageUnderstandingV1.new(
1316
version: "2018-03-16",
14-
iam_apikey: ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"],
17+
authenticator: authenticator,
1518
url: ENV["NATURAL_LANGUAGE_UNDERSTANDING_URL"]
1619
)
1720
@service.add_default_headers(

test/integration/test_personality_insights_v3.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ class PersonalityInsightsV3Test < Minitest::Test
99
include Minitest::Hooks
1010
attr_accessor :service
1111
def before_all
12+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
13+
apikey: ENV["PERSONALITY_INSIGHTS_APIKEY"]
14+
)
1215
@service = IBMWatson::PersonalityInsightsV3.new(
1316
version: "2017-10-13",
14-
iam_apikey: ENV["PERSONALITY_INSIGHTS_APIKEY"],
15-
url: ENV["PERSONALITY_INSIGHTS_URL"]
17+
url: ENV["PERSONALITY_INSIGHTS_URL"],
18+
authenticator: authenticator
1619
)
1720
@service.add_default_headers(
1821
headers: {

test/integration/test_speech_to_text_v1.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ class SpeechToTextV1Test < Minitest::Test
2828
include Minitest::Hooks
2929
attr_accessor :service
3030
def before_all
31+
authenticator = IBMCloudSdkCore::IamAuthenticator.new(
32+
apikey: ENV["SPEECH_TO_TEXT_APIKEY"]
33+
)
3134
@service = IBMWatson::SpeechToTextV1.new(
32-
iam_apikey: ENV["SPEECH_TO_TEXT_APIKEY"],
33-
url: ENV["SPEECH_TO_TEXT_URL"]
35+
url: ENV["SPEECH_TO_TEXT_URL"],
36+
authenticator: authenticator
3437
)
3538
@service.add_default_headers(
3639
headers: {
@@ -243,8 +246,11 @@ def test_invalid_auth_using_websocket
243246
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
244247
atomic_boolean = Concurrent::AtomicBoolean.new
245248
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
249+
authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
250+
bearer_token: "bogus_iam_access_token"
251+
)
246252
temp_service = IBMWatson::SpeechToTextV1.new(
247-
iam_access_token: "bogus_iam_access_token"
253+
authenticator: authenticator
248254
)
249255
temp_service.add_default_headers(
250256
headers: {

0 commit comments

Comments
 (0)