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

Use Schemathesis to test REST API #682

Merged
merged 7 commits into from
Mar 15, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ docs/_build/
poetry.lock
projects.cfg
venv/
.hypothesis/
24 changes: 13 additions & 11 deletions annif/openapi/annif.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ paths:
summary: get basic information about the API service
operationId: annif.rest.show_info
responses:
200:
"200":
description: successful operation
content:
application/json:
Expand All @@ -25,7 +25,7 @@ paths:
summary: get a list of projects
operationId: annif.rest.list_projects
responses:
200:
"200":
description: successful operation
content:
application/json:
Expand All @@ -40,13 +40,13 @@ paths:
parameters:
- $ref: '#/components/parameters/project_id'
responses:
200:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Project'
404:
"404":
description: Project not found
content:
application/problem+json:
Expand Down Expand Up @@ -89,25 +89,25 @@ paths:
description: language of subject labels
required: true
responses:
200:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/SuggestionResultList'
400:
"400":
description: Bad Request
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
404:
"404":
description: Project not found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
503:
"503":
description: Service Unavailable
content:
application/problem+json:
Expand All @@ -131,16 +131,16 @@ paths:
$ref: '#/components/schemas/IndexedDocument'
required: true
responses:
204:
"204":
description: successful operation
content: {}
404:
"404":
description: Project not found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
503:
"503":
description: Service Unavailable
content:
application/problem+json:
Expand Down Expand Up @@ -193,10 +193,12 @@ components:
is_trained:
type: boolean
example: true
nullable: true
modification_time:
type: string
format: date-time
example: 2020-05-19T16:42:42Z
nullable: true
description: A project definition
ProjectList:
type: object
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ flake8 = "*"
bumpversion = "*"
black = "23.*"
isort = "*"
schemathesis = "3.18.*"

[tool.poetry.extras]
fasttext = ["fasttext-wheel"]
Expand Down
6 changes: 0 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ def app_with_initialize():
return app


@pytest.fixture
def app_client(app):
with app.test_client() as app_client:
yield app_client


@pytest.fixture(scope="module")
def registry(app):
with app.app_context():
Expand Down
1 change: 1 addition & 0 deletions tests/projects.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ name=Dummy with no backend
language=en
vocab=dummy
analyzer=snowball(english)
access=private

[noname]
language=en
Expand Down
17 changes: 17 additions & 0 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Unit tests for Annif REST API / Swagger spec"""
import schemathesis
from hypothesis import settings

schema = schemathesis.from_path("annif/openapi/annif.yaml")


@schemathesis.check
def check_cors(response, case):
assert response.headers["access-control-allow-origin"] == "*"


@schema.parametrize()
@settings(max_examples=10)
def test_api(case, app):
response = case.call_wsgi(app)
case.validate_response(response, additional_checks=(check_cors,))
74 changes: 0 additions & 74 deletions tests/test_swagger.py

This file was deleted.