Contract Test
Test Anatomy
Test File Anatomy
This section explains the key elements of the generated test file. The Skyramp generated test is editable and runnable like any other executable file.
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
TS / JS
Test Anatomy for All Methods of Endpoint
# Generated by Skyramp v1.2.11 on 2025-08-07 17:19:07.9842 -0400 EDT m=+1.359675168 # Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \ # --api-schema https://demoshop.skyramp.dev/openapi.json \ # --framework pytest \ # --language python \ # Import of required libraries import skyramp import os import time # URL for test requests URL = "https://demoshop.skyramp.dev" # Definition of authentication header def get_header(): headers = {} if os.getenv("SKYRAMP_TEST_TOKEN") is not None: headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN") return headers # contract test for /api/v1/products GET def test_products_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Expected Response Body expected_products_GET_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_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 10, "offset": 0, "order": "asc", "orderBy": None } ) # Generated Assertions assert products_GET_response.status_code == 200 assert skyramp.check_schema(products_GET_response, expected_products_GET_response_body) assert skyramp.get_response_value(products_GET_response, "0.category") is not None assert skyramp.get_response_value(products_GET_response, "0.created_at") is not None assert skyramp.get_response_value(products_GET_response, "0.description") is not None # contract test for /api/v1/products POST def test_products_post(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # 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 # contract test for /api/v1/products/{product_id} GET def test_products_product_id_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Expected Response Body expected_products_product_id_GET_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_product_id_GET_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="GET", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_GET_response.status_code == 200 assert skyramp.check_schema(products_product_id_GET_response, expected_products_product_id_GET_response_body) assert skyramp.get_response_value(products_product_id_GET_response, "category") is not None assert skyramp.get_response_value(products_product_id_GET_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_GET_response, "description") is not None # contract test for /api/v1/products/{product_id} PUT def test_products_product_id_put(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_PUT_response.status_code == 200 assert skyramp.check_schema(products_product_id_PUT_response, expected_products_product_id_PUT_response_body) assert skyramp.get_response_value(products_product_id_PUT_response, "category") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "description") is not None # contract test for /api/v1/products/{product_id} DELETE def test_products_product_id_delete(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Execute Request products_product_id_DELETE_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="DELETE", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_DELETE_response.status_code == 204 if __name__ == "__main__": test_products_get() test_products_post() test_products_product_id_get() test_products_product_id_put() test_products_product_id_delete()
Change Assertion(s)
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.
Default Generated Asserts (lines 106-111)
# 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
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
Change Path Parameter(s)
To change the path parameter of any of the contract test cases, add path_params to any relevant client.send_request calls. You can specify a variable or immediately adjust the value in the request object:
# Declaration of variables product_id = 1 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} )
Change Query Parameter(s)
To change the query parameter of any of the contract test cases, add query_params to any relevant client.send_request calls:
# Execute Request products_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 20, "offset": 0, "order": "asc", "orderBy": None } )
Python
Java
TS / JS
Test Anatomy for All Methods of Endpoint
# Generated by Skyramp v1.2.11 on 2025-08-07 17:19:07.9842 -0400 EDT m=+1.359675168 # Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \ # --api-schema https://demoshop.skyramp.dev/openapi.json \ # --framework pytest \ # --language python \ # Import of required libraries import skyramp import os import time # URL for test requests URL = "https://demoshop.skyramp.dev" # Definition of authentication header def get_header(): headers = {} if os.getenv("SKYRAMP_TEST_TOKEN") is not None: headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN") return headers # contract test for /api/v1/products GET def test_products_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Expected Response Body expected_products_GET_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_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 10, "offset": 0, "order": "asc", "orderBy": None } ) # Generated Assertions assert products_GET_response.status_code == 200 assert skyramp.check_schema(products_GET_response, expected_products_GET_response_body) assert skyramp.get_response_value(products_GET_response, "0.category") is not None assert skyramp.get_response_value(products_GET_response, "0.created_at") is not None assert skyramp.get_response_value(products_GET_response, "0.description") is not None # contract test for /api/v1/products POST def test_products_post(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # 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 # contract test for /api/v1/products/{product_id} GET def test_products_product_id_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Expected Response Body expected_products_product_id_GET_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_product_id_GET_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="GET", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_GET_response.status_code == 200 assert skyramp.check_schema(products_product_id_GET_response, expected_products_product_id_GET_response_body) assert skyramp.get_response_value(products_product_id_GET_response, "category") is not None assert skyramp.get_response_value(products_product_id_GET_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_GET_response, "description") is not None # contract test for /api/v1/products/{product_id} PUT def test_products_product_id_put(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_PUT_response.status_code == 200 assert skyramp.check_schema(products_product_id_PUT_response, expected_products_product_id_PUT_response_body) assert skyramp.get_response_value(products_product_id_PUT_response, "category") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "description") is not None # contract test for /api/v1/products/{product_id} DELETE def test_products_product_id_delete(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Execute Request products_product_id_DELETE_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="DELETE", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_DELETE_response.status_code == 204 if __name__ == "__main__": test_products_get() test_products_post() test_products_product_id_get() test_products_product_id_put() test_products_product_id_delete()
Change Assertion(s)
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.
Default Generated Asserts (lines 106-111)
# 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
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
Change Path Parameter(s)
To change the path parameter of any of the contract test cases, add path_params to any relevant client.send_request calls. You can specify a variable or immediately adjust the value in the request object:
# Declaration of variables product_id = 1 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} )
Change Query Parameter(s)
To change the query parameter of any of the contract test cases, add query_params to any relevant client.send_request calls:
# Execute Request products_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 20, "offset": 0, "order": "asc", "orderBy": None } )
Python
Java
TS / JS
Test Anatomy for All Methods of Endpoint
# Generated by Skyramp v1.2.11 on 2025-08-07 17:19:07.9842 -0400 EDT m=+1.359675168 # Command: skyramp generate contract rest https://demoshop.skyramp.dev/api/v1/products \ # --api-schema https://demoshop.skyramp.dev/openapi.json \ # --framework pytest \ # --language python \ # Import of required libraries import skyramp import os import time # URL for test requests URL = "https://demoshop.skyramp.dev" # Definition of authentication header def get_header(): headers = {} if os.getenv("SKYRAMP_TEST_TOKEN") is not None: headers["Authorization"] = "Bearer " + os.getenv("SKYRAMP_TEST_TOKEN") return headers # contract test for /api/v1/products GET def test_products_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Expected Response Body expected_products_GET_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_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 10, "offset": 0, "order": "asc", "orderBy": None } ) # Generated Assertions assert products_GET_response.status_code == 200 assert skyramp.check_schema(products_GET_response, expected_products_GET_response_body) assert skyramp.get_response_value(products_GET_response, "0.category") is not None assert skyramp.get_response_value(products_GET_response, "0.created_at") is not None assert skyramp.get_response_value(products_GET_response, "0.description") is not None # contract test for /api/v1/products POST def test_products_post(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # 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 # contract test for /api/v1/products/{product_id} GET def test_products_product_id_get(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Expected Response Body expected_products_product_id_GET_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_product_id_GET_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="GET", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_GET_response.status_code == 200 assert skyramp.check_schema(products_product_id_GET_response, expected_products_product_id_GET_response_body) assert skyramp.get_response_value(products_product_id_GET_response, "category") is not None assert skyramp.get_response_value(products_product_id_GET_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_GET_response, "description") is not None # contract test for /api/v1/products/{product_id} PUT def test_products_product_id_put(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_PUT_response.status_code == 200 assert skyramp.check_schema(products_product_id_PUT_response, expected_products_product_id_PUT_response_body) assert skyramp.get_response_value(products_product_id_PUT_response, "category") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "created_at") is not None assert skyramp.get_response_value(products_product_id_PUT_response, "description") is not None # contract test for /api/v1/products/{product_id} DELETE def test_products_product_id_delete(): # Invocation of Skyramp Client client = skyramp.Client() # Definition of authentication header headers = get_header() # Declaration of variables product_id = 0 # Execute Request products_product_id_DELETE_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="DELETE", headers=headers, path_params={"product_id": product_id} ) # Generated Assertions assert products_product_id_DELETE_response.status_code == 204 if __name__ == "__main__": test_products_get() test_products_post() test_products_product_id_get() test_products_product_id_put() test_products_product_id_delete()
Change Assertion(s)
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.
Default Generated Asserts (lines 106-111)
# 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
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
Change Path Parameter(s)
To change the path parameter of any of the contract test cases, add path_params to any relevant client.send_request calls. You can specify a variable or immediately adjust the value in the request object:
# Declaration of variables product_id = 1 # Request Body products_product_id_PUT_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_product_id_PUT_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_product_id_PUT_response = client.send_request( url=URL, path="/api/v1/products/{product_id}", method="PUT", body=products_product_id_PUT_request_body, headers=headers, path_params={"product_id": product_id} )
Change Query Parameter(s)
To change the query parameter of any of the contract test cases, add query_params to any relevant client.send_request calls:
# Execute Request products_GET_response = client.send_request( url=URL, path="/api/v1/products", method="GET", headers=headers, query_params={ "limit": 20, "offset": 0, "order": "asc", "orderBy": None } )