Skip to content

Commit

Permalink
Merge pull request #682 from NatLibFi/schemathesis
Browse files Browse the repository at this point in the history
Use Schemathesis to test REST API
  • Loading branch information
juhoinkinen committed Mar 15, 2023
2 parents e9fd177 + 08bf4ce commit 3a5fc50
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 91 deletions.
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.

0 comments on commit 3a5fc50

Please sign in to comment.