Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema tests #695

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/scheme_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Proxy Schema Test

on:
workflow_dispatch:
inputs:
NETWORK:
description: 'Network to run test on'
required: true
default: 'local'
type: choice
options:
- local
- dev
- qa
- test
- main
push:
pull_request:
branches:
- development


jobs:
api-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: grid-proxy

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Setting up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Installing all necessary packages
run: pip install -r tests/schema_test/requirments.txt

- name: Build
env:
MNEMONICS: ${{ secrets.MNEMONICS }}
run: |
go mod tidy
make db-start
make db-fill
make server-start m="$MNEMONICS" &

- name: Wait on localhost
uses: iFaxity/wait-on-action@v1
with:
resource: http://localhost:8080

- name: Run tests
run: NETWORK=${{ github.event.inputs.NETWORK }} python3 -m pytest -v ./tests/schema_test/ --html=./tests/schema_test/report.html

- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: schema-pytest-results
path: |
///home/runner/work/tfgrid-sdk-go/tfgrid-sdk-go/grid-proxy/tests/schema_test/report.html
///home/runner/work/tfgrid-sdk-go/tfgrid-sdk-go/grid-proxy/tests/schema_test/assets
if: ${{ always() }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ coverage/
bin/

dist/

.hypothesis
3 changes: 3 additions & 0 deletions grid-proxy/tests/schema_test/requirments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest==7.3.1
schemathesis==3.24.3
pytest-html==4.1.1
25 changes: 25 additions & 0 deletions grid-proxy/tests/schema_test/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import pytest
import schemathesis
from schemathesis.checks import not_a_server_error, status_code_conformance, content_type_conformance, response_schema_conformance, response_headers_conformance

network = os.environ['NETWORK']
if network == 'main':
url = 'https://gridproxy.grid.tf'
swagger = 'https://gridproxy.grid.tf/swagger/doc.json'
schema = schemathesis.from_uri(swagger, base_url = url)
elif network == '':
url = 'http://localhost:8080'
swagger = "docs/swagger.json"
schema = schemathesis.from_path(swagger, base_url = url)
else:
url = 'https://gridproxy.' + network + '.grid.tf'
swagger = 'https://gridproxy.' + network + '.grid.tf/swagger/doc.json'
schema = schemathesis.from_uri(swagger, base_url = url)


@pytest.mark.parametrize("check", [not_a_server_error, status_code_conformance, content_type_conformance, response_schema_conformance, response_headers_conformance])
@schema.parametrize()
def test_api(case, check):
response = case.call()
case.validate_response(response, checks=(check,))
Loading