Skip to content

Commit

Permalink
Fix precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
francbartoli committed Apr 5, 2024
1 parent 4dd2769 commit 7ea8527
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
22 changes: 15 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Configuration for tests."""
import os
import sys
from unittest import mock

import pytest
import schemathesis
import sys
from typer.testing import CliRunner
from unittest import mock


@pytest.fixture
def runner() -> CliRunner:
"""Fixture for invoking command-line interfaces."""
return CliRunner()


def reload_app():
"""Reload the app with the test environment variables."""
if "app.main" in sys.modules:
del sys.modules["app.main"]
if "app.config.app" in sys.modules:
Expand All @@ -20,32 +24,36 @@ def reload_app():

return app


@pytest.fixture
def create_app():
"""Return a new app that is being reloaded with
any environment variable has being set"""

"""Return a new app that is being reloaded with any environment variable has being set.""" # noqa
yield reload_app


@pytest.fixture
def create_protected_with_apikey_app(create_app):
"""Return a protected app with an API key."""

def _protected_app():
with mock.patch.dict(
os.environ,
{
"API_KEY_ENABLED": "true",
"PYGEOAPI_KEY_GLOBAL": "pygeoapi",
"JWKS_ENABLED": "false",
"OPA_ENABLED": "false"
}
"OPA_ENABLED": "false",
},
):
app = create_app()
return app

yield _protected_app


@pytest.fixture
def protected_apikey_schema(create_protected_with_apikey_app):
"""Create a protected API key schema."""
app = create_protected_with_apikey_app()

return schemathesis.from_asgi("/geoapi/openapi?f=json", app=app)
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test cases for the cli module."""
import pytest
from cli import app
from typer.testing import CliRunner

Expand Down
4 changes: 3 additions & 1 deletion tests/test_openapi_contract.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pytest
"""OpenAPI contract tests module."""
import schemathesis


schema = schemathesis.from_pytest_fixture("protected_apikey_schema")


@schema.parametrize()
def test_api(case):
"""Test the API with API-KEY protection."""
case.headers = {"X-API-KEY": "pygeoapi"}
response = case.call_asgi()
case.validate_response(response)

0 comments on commit 7ea8527

Please sign in to comment.