Json Body Assertion
JSON Body Assertion: Submit your API JSON body to receive the corresponding tests for the response using both SDKs and REST APIs.
Usage 🚀
Refer to Setup Guide for installing dependecies for both Java and Python.
JAVA
There are 2 clients available with the Java SDK: SyncClient and AsyncClient
Java Client Code
# for async client
import org.qyrus.ai_sdk.Clients.AsyncClient;
AsyncClient client = new AsyncClient(<API_TOKEN>, null);
# for sync client
import org.qyrus.ai_sdk.Clients.SyncClient;
SyncClient client = new SyncClient(<API_TOKEN>, null);Using SyncClient
Here's an example of utilizing JSON Body Assertion with SyncClient.
Java SyncClient Code
private static void testJSONBodyAssertion() {
Dotenv dotenv = Dotenv.load();
String QYRUS_AI_SDK_API_TOKEN = dotenv.get("QYRUS_AI_SDK_API_TOKEN");
SyncClient client = new SyncClient(QYRUS_AI_SDK_API_TOKEN, null);
Map<String, Object> loanApplication = Map.of(
"loanId", 101,
"userId", 1,
"loanAmount", 200000,
"loanTerm", 30,
"propertyValue", 250000,
"income", 100000,
"creditScore", 750,
"status", "pending"
);
long startTime = System.currentTimeMillis();
int numberOfRequests = 2;
for (int i = 0; i < numberOfRequests; i++) {
try {
// Assuming that the client has an appropriate method for JSON body assertions
JSONBodyAssertion.JsonBodyAssertionResponse response = client.api_assertions.jsonbody.create(loanApplication);
// Process and print JSON body assertions
for (JSONBodyAssertion.Assertion assertion : response.getAssertions()) {
System.out.println(assertion.getValue());
System.out.println(assertion.getType());
System.out.println(assertion.getAssertionDescription());
}
} catch (Exception e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println("Synchronous Total time for JSON Body Assertion request: " + (endTime - startTime) + " ms");
}Using AsyncClient
Here's an example of utilizing JSON Body Assertion with AsyncClient.
PYTHON
There are two clients available with the Python SDK: SyncQyrusAI and AsyncQyrusAI.
Using SyncQyrusAI
Here's an example of utilizing JSON Body Assertion with SyncQyrusAI.
Using AsyncQyrusAI
Here's an example of utilizing JSON Body Assertion with AsyncQyrusAI.
REST APIs
This API allows users to create test based on provided API JSON Body.
Endpoint
URL : POST {{GATEWAY_URL}}/api-assertion-gpt-sdk/v1/api/assertion/jsonbody
Headers
Authorization: [Your Authorization Token]
Custom: [Your Custom Header Value]
Request Body: { "response": { "loanId": 101, "userId": 1, "loanAmount": 200000, "loanTerm": 30, "propertyValue": 250000, "income": 100000, "creditScore": 750, "status": "pending" } }
Response:
Last updated