Skip to content

Commit

Permalink
feat(python discovery): regenerate discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Mar 7, 2018
1 parent d351a19 commit 598f8f2
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 34 deletions.
Binary file modified .env.enc
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/discovery_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
environment_id=news_environment_id)
print(json.dumps(configurations, indent=2))

query_options = {'query': 'IBM'}
query_results = discovery.query(news_environment_id,
news_collections[0]['collection_id'],
query_options)
filter='extracted_metadata.sha1::f5*',
return_fields='extracted_metadata.sha1')
print(json.dumps(query_results, indent=2))

# new_environment = discovery.create_environment(name="new env", description="bogus env")
Expand Down
78 changes: 78 additions & 0 deletions test/integration/test_integration_discovery_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from unittest import TestCase
import os
import watson_developer_cloud
import json

class Discoveryv1(TestCase):
def setUp(self):
self.discovery = watson_developer_cloud.DiscoveryV1(
version='2017-10-16',
username=os.getenv('SPEECH_TO_TEXT_USERNAME'),
password=os.getenv('SPEECH_TO_TEXT_PASSWORD'))
self.discovery.set_default_headers({'X-Watson-Learning-Opt-Out': '1', 'X-Watson-Test': '1'})
self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing
self.collection_id = self.discovery.list_collections(self.environment_id)['collections'][0]['collection_id']

def test_environments(self):
envs = self.discovery.list_environments()
assert envs is not None
env = self.discovery.get_environment(envs['environments'][0]['environment_id'])
assert env is not None
fields = self.discovery.list_fields(self.environment_id, self.collection_id)
assert fields is not None

def test_configurations(self):
configs = self.discovery.list_configurations(self.environment_id)
assert configs is not None
new_configuration_id = self.discovery.create_configuration(self.environment_id, 'test', 'creating new config for python sdk')['configuration_id']
assert new_configuration_id is not None
self.discovery.get_configuration(self.environment_id, new_configuration_id)
updated_config = self.discovery.update_configuration(self.environment_id, new_configuration_id, 'lala')
assert updated_config['name'] == 'lala'
deleted_config = self.discovery.delete_configuration(self.environment_id, new_configuration_id)
assert deleted_config['status'] == 'deleted'

def test_collections_and_expansions(self):
new_collection_id = self.discovery.create_collection(self.environment_id,
name='Example collection for python',
description="Integration test for python sdk")['collection_id']
assert new_collection_id is not None
self.discovery.get_collection(self.environment_id, new_collection_id)
updated_collection = self.discovery.update_collection(self.environment_id, new_collection_id, name='lala')
assert updated_collection['name'] == 'lala'

self.discovery.create_expansions(self.environment_id, new_collection_id, [{'input_terms': ['a'], 'expanded_terms': ['aa']}])
expansions = self.discovery.list_expansions(self.environment_id, new_collection_id)
assert len(expansions['expansions']) > 0
self.discovery.delete_expansions(self.environment_id, new_collection_id)

deleted_collection = self.discovery.delete_collection(self.environment_id, new_collection_id)
assert deleted_collection['status'] == 'deleted'

def test_documents(self):
with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
add_doc = self.discovery.add_document(environment_id=self.environment_id,
collection_id=self.collection_id,
file=fileinfo)
add_doc['document_id'] is not None

doc_status = self.discovery.get_document_status(self.environment_id, self.collection_id, add_doc['document_id'])
assert doc_status is not None

with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
update_doc = self.discovery.update_document(self.environment_id,
self.collection_id,
add_doc['document_id'],
file=fileinfo,
filename='newname.html')
assert update_doc is not None
delete_doc = self.discovery.delete_document(self.environment_id, self.collection_id, add_doc['document_id'])
assert delete_doc['status'] == 'deleted'


def test_queries(self):
query_results = self.discovery.query(self.environment_id,
self.collection_id,
filter='extracted_metadata.sha1::9181d244*',
return_fields='extracted_metadata.sha1')
assert query_results is not None
4 changes: 2 additions & 2 deletions test/unit/test_discovery_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_query_relations():
discovery = watson_developer_cloud.DiscoveryV1(
'2016-11-07', username='username', password='password')

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

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

discovery.delete_expansions('envid', 'colid')
Expand Down
Loading

0 comments on commit 598f8f2

Please sign in to comment.