|
| 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 | +@pytest.mark.skip("Skip Compare and comply tests") |
| 10 | +class IntegrationTestCompareComplyV1(TestCase): |
| 11 | + compare_comply = None |
| 12 | + |
| 13 | + @classmethod |
| 14 | + def setup_class(cls): |
| 15 | + cls.compare_comply = watson_developer_cloud.CompareComplyV1( |
| 16 | + "2018-10-15", |
| 17 | + iam_apikey='YOUR IAM API KEY') |
| 18 | + cls.compare_comply.set_default_headers({ |
| 19 | + 'X-Watson-Learning-Opt-Out': |
| 20 | + '1', |
| 21 | + 'X-Watson-Test': |
| 22 | + '1' |
| 23 | + }) |
| 24 | + |
| 25 | + def test_convert_to_html(self): |
| 26 | + contract = abspath('resources/contract_A.pdf') |
| 27 | + with open(contract, 'rb') as file: |
| 28 | + result = self.compare_comply.convert_to_html(file).get_result() |
| 29 | + assert result is not None |
| 30 | + |
| 31 | + def test_classify_elements(self): |
| 32 | + contract = abspath('resources/contract_A.pdf') |
| 33 | + with open(contract, 'rb') as file: |
| 34 | + result = self.compare_comply.classify_elements(file).get_result() |
| 35 | + assert result is not None |
| 36 | + |
| 37 | + def test_extract_tables(self): |
| 38 | + table = abspath('resources/contract_A.pdf') |
| 39 | + with open(table, 'rb') as file: |
| 40 | + result = self.compare_comply.extract_tables(file).get_result() |
| 41 | + assert result is not None |
| 42 | + |
| 43 | + def test_compare_documents(self): |
| 44 | + with open(os.path.join(os.path.dirname(__file__), '../../resources/contract_A.pdf'), 'rb') as file1, \ |
| 45 | + open(os.path.join(os.path.dirname(__file__), '../../resources/contract_B.pdf'), 'rb') as file2: |
| 46 | + result = self.compare_comply.compare_documents(file1, file2).get_result() |
| 47 | + |
| 48 | + assert result is not None |
| 49 | + |
| 50 | + def test_feedback(self): |
| 51 | + feedback_data = { |
| 52 | + "feedback_type": "element_classification", |
| 53 | + "document": { |
| 54 | + "hash": "", |
| 55 | + "title": "doc title" |
| 56 | + }, |
| 57 | + "model_id": "contracts", |
| 58 | + "model_version": "11.00", |
| 59 | + "location": { |
| 60 | + "begin": "214", |
| 61 | + "end": "237" |
| 62 | + }, |
| 63 | + "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.", |
| 64 | + "original_labels": { |
| 65 | + "types": [ |
| 66 | + { |
| 67 | + "label": { |
| 68 | + "nature": "Obligation", |
| 69 | + "party": "IBM" |
| 70 | + }, |
| 71 | + "provenance_ids": [ |
| 72 | + "85f5981a-ba91-44f5-9efa-0bd22e64b7bc", |
| 73 | + "ce0480a1-5ef1-4c3e-9861-3743b5610795" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "label": { |
| 78 | + "nature": "End User", |
| 79 | + "party": "Exclusion" |
| 80 | + }, |
| 81 | + "provenance_ids": [ |
| 82 | + "85f5981a-ba91-44f5-9efa-0bd22e64b7bc", |
| 83 | + "ce0480a1-5ef1-4c3e-9861-3743b5610795" |
| 84 | + ] |
| 85 | + } |
| 86 | + ], |
| 87 | + "categories": [ |
| 88 | + { |
| 89 | + "label": "Responsibilities", |
| 90 | + "provenance_ids": [] |
| 91 | + }, |
| 92 | + { |
| 93 | + "label": "Amendments", |
| 94 | + "provenance_ids": [] |
| 95 | + } |
| 96 | + ] |
| 97 | + }, |
| 98 | + "updated_labels": { |
| 99 | + "types": [ |
| 100 | + { |
| 101 | + "label": { |
| 102 | + "nature": "Obligation", |
| 103 | + "party": "IBM" |
| 104 | + } |
| 105 | + }, |
| 106 | + { |
| 107 | + "label": { |
| 108 | + "nature": "Disclaimer", |
| 109 | + "party": "Buyer" |
| 110 | + } |
| 111 | + } |
| 112 | + ], |
| 113 | + "categories": [ |
| 114 | + { |
| 115 | + "label": "Responsibilities" |
| 116 | + }, |
| 117 | + { |
| 118 | + "label": "Audits" |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + add_feedback = self.compare_comply.add_feedback( |
| 125 | + feedback_data, |
| 126 | + "wonder woman", |
| 127 | + "test commment").get_result() |
| 128 | + assert add_feedback is not None |
| 129 | + assert add_feedback["feedback_id"] is not None |
| 130 | + feedback_id = add_feedback["feedback_id"] |
| 131 | + |
| 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 | + def test_batches(self): |
| 143 | + list_batches = self.compare_comply.list_batches().get_result() |
| 144 | + assert list_batches is not None |
| 145 | + |
| 146 | + with open(os.path.join(os.path.dirname(__file__), '../../resources/cloud-object-storage-credentials-input.json'), 'rb') as input_credentials_file, \ |
| 147 | + open(os.path.join(os.path.dirname(__file__), '../../resources/cloud-object-storage-credentials-output.json'), 'rb') as output_credentials_file: |
| 148 | + create_batch = self.compare_comply.create_batch( |
| 149 | + "html_conversion", |
| 150 | + input_credentials_file, |
| 151 | + "us-south", |
| 152 | + "compare-comply-integration-test-bucket-input", |
| 153 | + output_credentials_file, |
| 154 | + "us-south", |
| 155 | + "compare-comply-integration-test-bucket-output").get_result() |
| 156 | + |
| 157 | + assert create_batch is not None |
| 158 | + assert create_batch["batch_id"] is not None |
| 159 | + batch_id = create_batch["batch_id"] |
| 160 | + |
| 161 | + get_batch = self.compare_comply.get_batch(batch_id) |
| 162 | + assert get_batch is not None |
| 163 | + |
| 164 | + update_batch = self.compare_comply.update_batch(batch_id, "rescan") |
| 165 | + assert update_batch is not None |
0 commit comments