Пример #1
0
def test_get_training_data():
    training_endpoint = '/v1/environments/{0}/collections/{1}/training_data/{2}'
    query_id = 'queryid'
    endpoint = training_endpoint.format(environment_id, collection_id,
                                        query_id)
    url = '{0}{1}'.format(base_url, endpoint)
    mock_response = {
        "query_id":
        "string",
        "natural_language_query":
        "string",
        "filter":
        "string",
        "examples": [{
            "document_id": "string",
            "cross_reference": "string",
            "relevance": 0
        }]
    }
    responses.add(responses.GET,
                  url,
                  body=json.dumps(mock_response),
                  status=200,
                  content_type='application/json')

    service = watson_developer_cloud.DiscoveryV1(version,
                                                 username='******',
                                                 password='******')
    response = service.get_training_data(environment_id=environment_id,
                                         collection_id=collection_id,
                                         query_id=query_id)

    assert response == mock_response
    # Verify that response can be converted to a TrainingQuery
    TrainingQuery._from_dict(response)
def test_add_training_data():
    training_endpoint = '/v1/environments/{0}/collections/{1}/training_data'
    endpoint = training_endpoint.format(environment_id, collection_id)
    url = '{0}{1}'.format(base_url, endpoint)
    natural_language_query = "why is the sky blue"
    filter = "text:meteorology"
    examples = [
        {
            "document_id": "54f95ac0-3e4f-4756-bea6-7a67b2713c81",
            "relevance": 1
        },
        {
            "document_id": "01bcca32-7300-4c9f-8d32-33ed7ea643da",
            "cross_reference": "my_id_field:1463",
            "relevance": 5
        }
    ]
    mock_response = {
        "query_id": "string",
        "natural_language_query": "string",
        "filter": "string",
        "examples": [
            {
                "document_id": "string",
                "cross_reference": "string",
                "relevance": 0
            }
        ]
    }
    responses.add(responses.POST,
                  url,
                  body=json.dumps(mock_response),
                  status=200,
                  content_type='application/json')

    service = watson_developer_cloud.DiscoveryV1(version,
                                                 username='******',
                                                 password='******')
    response = service.add_training_data(
        environment_id=environment_id,
        collection_id=collection_id,
        natural_language_query=natural_language_query,
        filter=filter,
        examples=examples).get_result()

    assert response == mock_response
    # Verify that response can be converted to a TrainingQuery
    TrainingQuery._from_dict(response)