Contract Test
Test Anatomy
Test File Anatomy
This section explains the key elements of the generated test files allowing you to make adjustments, if needed.
The header of each test file shows when the test was generated and what command was used
The body of the test file imports all relevant libraries and specify the URL for all test requests
Each method being tested has a function that consists of:
Invocation of Skyramp Client
Definition of the authentication header
Definition of the request body
Definition of the expected response body
Creation of the request
Generated Assertions
Status code assertion
Schema check
Body value checks (first 3 values)
Test File Anatomy
This section explains the key elements of the generated test files allowing you to make adjustments, if needed.
The header of each test file shows when the test was generated and what command was used
The body of the test file imports all relevant libraries and specify the URL for all test requests
Each method being tested has a function that consists of:
Invocation of Skyramp Client
Definition of the authentication header
Definition of the request body
Definition of the expected response body
Creation of the request
Generated Assertions
Status code assertion
Schema check
Body value checks (first 3 values)
Test File Anatomy
This section explains the key elements of the generated test files allowing you to make adjustments, if needed.
The header of each test file shows when the test was generated and what command was used
The body of the test file imports all relevant libraries and specify the URL for all test requests
Each method being tested has a function that consists of:
Invocation of Skyramp Client
Definition of the authentication header
Definition of the request body
Definition of the expected response body
Creation of the request
Generated Assertions
Status code assertion
Schema check
Body value checks (first 3 values)
Python
Java
Typescript
Single Method Test Generation (POST)
# Generated by Skyramp v0.5.23 on 2025-06-22 17:27:46.581415 -0400 EDT m=+1.490193376
# Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
# --api-schema https://demoshop.skyramp.dev/openapi.json \
# --framework pytest \
# --language python \
# --method POST \
# Import of required libraries
import skyramp
import os
import time
# URL for test requests
URL = "https://demoshop.skyramp.dev"
# contract test for /api/v1/products POST
def test_products_post():
# Invocation of Skyramp Client
client = skyramp.Client()
# Definition of authentication header
headers = {}
if os.getenv("SKYRAMP_TEST_TOKEN") is not None:
headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN")
# Request Body
products_POST_request_body = r'''{
"category": "Toys",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99
}'''
# Expected Response Body
expected_products_POST_response_body = r'''{
"category": "Toys",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99,
"product_id": 1,
"updated_at": "2025-02-25T10:54:22-05:00"
}'''
# Execute Request
products_POST_response = client.send_request(
url=URL,
path="/api/v1/products",
method="POST",
body=products_POST_request_body,
headers=headers
)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
if __name__ == "__main__":
test_products_post()
Changing asserts
By default, we generate value asserts only on the first 3 body values - this prevents the test code from becoming too verbose. Generated body value asserts validate if the field returned a value but do not do any matching. For more complex and/or additional asserts, you can adjust the code as follows:
Default Generated Asserts (lines 55-60)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
Manually Adjusted Asserts
Following the same principle you can simply adjust and add more assertions to the generated code. Additional details on defining assertions can be found in the Pytest Documentation.
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
# Manual addition of asserts
assert skyramp.get_response_value(products_POST_response, "image_url") is not None
assert skyramp.get_response_value(products_POST_response, "in_stock") is not None
assert skyramp.get_response_value(products_POST_response, "name")=="bigbear"
assert skyramp.get_response_value(products_POST_response, "price")==9.99
assert skyramp.get_response_value(products_POST_response, "product_id") is not None
Python
Java
Typescript
Single Method Test Generation (POST)
# Generated by Skyramp v0.5.23 on 2025-06-22 17:27:46.581415 -0400 EDT m=+1.490193376
# Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
# --api-schema https://demoshop.skyramp.dev/openapi.json \
# --framework pytest \
# --language python \
# --method POST \
# Import of required libraries
import skyramp
import os
import time
# URL for test requests
URL = "https://demoshop.skyramp.dev"
# contract test for /api/v1/products POST
def test_products_post():
# Invocation of Skyramp Client
client = skyramp.Client()
# Definition of authentication header
headers = {}
if os.getenv("SKYRAMP_TEST_TOKEN") is not None:
headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN")
# Request Body
products_POST_request_body = r'''{
"category": "Toys",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99
}'''
# Expected Response Body
expected_products_POST_response_body = r'''{
"category": "Toys",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99,
"product_id": 1,
"updated_at": "2025-02-25T10:54:22-05:00"
}'''
# Execute Request
products_POST_response = client.send_request(
url=URL,
path="/api/v1/products",
method="POST",
body=products_POST_request_body,
headers=headers
)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
if __name__ == "__main__":
test_products_post()
Changing asserts
By default, we generate value asserts only on the first 3 body values - this prevents the test code from becoming too verbose. Generated body value asserts validate if the field returned a value but do not do any matching. For more complex and/or additional asserts, you can adjust the code as follows:
Default Generated Asserts (lines 55-60)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
Manually Adjusted Asserts
Following the same principle you can simply adjust and add more assertions to the generated code. Additional details on defining assertions can be found in the Pytest Documentation.
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
# Manual addition of asserts
assert skyramp.get_response_value(products_POST_response, "image_url") is not None
assert skyramp.get_response_value(products_POST_response, "in_stock") is not None
assert skyramp.get_response_value(products_POST_response, "name")=="bigbear"
assert skyramp.get_response_value(products_POST_response, "price")==9.99
assert skyramp.get_response_value(products_POST_response, "product_id") is not None
Python
Java
Typescript
Single Method Test Generation (POST)
# Generated by Skyramp v0.5.23 on 2025-06-22 17:27:46.581415 -0400 EDT m=+1.490193376
# Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \
# --api-schema https://demoshop.skyramp.dev/openapi.json \
# --framework pytest \
# --language python \
# --method POST \
# Import of required libraries
import skyramp
import os
import time
# URL for test requests
URL = "https://demoshop.skyramp.dev"
# contract test for /api/v1/products POST
def test_products_post():
# Invocation of Skyramp Client
client = skyramp.Client()
# Definition of authentication header
headers = {}
if os.getenv("SKYRAMP_TEST_TOKEN") is not None:
headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN")
# Request Body
products_POST_request_body = r'''{
"category": "Toys",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99
}'''
# Expected Response Body
expected_products_POST_response_body = r'''{
"category": "Toys",
"created_at": "2025-02-25T10:54:22-05:00",
"description": "Bear Soft Toy",
"image_url": "https://images.app.goo.gl/cgcHpeehRdu5osot8",
"in_stock": true,
"name": "bigbear",
"price": 9.99,
"product_id": 1,
"updated_at": "2025-02-25T10:54:22-05:00"
}'''
# Execute Request
products_POST_response = client.send_request(
url=URL,
path="/api/v1/products",
method="POST",
body=products_POST_request_body,
headers=headers
)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
if __name__ == "__main__":
test_products_post()
Changing asserts
By default, we generate value asserts only on the first 3 body values - this prevents the test code from becoming too verbose. Generated body value asserts validate if the field returned a value but do not do any matching. For more complex and/or additional asserts, you can adjust the code as follows:
Default Generated Asserts (lines 55-60)
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
Manually Adjusted Asserts
Following the same principle you can simply adjust and add more assertions to the generated code. Additional details on defining assertions can be found in the Pytest Documentation.
# Generated Assertions
assert products_POST_response.status_code == 201
assert skyramp.check_schema(products_POST_response, expected_products_POST_response_body)
assert skyramp.get_response_value(products_POST_response, "category") is not None
assert skyramp.get_response_value(products_POST_response, "created_at") is not None
assert skyramp.get_response_value(products_POST_response, "description") is not None
# Manual addition of asserts
assert skyramp.get_response_value(products_POST_response, "image_url") is not None
assert skyramp.get_response_value(products_POST_response, "in_stock") is not None
assert skyramp.get_response_value(products_POST_response, "name")=="bigbear"
assert skyramp.get_response_value(products_POST_response, "price")==9.99
assert skyramp.get_response_value(products_POST_response, "product_id") is not None