Skip to content

Commit a891041

Browse files
Merge pull request #613 from watson-developer-cloud/compare-comply
New service Compare comply
2 parents 9d8ea23 + bb870fe commit a891041

29 files changed

Lines changed: 7033 additions & 1197 deletions

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.4.4
2+
current_version = 2.5.1
33
commit = True
44

55
[bumpversion:file:watson_developer_cloud/version.py]

.env.enc

160 Bytes
Binary file not shown.

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ python:
44
- '3.4'
55
- '3.5'
66
- '3.6'
7-
matrix:
8-
include:
9-
- python: '3.7'
10-
dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069)
7+
# Temporarily comment, check issue: https://github.com/watson-developer-cloud/python-sdk/issues/612
8+
# matrix:
9+
# include:
10+
# - python: '3.7'
11+
# dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069)
1112
cache: pip
1213
before_install:
1314
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cebf25e6c525_key

resources/contract_A.pdf

83.7 KB
Binary file not shown.

resources/contract_B.pdf

83.6 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"apikey": "random-apikey",
3+
"cos_hmac_keys": {
4+
"access_key_id": "aaaa",
5+
"secret_access_key": "bbb"
6+
},
7+
"endpoints": "https://cos-service.bluemix.net/endpoints",
8+
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/070794137072b93b6eb44420201f6194:c290d41e-c445-420e-ad44-65b2a15a7c6c::",
9+
"iam_apikey_name": "auto-generated-apikey-5a3550b4-e3af-40b7-8bda-0fb839533c02",
10+
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Manager",
11+
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/070794137072b93b6eb44420201f6194::serviceid:ServiceId-3ff1a723-d223-41ff-99e4-32ff8d022549",
12+
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/xxx:yyy::"
13+
}

resources/sample-tables.pdf

142 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import sys
2121

22-
__version__ = '2.4.4'
22+
__version__ = '2.5.1'
2323

2424
if sys.argv[-1] == 'publish':
2525
# test server
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# coding: utf-8
2+
import pytest
3+
import watson_developer_cloud
4+
import os
5+
from os.path import abspath
6+
from unittest import TestCase
7+
8+
9+
class IntegrationTestCompareComplyV1(TestCase):
10+
compare_comply = None
11+
12+
@classmethod
13+
def setup_class(cls):
14+
cls.compare_comply = watson_developer_cloud.CompareComplyV1(
15+
'2018-10-15',
16+
iam_apikey='YOUR IAM API KEY')
17+
cls.compare_comply.set_default_headers({
18+
'X-Watson-Learning-Opt-Out':
19+
'1',
20+
'X-Watson-Test':
21+
'1'
22+
})
23+
24+
def test_convert_to_html(self):
25+
contract = abspath('resources/contract_A.pdf')
26+
with open(contract, 'rb') as file:
27+
result = self.compare_comply.convert_to_html(file).get_result()
28+
assert result is not None
29+
30+
def test_classify_elements(self):
31+
contract = abspath('resources/contract_A.pdf')
32+
with open(contract, 'rb') as file:
33+
result = self.compare_comply.classify_elements(file).get_result()
34+
assert result is not None
35+
36+
def test_extract_tables(self):
37+
table = abspath('resources/contract_A.pdf')
38+
with open(table, 'rb') as file:
39+
result = self.compare_comply.extract_tables(file).get_result()
40+
assert result is not None
41+
42+
def test_compare_documents(self):
43+
with open(os.path.join(os.path.dirname(__file__), '../../resources/contract_A.pdf'), 'rb') as file1, \
44+
open(os.path.join(os.path.dirname(__file__), '../../resources/contract_B.pdf'), 'rb') as file2:
45+
result = self.compare_comply.compare_documents(file1, file2).get_result()
46+
47+
assert result is not None
48+
49+
def test_feedback(self):
50+
feedback_data = {
51+
'feedback_type': 'element_classification',
52+
'document': {
53+
'hash': '',
54+
'title': 'doc title'
55+
},
56+
'model_id': 'contracts',
57+
'model_version': '11.00',
58+
'location': {
59+
'begin': '214',
60+
'end': '237'
61+
},
62+
'text': '1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing infrastructure.',
63+
'original_labels': {
64+
'types': [
65+
{
66+
'label': {
67+
'nature': 'Obligation',
68+
'party': 'IBM'
69+
},
70+
'provenance_ids': [
71+
'85f5981a-ba91-44f5-9efa-0bd22e64b7bc',
72+
'ce0480a1-5ef1-4c3e-9861-3743b5610795'
73+
]
74+
},
75+
{
76+
'label': {
77+
'nature': 'End User',
78+
'party': 'Exclusion'
79+
},
80+
'provenance_ids': [
81+
'85f5981a-ba91-44f5-9efa-0bd22e64b7bc',
82+
'ce0480a1-5ef1-4c3e-9861-3743b5610795'
83+
]
84+
}
85+
],
86+
'categories': [
87+
{
88+
'label': 'Responsibilities',
89+
'provenance_ids': []
90+
},
91+
{
92+
'label': 'Amendments',
93+
'provenance_ids': []
94+
}
95+
]
96+
},
97+
'updated_labels': {
98+
'types': [
99+
{
100+
'label': {
101+
'nature': 'Obligation',
102+
'party': 'IBM'
103+
}
104+
},
105+
{
106+
'label': {
107+
'nature': 'Disclaimer',
108+
'party': 'Buyer'
109+
}
110+
}
111+
],
112+
'categories': [
113+
{
114+
'label': 'Responsibilities'
115+
},
116+
{
117+
'label': 'Audits'
118+
}
119+
]
120+
}
121+
}
122+
123+
add_feedback = self.compare_comply.add_feedback(
124+
feedback_data,
125+
'wonder woman',
126+
'test commment').get_result()
127+
assert add_feedback is not None
128+
assert add_feedback['feedback_id'] is not None
129+
feedback_id = add_feedback['feedback_id']
130+
131+
self.compare_comply.set_default_headers({'x-watson-metadata': 'customer_id=sdk-test-customer-id'})
132+
get_feedback = self.compare_comply.get_feedback(feedback_id).get_result()
133+
assert get_feedback is not None
134+
135+
list_feedback = self.compare_comply.list_feedback(
136+
feedback_type='element_classification').get_result()
137+
assert list_feedback is not None
138+
139+
delete_feedback = self.compare_comply.delete_feedback(feedback_id).get_result()
140+
assert delete_feedback is not None
141+
142+
@pytest.mark.skip(reason="Temporarily skip")
143+
def test_batches(self):
144+
list_batches = self.compare_comply.list_batches().get_result()
145+
assert list_batches is not None
146+
147+
with open(os.path.join(os.path.dirname(__file__), '../../resources/cloud-object-storage-credentials-input.json'), 'rb') as input_credentials_file, \
148+
open(os.path.join(os.path.dirname(__file__), '../../resources/cloud-object-storage-credentials-output.json'), 'rb') as output_credentials_file:
149+
create_batch = self.compare_comply.create_batch(
150+
'html_conversion',
151+
input_credentials_file,
152+
'us-south',
153+
'compare-comply-integration-test-bucket-input',
154+
output_credentials_file,
155+
'us-south',
156+
'compare-comply-integration-test-bucket-output').get_result()
157+
158+
assert create_batch is not None
159+
assert create_batch['batch_id'] is not None
160+
batch_id = create_batch['batch_id']
161+
162+
get_batch = self.compare_comply.get_batch(batch_id)
163+
assert get_batch is not None
164+
165+
update_batch = self.compare_comply.update_batch(batch_id, 'rescan')
166+
assert update_batch is not None

test/unit/test_assistant_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ def test_get_workspace():
13591359
content_type='application/json')
13601360
service = watson_developer_cloud.AssistantV1(
13611361
username='username', password='password', version='2017-02-03')
1362-
workspace = service.get_workspace(workspace_id='boguswid', export=False).get_result()
1362+
workspace = service.get_workspace(workspace_id='boguswid', export=True, sort='stable').get_result()
13631363
assert len(responses.calls) == 1
13641364
assert responses.calls[0].request.url.startswith(url)
13651365
assert workspace == response

0 commit comments

Comments
 (0)