Skip to content

Commit

Permalink
Merge pull request #1316 from solliancenet/aa-content-safety-tests
Browse files Browse the repository at this point in the history
Fix Azure Content Safety service tests
  • Loading branch information
ciprianjichici authored Aug 1, 2024
2 parents 8e709a9 + ee55d21 commit 0e672d9
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Azure;
using Azure.AI.ContentSafety;
using FoundationaLLM.Common.Interfaces;
using FoundationaLLM.Common.Interfaces;
using FoundationaLLM.Gatekeeper.Core.Models.ConfigurationOptions;
using FoundationaLLM.Gatekeeper.Core.Models.ContentSafety;
using FoundationaLLM.Gatekeeper.Core.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NSubstitute;
using NSubstitute.ExceptionExtensions;

namespace Gatekeeper.Tests.Services
{
Expand All @@ -16,18 +13,13 @@ public class AzureContentSafetyServiceTests
private readonly AzureContentSafetyService _testedService;

private readonly ILogger<AzureContentSafetyService> _logger = Substitute.For<ILogger<AzureContentSafetyService>>();
private ContentSafetyClient _client;
private AzureContentSafetyService _service;

private readonly IOptions<AzureContentSafetySettings> _settings = Substitute.For<IOptions<AzureContentSafetySettings>>();
private readonly ICallContext _callContext = Substitute.For<ICallContext>();
private readonly IHttpClientFactoryService _httpClientFactoryService = Substitute.For<IHttpClientFactoryService>();

public AzureContentSafetyServiceTests()
{
// TODO: move to APIEndpointConfiguration
//_testedService = new AzureContentSafetyService(_callContext, _httpClientFactoryService, _settings, _logger);
//_client = Substitute.ForPartsOf<ContentSafetyClient>(new Uri(_settings.Value.APIUrl), new AzureKeyCredential(_settings.Value.APIKey));
//_service = new AzureContentSafetyService(_callContext, _httpClientFactoryService, _settings, _logger);
_testedService = new AzureContentSafetyService(_callContext, _httpClientFactoryService, _settings, _logger);
}

[Fact]
Expand All @@ -41,9 +33,6 @@ public async Task AnalyzeText_RequestFailedException_ReturnsExpectedResult()
Reason = "The content safety service was unable to validate the prompt text due to an internal error."
};

_client.AnalyzeTextAsync(Arg.Any<AnalyzeTextOptions>())
.Throws(new RequestFailedException("Test error"));

// Act
var result = await _testedService.AnalyzeText(content);

Expand Down

0 comments on commit 0e672d9

Please sign in to comment.