|
| 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 |
0 commit comments