Skip to content

Commit

Permalink
feat: Support Schemathesis hooks
Browse files Browse the repository at this point in the history
Ref: #4
  • Loading branch information
Stranger6667 committed Feb 18, 2023
1 parent 64470e1 commit cd782ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ jobs:
# Start the API in the background
- run: python apps/python/app.py &

- name: TEST
- name: Default test
uses: ./
continue-on-error: true
with:
schema: 'http://127.0.0.1:5001/openapi.json'
token: ${{ secrets.SCHEMATHESIS_TOKEN }}
args: '-E success'

- name: Custom hooks
uses: ./
with:
schema: 'http://127.0.0.1:5001/openapi.json'
token: ${{ secrets.SCHEMATHESIS_TOKEN }}
version: '3.18.5'
hooks: 'apps.python.hooks'
args: '-c custom_check -E success'
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Minimal:
- uses: schemathesis/action@v1
with:
# API schema location
schema: 'http://127.0.0.1:5001/openapi.json'
schema: 'https://example.schemathesis.io/openapi.json'
```
All options:
Expand All @@ -20,11 +20,11 @@ All options:
- uses: schemathesis/action@v1
with:
# API schema location
schema: 'http://127.0.0.1:5001/openapi.json'
schema: 'https://example.schemathesis.io/openapi.json'
# OPTIONAL. URL that will be used as a prefix for all API operations.
# Required if the schema is provided as a file.
# Otherwise, inferred from the schema.
base-url: 'http://127.0.0.1:5001/v2/'
base-url: 'https://example.schemathesis.io/v2/'
# OPTIONAL. Your Schemathesis.io token
token: ${{ secrets.SCHEMATHESIS_TOKEN }}
# OPTIONAL. API name from Schemathesis.io
Expand All @@ -41,6 +41,8 @@ All options:
# OPTIONAL. Specify which version of Schemathesis should be used.
# Defaults to `latest`
version: 'latest'
# OPTIONAL. Schemathesis hooks module. Available for Schemathesis >= 3.18.5 only
hooks: 'tests.hooks'
# OPTIONAL. Extra arguments to pass to Schemathesis
args: '-D negative'
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ inputs:
description: 'Specify which version of Schemathesis should be used. Defaults to `latest`'
required: false
default: "latest"
hooks:
description: 'Schemathesis hooks module'
required: false
args:
description: 'Extra arguments to pass to Schemathesis'
required: false
Expand Down Expand Up @@ -71,4 +74,5 @@ runs:
SCHEMATHESIS_REPORT: ${{ inputs.report }}
SCHEMATHESIS_WAIT_FOR_SCHEMA: ${{ inputs.wait-for-schema }}
SCHEMATHESIS_TOKEN: ${{ inputs.token }}
SCHEMATHESIS_HOOKS: ${{ inputs.hooks }}
SCHEMATHESIS_ACTION_REF: ${{ github.action_ref }}
7 changes: 7 additions & 0 deletions apps/python/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import schemathesis


@schemathesis.check
def custom_check(response, case):
# Always succeeds
return None

0 comments on commit cd782ab

Please sign in to comment.