Skip to content

Commit

Permalink
Test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed May 9, 2024
1 parent d28acf0 commit 95e6388
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import com.atlassian.oai.validator.report.ValidationReport;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.stefanbratanov.jvm.openai.RunStepsClient.PaginatedThreadRunSteps;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;

Expand Down Expand Up @@ -162,11 +160,13 @@ void validateBatch() {
void validateFiles() {
File file = testDataUtil.randomFile();

// manually add deprecated required field "status"
Response response =
createResponseWithBody(serializeObject(file, Map.of("status", "processed")));
Response response = createResponseWithBody(serializeObject(file));

validate("/" + Endpoint.FILES.getPath() + "/{file_id}", Method.GET, response);
validate(
"/" + Endpoint.FILES.getPath() + "/{file_id}",
Method.GET,
response,
"Object has missing required properties ([\"object\",\"status\"])");
}

@RepeatedTest(50)
Expand Down Expand Up @@ -458,14 +458,4 @@ private String serializeObject(Object object) {
throw new UncheckedIOException(ex);
}
}

private String serializeObject(Object object, Map<String, Object> additionalFields) {
try {
ObjectNode objectNode = objectMapper.valueToTree(object);
additionalFields.forEach(objectNode::putPOJO);
return objectMapper.writeValueAsString(objectNode);
} catch (JsonProcessingException ex) {
throw new UncheckedIOException(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CreateChatCompletionRequest randomCreateChatCompletionRequest() {
.topP(randomDouble(0.0, 1.0))
.tools(listOf(randomInt(0, 5), this::randomFunctionTool));
runOne(
() -> builder.toolChoice(oneOf("none", "auto")),
() -> builder.toolChoice(oneOf("none", "auto", "required")),
() ->
builder.toolChoice(
ToolChoice.functionToolChoice(new ToolChoice.Function(randomString(5)))));
Expand Down Expand Up @@ -235,7 +235,13 @@ public File randomFile() {
randomInt(1, 1000),
randomLong(1, 42_000),
randomString(7),
oneOf("fine-tune", "fine-tune-results", "assistants", "assistants_output"));
oneOf(
"assistants",
"assistants_output",
"batch",
"batch_output",
"fine-tune",
"fine-tune-results"));
}

public CreateImageRequest randomCreateImageRequest() {
Expand Down

0 comments on commit 95e6388

Please sign in to comment.