Skip to content

Commit f70b42b

Browse files
committed
test: add tests for BulkClassify, AnalyzeDocument and refactor TTS tests
1 parent 93cd391 commit f70b42b

File tree

6 files changed

+1388
-74
lines changed

6 files changed

+1388
-74
lines changed

Tests/AssistantV1IntegrationTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,40 @@ public IEnumerator TestListLogs()
11401140
yield return null;
11411141
}
11421142

1143+
[UnityTest, Order(36)]
1144+
public IEnumerator TestBulkClassify()
1145+
{
1146+
IamAuthenticator auth = new IamAuthenticator(
1147+
apikey: "{IAM_APIKEY}"
1148+
);
1149+
// Wait for tokendata
1150+
while (!auth.CanAuthenticate())
1151+
yield return null;
1152+
AssistantService premiumService = new AssistantService(versionDate, auth);
1153+
premiumService.SetServiceUrl("{SERVICE_URL}");
1154+
1155+
Log.Debug("AssistantServiceV1IntegrationTests", "Attempting to BulkClassify...");
1156+
BulkClassifyUtterance bulkClassifyUtterance = new BulkClassifyUtterance()
1157+
{
1158+
Text = "help I need help"
1159+
};
1160+
List<BulkClassifyUtterance> bulkClassifyUtterances = new List<BulkClassifyUtterance>() { bulkClassifyUtterance };
1161+
BulkClassifyResponse bulkClassifyResponse = null;
1162+
premiumService.BulkClassify(
1163+
callback: (DetailedResponse<BulkClassifyResponse> response, IBMError error) =>
1164+
{
1165+
Log.Debug("AssistantServiceV1IntegrationTests", "BulkClassify result: {0}", response.Response);
1166+
bulkClassifyResponse = response.Result;
1167+
Assert.IsNull(error);
1168+
Assert.IsNotNull(bulkClassifyResponse);
1169+
},
1170+
workspaceId: "f84c20fd-2c2d-4065-abcc-7a9ecc6da124",
1171+
input: bulkClassifyUtterances
1172+
);
1173+
while (bulkClassifyResponse == null)
1174+
yield return null;
1175+
}
1176+
11431177
[UnityTest, Order(91)]
11441178
public IEnumerator TestDeleteUserData()
11451179
{

Tests/DiscoveryV1IntegrationTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,11 @@ public IEnumerator TestQueryAggregation()
934934
Assert.IsNotNull(queryResultTimeslice.Aggregations);
935935
Assert.IsTrue((queryResultTimeslice.Aggregations[0] as Timeslice).Field == "product.sales");
936936
Assert.IsTrue((queryResultTimeslice.Aggregations[0] as Timeslice).Interval == "2d");
937-
Assert.IsTrue((queryResultTimeslice.Aggregations[0] as Timeslice).Anomaly == true);
938937
},
939938
environmentId: "system",
940939
collectionId: "news-en",
941940
naturalLanguageQuery: naturalLanguageQuery,
942-
aggregation: "timeslice(product.sales,2day,anomaly:true)"
941+
aggregation: "timeslice(product.sales,2day)"
943942
);
944943

945944
QueryResponse queryResultTerm = null;

Tests/DiscoveryV2IntegrationTests.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018, 2019 IBM Corp. All Rights Reserved.
2+
* (C) Copyright IBM Corp. 2018, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,8 @@ public class DiscoveryV2IntegrationTests
5050
public void OneTimeSetup()
5151
{
5252
LogSystem.InstallDefaultReactors();
53+
analyzeDocumentFile = Application.dataPath + "/Watson/Tests/TestData/DiscoveryV2/WatsonBeatsJeopardy.html";
54+
5355
addDocumentFile = Application.dataPath + "/Watson/Tests/TestData/DiscoveryV2/TestAddDoc.pdf";
5456
enrichmentFile = Application.dataPath + "/Watson/Tests/TestData/DiscoveryV2/TestEnrichments.csv";
5557
}
@@ -648,6 +650,48 @@ public IEnumerator TestGetProject()
648650
}
649651
#endregion
650652

653+
#region AnalyzeDocument
654+
[UnityTest, Order(20)]
655+
public IEnumerator TestAnalyzeDocument()
656+
{
657+
BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
658+
bearerToken: "{BEARER_TOKEN}"
659+
);
660+
DiscoveryService cpdService = new DiscoveryService(versionDate, authenticator);
661+
cpdService.SetServiceUrl("{SERVICE_URL}");
662+
cpdService.WithHeader("X-Watson-Test", "1");
663+
664+
Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to AnalyzeDocument...");
665+
AnalyzedDocument analyzeDocumentResponse = null;
666+
using (FileStream fs = File.OpenRead(analyzeDocumentFile))
667+
{
668+
using (MemoryStream ms = new MemoryStream())
669+
{
670+
fs.CopyTo(ms);
671+
672+
cpdService.AnalyzeDocument(
673+
callback: (DetailedResponse<AnalyzedDocument> response, IBMError error) =>
674+
{
675+
Log.Debug("DiscoveryServiceV2IntegrationTests", "AnalyzeDocument result: {0}", response.Response);
676+
analyzeDocumentResponse = response.Result;
677+
Assert.IsNull(error);
678+
Assert.IsNotNull(analyzeDocumentResponse);
679+
},
680+
projectId: "{projectId}",
681+
collectionId: "{collectionId}",
682+
file: ms,
683+
filename: "WatsonBeatsJeopardy.html",
684+
fileContentType: "text/html",
685+
metadata: "{ \"metadata\": \"value\" }"
686+
);
687+
}
688+
}
689+
690+
while (analyzeDocumentResponse == null)
691+
yield return null;
692+
}
693+
#endregion
694+
651695
#region DeleteCollection
652696
[UnityTest, Order(101)]
653697
public IEnumerator TestDeleteCollection()

0 commit comments

Comments
 (0)