コード例 #1
0
    def setup_class(cls):
        authenticator = IAMAuthenticator('apikey')
        cls.discovery = ibm_watson.DiscoveryV2(
            version='2020-08-12',
            authenticator=authenticator
        )
        cls.discovery.set_service_url('url')
        cls.discovery.set_default_headers({
            'X-Watson-Learning-Opt-Out': '1',
            'X-Watson-Test': '1'
        })

        collections = cls.discovery.list_collections(
            cls.project_id).get_result()['collections']
        for collection in collections:
            if collection['name'] == cls.collection_name:
                cls.collection_id = collection['collection_id']

        if cls.collection_id is None:
            print("Creating a new temporary collection")
            cls.collection_id = cls.discovery.create_collection(
                cls.project_id,
                cls.collection_name,
                description="Integration test for python sdk").get_result(
                )['collection_id']
コード例 #2
0
 def test_analyze(self):
     authenticator = BearerTokenAuthenticator('<bearer_token>')
     discovery_cpd = ibm_watson.DiscoveryV2(
         version='2020-08-12',
         authenticator=authenticator
     )
     discovery_cpd.service_url = "<url>"
     discovery_cpd.set_disable_ssl_verification(True)
     test_file = abspath('resources/problem.json')
     with open(test_file, 'rb') as file:
         result = discovery_cpd.analyze_document(
             project_id="<project_id>",
             collection_id="<collection_id>",
             file=file,
             file_content_type="application/json"
         ).get_result()
         assert result is not None