Skip to content

Commit fb185a9

Browse files
committed
test(credential): Add better unit tests
1 parent f9b5190 commit fb185a9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

resources/ibm-credentials.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
VISUAL_RECOGNITION_APIKEY=1234abcd
2+
VISUAL_RECOGNITION_URL=https://stgwat-us-south-mzr-cruiser6.us-south.containers.mybluemix.net/visual-recognition/api
3+
WATSON_APIKEY=5678efgh
4+
WATSON_URL=https://gateway-s.watsonplatform.net/watson/api

test/unit/test_watson_service.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from watson_developer_cloud import WatsonService
55
import time
6+
import os
67

78
import responses
89

@@ -29,7 +30,7 @@ def __init__(self, version, url=default_url, username=None, password=None,
2930
iam_apikey=iam_apikey,
3031
iam_access_token=iam_access_token,
3132
iam_url=iam_url,
32-
display_name='Test')
33+
display_name='Watson')
3334
self.version = version
3435

3536
def op_with_path_params(self, path0, path1):
@@ -221,6 +222,11 @@ def test_has_bad_first_or_last_char():
221222

222223
@responses.activate
223224
def test__set_credential_based_on_type():
224-
service = AnyServiceV1('2018-11-20', username='username', password='password')
225-
service._set_credential_based_on_type('test', 'test_apikey', 'xxx')
226-
assert service.iam_apikey == 'xxx'
225+
file_path = os.path.join(os.path.dirname(__file__), '../../resources/ibm-credentials.env')
226+
os.environ['IBM_CREDENTIALS_FILE'] = file_path
227+
service = AnyServiceV1('2018-11-20')
228+
assert service.iam_apikey == '5678efgh'
229+
del os.environ['IBM_CREDENTIALS_FILE']
230+
231+
service = AnyServiceV1('2018-11-20', username='test', password='test')
232+
assert service.username == 'test'

0 commit comments

Comments
 (0)