Skip to content

Commit 2b63901

Browse files
Merge pull request #386 from watson-developer-cloud/codegen/discovery
Regenerate discovery service
2 parents b705442 + f8d655b commit 2b63901

6 files changed

Lines changed: 166 additions & 34 deletions

File tree

.env.enc

0 Bytes
Binary file not shown.

examples/discovery_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
environment_id=news_environment_id)
2323
print(json.dumps(configurations, indent=2))
2424

25-
query_options = {'query': 'IBM'}
2625
query_results = discovery.query(news_environment_id,
2726
news_collections[0]['collection_id'],
28-
query_options)
27+
filter='extracted_metadata.sha1::f5*',
28+
return_fields='extracted_metadata.sha1')
2929
print(json.dumps(query_results, indent=2))
3030

3131
# new_environment = discovery.create_environment(name="new env", description="bogus env")

test/integration/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
# Copyright 2015 IBM All Rights Reserved.
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# coding: utf-8
2+
3+
from unittest import TestCase
4+
import os
5+
import watson_developer_cloud
6+
import json
7+
import random
8+
9+
class Discoveryv1(TestCase):
10+
def setUp(self):
11+
self.discovery = watson_developer_cloud.DiscoveryV1(
12+
version='2017-10-16',
13+
username=os.getenv('DISCOVERY_TO_TEXT_USERNAME'),
14+
password=os.getenv('DISCOVERY_TO_TEXT_PASSWORD'))
15+
self.discovery.set_default_headers({'X-Watson-Learning-Opt-Out': '1', 'X-Watson-Test': '1'})
16+
self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
17+
self.collection_id = self.discovery.list_collections(self.environment_id)['collections'][0]['collection_id']
18+
19+
def test_environments(self):
20+
envs = self.discovery.list_environments()
21+
assert envs is not None
22+
env = self.discovery.get_environment(envs['environments'][0]['environment_id'])
23+
assert env is not None
24+
fields = self.discovery.list_fields(self.environment_id, self.collection_id)
25+
assert fields is not None
26+
27+
def test_configurations(self):
28+
configs = self.discovery.list_configurations(self.environment_id)
29+
assert configs is not None
30+
new_configuration_id = self.discovery.create_configuration(self.environment_id, 'test', 'creating new config for python sdk')['configuration_id']
31+
assert new_configuration_id is not None
32+
self.discovery.get_configuration(self.environment_id, new_configuration_id)
33+
updated_config = self.discovery.update_configuration(self.environment_id, new_configuration_id, 'lala')
34+
assert updated_config['name'] == 'lala'
35+
deleted_config = self.discovery.delete_configuration(self.environment_id, new_configuration_id)
36+
assert deleted_config['status'] == 'deleted'
37+
38+
def test_collections_and_expansions(self):
39+
new_collection_id = self.discovery.create_collection(self.environment_id,
40+
name='Example collection for python' + random.choice('ABCDEFGHIJKLMNOPQ'),
41+
description="Integration test for python sdk")['collection_id']
42+
assert new_collection_id is not None
43+
self.discovery.get_collection(self.environment_id, new_collection_id)
44+
updated_collection = self.discovery.update_collection(self.environment_id, new_collection_id, name='lala')
45+
assert updated_collection['name'] == 'lala'
46+
47+
self.discovery.create_expansions(self.environment_id, new_collection_id, [{'input_terms': ['a'], 'expanded_terms': ['aa']}])
48+
expansions = self.discovery.list_expansions(self.environment_id, new_collection_id)
49+
assert len(expansions['expansions']) > 0
50+
self.discovery.delete_expansions(self.environment_id, new_collection_id)
51+
52+
deleted_collection = self.discovery.delete_collection(self.environment_id, new_collection_id)
53+
assert deleted_collection['status'] == 'deleted'
54+
55+
def test_documents(self):
56+
with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
57+
add_doc = self.discovery.add_document(environment_id=self.environment_id,
58+
collection_id=self.collection_id,
59+
file=fileinfo)
60+
add_doc['document_id'] is not None
61+
62+
doc_status = self.discovery.get_document_status(self.environment_id, self.collection_id, add_doc['document_id'])
63+
assert doc_status is not None
64+
65+
with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
66+
update_doc = self.discovery.update_document(self.environment_id,
67+
self.collection_id,
68+
add_doc['document_id'],
69+
file=fileinfo,
70+
filename='newname.html')
71+
assert update_doc is not None
72+
delete_doc = self.discovery.delete_document(self.environment_id, self.collection_id, add_doc['document_id'])
73+
assert delete_doc['status'] == 'deleted'
74+
75+
76+
def test_queries(self):
77+
query_results = self.discovery.query(self.environment_id,
78+
self.collection_id,
79+
filter='extracted_metadata.sha1::9181d244*',
80+
return_fields='extracted_metadata.sha1')
81+
assert query_results is not None

test/unit/test_discovery_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_query_relations():
250250
discovery = watson_developer_cloud.DiscoveryV1(
251251
'2016-11-07', username='username', password='password')
252252

253-
discovery.query_relations('envid', 'collid', {'count': 10})
253+
discovery.query_relations('envid', 'collid', count=10)
254254
called_url = urlparse(responses.calls[0].request.url)
255255
test_url = urlparse(discovery_url)
256256
assert called_url.netloc == test_url.netloc
@@ -792,7 +792,7 @@ def test_expansions():
792792
discovery.list_expansions('envid', 'colid')
793793
assert responses.calls[0].response.json() == {"expansions": "results"}
794794

795-
discovery.create_expansions('envid', 'colid', { "expansions": [{"input_terms": "dumb"}] })
795+
discovery.create_expansions('envid', 'colid', [{"input_terms": "dumb", "expanded_terms": "dumb2"}])
796796
assert responses.calls[1].response.json() == {"expansions": "success" }
797797

798798
discovery.delete_expansions('envid', 'colid')

0 commit comments

Comments
 (0)