Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

schemathesis tests #297

Closed
wants to merge 3 commits into from
Closed
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
76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Schema test

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


jobs:
api-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: tfgrid-graphql
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

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

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

- name: Build
if: ${{ github.event.inputs.NETWORK }} != 'dev'
run: |
export PATH=/home/runner/go/bin:$PATH
export GIT_COMMIT=$(git rev-list -1 HEAD)
go build -ldflags "-X main.GitCommit=$GIT_COMMIT" cmds/proxy_server/main.go
export PATH=/home/runner/go/bin:$PATH
pushd tools/db
go run . --seed 13 --postgres-host localhost --postgres-db tfgrid-graphql --postgres-password postgres --postgres-user postgres --reset
popd
go run cmds/proxy_server/main.go -no-cert --address :8080 --log-level debug --postgres-host localhost --postgres-db tfgrid-graphql --postgres-password postgres --postgres-user postgres &
sleep 6
env:
GO111MODULE: on

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

- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
name: schema-pytest-results
path: |
report.html
assets
if: ${{ always() }}
3 changes: 3 additions & 0 deletions tests/schema_test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest==7.1.2
schemathesis==3.17.5
pytest-html==3.2.0
18 changes: 18 additions & 0 deletions tests/schema_test/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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']
url = 'http://localhost:8080'
if network == 'dev':
url = 'https://gridproxy.dev.grid.tf'

schema = schemathesis.from_path("docs/swagger.json", 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,))