From 41c158e2fc13507c90f97849f078b03a592cea12 Mon Sep 17 00:00:00 2001 From: Juho Inkinen Date: Tue, 21 Mar 2023 18:55:08 +0200 Subject: [PATCH 1/5] Add test which targets existing project --- tests/test_openapi.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_openapi.py b/tests/test_openapi.py index e77230fd9..ea4942667 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -15,3 +15,11 @@ def check_cors(response, case): def test_api(case, app): response = case.call_wsgi(app) case.validate_response(response, additional_checks=(check_cors,)) + + +@schema.parametrize(endpoint="/v1/projects/{project_id}") +@settings(max_examples=100) +def test_api_target_dummy_fi(case, app): + case.path_parameters = {"project_id": "dummy-fi"} + response = case.call_wsgi(app) + case.validate_response(response) From 09b4e961a3fda8a87e7f4fc01d40eb3b5a8aeccc Mon Sep 17 00:00:00 2001 From: Juho Inkinen Date: Tue, 21 Mar 2023 19:29:21 +0200 Subject: [PATCH 2/5] Mark targeted test slow & skip it by default --- pyproject.toml | 3 +++ tests/test_openapi.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 4c7fb93a9..5a69bc4b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,3 +91,6 @@ build-backend = "poetry.core.masonry.api" profile = "black" line_length = "88" skip_gitignore = true + +[tool.pytest.ini_options] +addopts = "-m 'not slow'" diff --git a/tests/test_openapi.py b/tests/test_openapi.py index ea4942667..e99fe9b60 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -1,4 +1,5 @@ """Unit tests for Annif REST API / Swagger spec""" +import pytest import schemathesis from hypothesis import settings @@ -17,6 +18,7 @@ def test_api(case, app): case.validate_response(response, additional_checks=(check_cors,)) +@pytest.mark.slow @schema.parametrize(endpoint="/v1/projects/{project_id}") @settings(max_examples=100) def test_api_target_dummy_fi(case, app): From f476c9d5e4134be96c7fd07733fb1a699e8cd92a Mon Sep 17 00:00:00 2001 From: Juho Inkinen Date: Tue, 21 Mar 2023 19:47:10 +0200 Subject: [PATCH 3/5] Fix missing attributes in OpenAPI specification Noted by targeted Schemathesis test --- annif/openapi/annif.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/annif/openapi/annif.yaml b/annif/openapi/annif.yaml index 117faef9c..09d26a2a0 100644 --- a/annif/openapi/annif.yaml +++ b/annif/openapi/annif.yaml @@ -224,6 +224,7 @@ components: notation: type: string example: "42.42" + nullable: true score: type: number example: 0.85 @@ -246,6 +247,8 @@ components: type: array items: type: object + required: + - uri properties: uri: type: string From 7402e9b7934db21065f2f798570fbe4296b009e6 Mon Sep 17 00:00:00 2001 From: Juho Inkinen Date: Wed, 22 Mar 2023 18:06:20 +0200 Subject: [PATCH 4/5] Run slow test in Python 3.9 CI/CD job --- .github/workflows/cicd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index c799228b3..b9ea4cea9 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -77,6 +77,9 @@ jobs: - name: Test with pytest run: | poetry run pytest --cov=./ --cov-report xml + if [[ ${{ matrix.python-version }} == '3.9' ]]; then + poetry run pytest --cov=./ --cov-report xml --cov-append -m slow + fi - name: Upload coverage to Codecov uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - name: Save cache From 3f2567116c9a987d8176ccacc047efd38438ca52 Mon Sep 17 00:00:00 2001 From: Juho Inkinen Date: Wed, 22 Mar 2023 19:04:43 +0200 Subject: [PATCH 5/5] Use only 50 requests to speed up testing --- tests/test_openapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_openapi.py b/tests/test_openapi.py index e99fe9b60..91de50385 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -20,7 +20,7 @@ def test_api(case, app): @pytest.mark.slow @schema.parametrize(endpoint="/v1/projects/{project_id}") -@settings(max_examples=100) +@settings(max_examples=50) def test_api_target_dummy_fi(case, app): case.path_parameters = {"project_id": "dummy-fi"} response = case.call_wsgi(app)