Skip to content

Commit

Permalink
Fix content safety tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alistar-andrei committed Aug 1, 2024
1 parent ee6d439 commit ee55d21
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 ee55d21

Please sign in to comment.