Skip to content

Commit 017dd95

Browse files
authored
Merge pull request #574 from watson-developer-cloud/release-2.2.0
Release 2.2.0
2 parents 7be6a4f + 751e332 commit 017dd95

18 files changed

Lines changed: 935 additions & 623 deletions

.env.enc

0 Bytes
Binary file not shown.

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ deploy:
3434
script: docs/publish.sh
3535
skip_cleanup: true
3636
on:
37-
python: '2.7'
37+
python: '3.5'
3838
branch: master
3939
- provider: script
4040
script: npx semantic-release
4141
skip_cleanup: true
4242
on:
43-
python: '2.7'
43+
python: '3.5'
4444
branch: master
4545
- provider: pypi
4646
user: ehdsouza
@@ -49,5 +49,5 @@ deploy:
4949
repository: https://upload.pypi.org/legacy
5050
skip_cleanup: true
5151
on:
52-
python: '2.7'
52+
python: '3.5'
5353
branch: master

README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
1919
* [Getting credentials](#getting-credentials)
2020
* [IAM](#iam)
2121
* [Username and password](#username-and-password)
22-
* [API key](#api-key)
2322
* [Python version](#python-version)
2423
* [Changes for v1.0](#changes-for-v10)
2524
* [Changes for v2.0](#changes-for-v20)
@@ -71,7 +70,10 @@ For more details see [#405](https://github.com/watson-developer-cloud/python-sdk
7170

7271
## Examples
7372

74-
The [examples][examples] folder has basic and advanced examples. The examples within each service assume that you already have [service credentials](#getting-credentials).
73+
The [examples][examples] folder has basic and advanced examples. The examples within each service assume that you already have [service credentials](#getting-credentials).
74+
75+
Note:
76+
Conversation V1 is deprecated and will be removed in the next major release of the SDK. Use Assistant V1 or Assistant V2.
7577

7678
## Running in IBM Cloud
7779

@@ -83,7 +85,6 @@ Watson services are migrating to token-based Identity and Access Management (IAM
8385

8486
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
8587
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
86-
- Visual Recognition uses a form of [API key](#api-key) only with instances created before May 23, 2018. Newer instances of Visual Recognition use IAM.
8788

8889
**Note:** Authenticating with the X-Watson-Authorization-Token header is deprecated. The token continues to work with Cloud Foundry services, but is not supported for services that use Identity and Access Management (IAM) authentication. See [here](#iam) for details.
8990

@@ -146,22 +147,6 @@ discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>')
146147
discovery.set_username_and_password('<username>', '<password>')
147148
```
148149

149-
### API key
150-
151-
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
152-
153-
```python
154-
from watson_developer_cloud import VisualRecognitionV3
155-
# In the constructor
156-
visual_recognition = VisualRecognitionV3(version='2018-03-19', url='<url_as_per_region>', api_key='<api_key>')
157-
```
158-
159-
```python
160-
# After instantiation
161-
visual_recognition = VisualRecognitionV3(version='2018-03-19')
162-
visual_recognition.set_api_key('<api_key>')
163-
```
164-
165150
## Python version
166151

167152
Tested on Python 2.7, 3.4, 3.5, and 3.6.

examples/visual_recognition_v3.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
test_url = 'https://www.ibm.com/ibm/ginni/images' \
77
'/ginni_bio_780x981_v4_03162016.jpg'
88

9-
# # If service instance provides IAM API key authentication
10-
# service = VisualRecognitionV3(
11-
# '2018-03-19',
12-
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
13-
# url='https://gateway.watsonplatform.net/visual-recognition/api',
14-
# iam_apikey='iam_apikey')
15-
16-
service = VisualRecognitionV3('2018-03-19',
17-
## url is optional, and defaults to the URL below. Use the correct URL for your region.
18-
# url='https://gateway.watsonplatform.net/visual-recognition/api',
19-
api_key='YOUR API KEY')
9+
# If service instance provides IAM API key authentication
10+
service = VisualRecognitionV3(
11+
'2018-03-19',
12+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
13+
url='https://gateway.watsonplatform.net/visual-recognition/api',
14+
iam_apikey='iam_apikey')
2015

2116
# with open(abspath('resources/cars.zip'), 'rb') as cars, \
2217
# open(abspath('resources/trucks.zip'), 'rb') as trucks:

test/integration/test_visual_recognition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class IntegrationTestVisualRecognitionV3(TestCase):
1414
@classmethod
1515
def setup_class(cls):
1616
cls.visual_recognition = watson_developer_cloud.VisualRecognitionV3(
17-
'2018-03-19', api_key='YOUR API KEY')
17+
'2018-03-19', iam_apikey='YOUR IAM API KEY')
1818
cls.visual_recognition.set_default_headers({
1919
'X-Watson-Learning-Opt-Out':
2020
'1',
2121
'X-Watson-Test':
2222
'1'
2323
})
24-
cls.classifier_id = 'doxnotxdeletexintegrationxtest_397877192'
24+
cls.classifier_id = 'sdkxtestxclassifierxdoxnotxdel_1089651138'
2525

2626
def test_classify(self):
2727
dog_path = abspath('resources/dog.jpg')
@@ -37,7 +37,7 @@ def test_detect_faces(self):
3737
url='https://www.ibm.com/ibm/ginni/images/ginni_bio_780x981_v4_03162016.jpg').get_result()
3838
assert output is not None
3939

40-
# @pytest.mark.skip(reason="Time consuming")
40+
@pytest.mark.skip(reason="Time consuming")
4141
def test_custom_classifier(self):
4242
with open(abspath('resources/cars.zip'), 'rb') as cars, \
4343
open(abspath('resources/trucks.zip'), 'rb') as trucks:

test/unit/test_discovery_v1.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_federated_query():
219219
discovery_url = urljoin(base_discovery_url,
220220
'environments/envid/query')
221221

222-
responses.add(responses.GET, discovery_url,
222+
responses.add(responses.POST, discovery_url,
223223
body="{\"body\": \"hello\"}", status=200,
224224
content_type='application/json')
225225
discovery = watson_developer_cloud.DiscoveryV1('2016-11-07',
@@ -234,6 +234,29 @@ def test_federated_query():
234234
assert called_url.path == test_url.path
235235
assert len(responses.calls) == 1
236236

237+
@responses.activate
238+
def test_federated_query_2():
239+
discovery_url = urljoin(base_discovery_url,
240+
'environments/envid/query')
241+
242+
responses.add(responses.POST, discovery_url,
243+
body="{\"body\": \"hello\"}", status=200,
244+
content_type='application/json')
245+
discovery = watson_developer_cloud.DiscoveryV1('2016-11-07',
246+
username='username',
247+
password='password')
248+
discovery.federated_query('envid', "'collid1', 'collid2'",
249+
filter='colls.sha1::9181d244*',
250+
bias='1',
251+
logging_opt_out=True)
252+
253+
called_url = urlparse(responses.calls[0].request.url)
254+
test_url = urlparse(discovery_url)
255+
256+
assert called_url.netloc == test_url.netloc
257+
assert called_url.path == test_url.path
258+
assert len(responses.calls) == 1
259+
237260
@responses.activate
238261
def test_federated_query_notices():
239262
discovery_url = urljoin(base_discovery_url,
@@ -259,7 +282,7 @@ def test_query():
259282
discovery_url = urljoin(base_discovery_url,
260283
'environments/envid/collections/collid/query')
261284

262-
responses.add(responses.GET, discovery_url,
285+
responses.add(responses.POST, discovery_url,
263286
body="{\"body\": \"hello\"}", status=200,
264287
content_type='application/json')
265288
discovery = watson_developer_cloud.DiscoveryV1('2016-11-07',
@@ -280,6 +303,34 @@ def test_query():
280303
assert called_url.path == test_url.path
281304
assert len(responses.calls) == 1
282305

306+
@responses.activate
307+
def test_query_2():
308+
discovery_url = urljoin(base_discovery_url,
309+
'environments/envid/collections/collid/query')
310+
311+
responses.add(responses.POST, discovery_url,
312+
body="{\"body\": \"hello\"}", status=200,
313+
content_type='application/json')
314+
discovery = watson_developer_cloud.DiscoveryV1('2016-11-07',
315+
username='username',
316+
password='password')
317+
discovery.query('envid', 'collid',
318+
filter='extracted_metadata.sha1::9181d244*',
319+
count=1,
320+
passages=True,
321+
passages_fields=['x', 'y'],
322+
logging_opt_out='True',
323+
passages_count=2,
324+
bias='1',
325+
collection_ids='1,2')
326+
327+
called_url = urlparse(responses.calls[0].request.url)
328+
test_url = urlparse(discovery_url)
329+
330+
assert called_url.netloc == test_url.netloc
331+
assert called_url.path == test_url.path
332+
assert len(responses.calls) == 1
333+
283334
@responses.activate
284335
def test_query_relations():
285336
discovery_url = urljoin(

test/unit/test_visual_recognition_v3.py

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@
66

77
from unittest import TestCase
88

9-
base_url = "https://gateway-a.watsonplatform.net/visual-recognition/api/"
9+
base_url = "https://gateway.watsonplatform.net/visual-recognition/api/"
1010

1111
class TestVisualRecognitionV3(TestCase):
12+
@classmethod
13+
def setUp(cls):
14+
iam_url = "https://iam.bluemix.net/identity/token"
15+
iam_token_response = """{
16+
"access_token": "oAeisG8yqPY7sFR_x66Z15",
17+
"token_type": "Bearer",
18+
"expires_in": 3600,
19+
"expiration": 1524167011,
20+
"refresh_token": "jy4gl91BQ"
21+
}"""
22+
responses.add(responses.POST, url=iam_url, body=iam_token_response, status=200)
23+
1224
@responses.activate
1325
def test_get_classifier(self):
14-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
26+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
1527

1628
gc_url = "{0}{1}".format(base_url, 'v3/classifiers/bogusnumber')
1729

@@ -31,11 +43,11 @@ def test_get_classifier(self):
3143
content_type='application/json')
3244
vr_service.get_classifier(classifier_id='bogusnumber')
3345

34-
assert len(responses.calls) == 1
46+
assert len(responses.calls) == 2
3547

3648
@responses.activate
3749
def test_delete_classifier(self):
38-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
50+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
3951

4052
gc_url = "{0}{1}".format(base_url, 'v3/classifiers/bogusnumber')
4153

@@ -46,11 +58,11 @@ def test_delete_classifier(self):
4658
content_type='application/json')
4759
vr_service.delete_classifier(classifier_id='bogusnumber')
4860

49-
assert len(responses.calls) == 1
61+
assert len(responses.calls) == 2
5062

5163
@responses.activate
5264
def test_list_classifiers(self):
53-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
65+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
5466

5567
gc_url = "{0}{1}".format(base_url, 'v3/classifiers')
5668

@@ -74,11 +86,11 @@ def test_list_classifiers(self):
7486
content_type='application/json')
7587
vr_service.list_classifiers()
7688

77-
assert len(responses.calls) == 1
89+
assert len(responses.calls) == 2
7890

7991
@responses.activate
8092
def test_create_classifier(self):
81-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
93+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
8294

8395
gc_url = "{0}{1}".format(base_url, 'v3/classifiers')
8496

@@ -101,11 +113,11 @@ def test_create_classifier(self):
101113
open(os.path.join(os.path.dirname(__file__), '../../resources/trucks.zip'), 'rb') as trucks:
102114
vr_service.create_classifier('Cars vs Trucks', cars_positive_examples=cars, negative_examples=trucks)
103115

104-
assert len(responses.calls) == 1
116+
assert len(responses.calls) == 2
105117

106118
@responses.activate
107119
def test_update_classifier(self):
108-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
120+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
109121

110122
gc_url = "{0}{1}".format(base_url, 'v3/classifiers/bogusid')
111123

@@ -129,11 +141,11 @@ def test_update_classifier(self):
129141
content_type='application/json')
130142

131143
vr_service.update_classifier(classifier_id="bogusid")
132-
assert len(responses.calls) == 1
144+
assert len(responses.calls) == 2
133145

134146
@responses.activate
135147
def test_classify(self):
136-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
148+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
137149

138150
gc_url = "{0}{1}".format(base_url, 'v3/classify')
139151

@@ -175,11 +187,11 @@ def test_classify(self):
175187

176188
with open(os.path.join(os.path.dirname(__file__), '../../resources/test.jpg'), 'rb') as image_file:
177189
vr_service.classify(images_file=image_file)
178-
assert len(responses.calls) == 4
190+
assert len(responses.calls) == 8
179191

180192
@responses.activate
181193
def test_detect_faces(self):
182-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
194+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
183195

184196
gc_url = "{0}{1}".format(base_url, 'v3/detect_faces')
185197

@@ -232,19 +244,19 @@ def test_detect_faces(self):
232244
vr_service.detect_faces(parameters='{"url": "http://google.com"}')
233245
with open(os.path.join(os.path.dirname(__file__), '../../resources/test.jpg'), 'rb') as image_file:
234246
vr_service.detect_faces(images_file=image_file)
235-
assert len(responses.calls) == 2
247+
assert len(responses.calls) == 4
236248

237-
@responses.activate
238-
def test_delete_user_data():
239-
url = "{0}{1}".format(base_url, 'v3/user_data')
240-
responses.add(
241-
responses.DELETE,
242-
url,
243-
body='{"description": "success" }',
244-
status=204,
245-
content_type='application_json')
246-
247-
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
248-
response = vr_service.delete_user_data('id').get_result()
249-
assert response is None
250-
assert len(responses.calls) == 1
249+
@responses.activate
250+
def test_delete_user_data(self):
251+
url = "{0}{1}".format(base_url, 'v3/user_data')
252+
responses.add(
253+
responses.DELETE,
254+
url,
255+
body='{"description": "success" }',
256+
status=204,
257+
content_type='application_json')
258+
259+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', iam_apikey='bogusapikey')
260+
response = vr_service.delete_user_data('id').get_result()
261+
assert response is None
262+
assert len(responses.calls) == 2

test/unit/test_watson_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_when_apikey_is_username():
150150

151151
@responses.activate
152152
def test_for_icp():
153-
service1 = AnyServiceV1('2017-07-07', api_key='icp-xxxx', url='service_url')
153+
service1 = AnyServiceV1('2017-07-07', username='apikey', password='icp-xxxx', url='service_url')
154154
assert service1.token_manager is None
155155
assert service1.iam_apikey is None
156156
assert service1.username is not None
@@ -166,7 +166,7 @@ def test_for_icp():
166166

167167
@responses.activate
168168
def test_disable_SSL_verification():
169-
service1 = AnyServiceV1('2017-07-07', api_key='icp-xxxx', url='service_url')
169+
service1 = AnyServiceV1('2017-07-07', username='apikey', password='icp-xxxx', url='service_url')
170170
assert service1.verify is None
171171

172172
service1.disable_SSL_verification()

watson_developer_cloud/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
from .version import __version__
3333
from .speech_to_text_v1_adapter import SpeechToTextV1Adapter as SpeechToTextV1
3434
from .visual_recognition_v3_adapter import VisualRecognitionV3Adapter as VisualRecognitionV3
35+
from .discovery_v1_adapter import DiscoveryV1Adapter as DiscoveryV1

0 commit comments

Comments
 (0)