필터로 데이터 나열

API를 사용하여 데이터를 나열할 때 일부 list 메서드 요청은 filter 필드를 제공합니다. 이 필터를 사용하여 관심 있는 결과만 반환할 수 있습니다. 이 필터링 기능은 여러 Google Cloud API에서 공통적입니다.

다음은 테스트 사례 결과를 나열할 때 응답을 필터링하는 방법을 보여주는 예시입니다.

Java

Dialogflow에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


import com.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest;
import com.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest.Builder;
import com.google.cloud.dialogflow.cx.v3.TestCaseResult;
import com.google.cloud.dialogflow.cx.v3.TestCasesClient;
import com.google.cloud.dialogflow.cx.v3.TestCasesSettings;
import java.io.IOException;

public class ListTestCaseResults {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String agentId = "my-agent-id";
    String testId = "my-test-id";
    String location = "my-location";
    listTestCaseResults(projectId, agentId, testId, location);
  }

  public static void listTestCaseResults(
      String projectId, String agentId, String testId, String location) throws IOException {
    String parent =
        "projects/"
            + projectId
            + "/locations/"
            + location
            + "/agents/"
            + agentId
            + "/testCases/"
            + testId;

    Builder req = ListTestCaseResultsRequest.newBuilder();

    req.setParent(parent);
    req.setFilter("environment=draft");

    TestCasesSettings testCasesSettings =
        TestCasesSettings.newBuilder()
            .setEndpoint(location + "-dialogflow.googleapis.com:443")
            .build();

    // Note: close() needs to be called on the TestCasesClient object to clean up resources
    // such as threads. In the example below, try-with-resources is used,
    // which automatically calls close().
    try (TestCasesClient client = TestCasesClient.create(testCasesSettings)) {
      for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) {
        System.out.println(element);
      }
    }
  }
}

Node.js

CTS에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

const parent = `projects/${projectId}/locations/${location}/agents/${agentId}/testCases/${testId}`;

const {TestCasesClient} = require('@google-cloud/dialogflow-cx');

const client = new TestCasesClient({
  apiEndpoint: 'global-dialogflow.googleapis.com',
});
const req = {
  parent,
  filter: 'environment=draft',
};

const res = await client.listTestCaseResults(req);

console.log(res);

Python

CTS에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


from google.cloud.dialogflowcx_v3.services.test_cases.client import TestCasesClient
from google.cloud.dialogflowcx_v3.types.test_case import ListTestCaseResultsRequest

def list_test_case(project_id, agent_id, test_id, location):
    req = ListTestCaseResultsRequest()
    req.parent = f"projects/{project_id}/locations/{location}/agents/{agent_id}/testCases/{test_id}"
    req.filter = "environment=draft"
    client = TestCasesClient(
        client_options={"api_endpoint": f"{location}-dialogflow.googleapis.com"}
    )
    # Makes a call to list all test case results that match filter
    result = client.list_test_case_results(request=req)
    print(result)
    return result