From 53ca27a9280005ac7284f22617bab07f7878ec8b Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Thu, 18 Jan 2024 12:17:59 +1000 Subject: [PATCH] Update default for env param --- README.md | 10 +++++----- apitally/django.py | 2 +- apitally/flask.py | 2 +- apitally/starlette.py | 2 +- tests/constants.py | 2 ++ tests/test_client_asyncio.py | 8 +++----- tests/test_client_base.py | 4 +--- tests/test_client_threading.py | 6 ++---- tests/test_django_ninja.py | 2 +- tests/test_django_rest_framework.py | 2 +- tests/test_fastapi.py | 6 ++---- tests/test_flask.py | 6 ++---- tests/test_starlette.py | 6 ++---- 13 files changed, 24 insertions(+), 34 deletions(-) create mode 100644 tests/constants.py diff --git a/README.md b/README.md index 5c523fa..2002547 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ app = FastAPI() app.add_middleware( ApitallyMiddleware, client_id="your-client-id", - env="default", # or "dev", "prod" etc. (optional) + env="dev", # or "prod" etc. ) ``` @@ -92,7 +92,7 @@ app = Starlette(routes=[...]) app.add_middleware( ApitallyMiddleware, client_id="your-client-id", - env="default", # or "dev", "prod" etc. (optional) + env="dev", # or "prod" etc. ) ``` @@ -110,7 +110,7 @@ app = Flask(__name__) app.wsgi_app = ApitallyMiddleware( app, client_id="your-client-id", - env="default", # or "dev", "prod" etc. (optional) + env="dev", # or "prod" etc. ) ``` @@ -129,7 +129,7 @@ MIDDLEWARE = [ ] APITALLY_MIDDLEWARE = { "client_id": "your-client-id", - "env": "default", # or "dev", "prod" etc. (optional) + "env": "dev", # or "prod" etc. } ``` @@ -148,7 +148,7 @@ MIDDLEWARE = [ ] APITALLY_MIDDLEWARE = { "client_id": "your-client-id", - "env": "default", # or "dev", "prod" etc. (optional) + "env": "dev", # or "prod" etc. } ``` diff --git a/apitally/django.py b/apitally/django.py index 5feb97c..8ea0df0 100644 --- a/apitally/django.py +++ b/apitally/django.py @@ -64,7 +64,7 @@ def __init__(self, get_response: Callable[[HttpRequest], HttpResponse]) -> None: def configure( cls, client_id: str, - env: str = "default", + env: str = "dev", app_version: Optional[str] = None, sync_api_keys: bool = False, openapi_url: Optional[str] = None, diff --git a/apitally/flask.py b/apitally/flask.py index 3b6cc71..296b16d 100644 --- a/apitally/flask.py +++ b/apitally/flask.py @@ -28,7 +28,7 @@ def __init__( self, app: Flask, client_id: str, - env: str = "default", + env: str = "dev", app_version: Optional[str] = None, sync_api_keys: bool = False, openapi_url: Optional[str] = None, diff --git a/apitally/starlette.py b/apitally/starlette.py index 18a3310..a3c2306 100644 --- a/apitally/starlette.py +++ b/apitally/starlette.py @@ -51,7 +51,7 @@ def __init__( self, app: ASGIApp, client_id: str, - env: str = "default", + env: str = "dev", app_version: Optional[str] = None, sync_api_keys: bool = False, openapi_url: Optional[str] = "/openapi.json", diff --git a/tests/constants.py b/tests/constants.py new file mode 100644 index 0000000..a241a25 --- /dev/null +++ b/tests/constants.py @@ -0,0 +1,2 @@ +CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" +ENV = "dev" diff --git a/tests/test_client_asyncio.py b/tests/test_client_asyncio.py index 9e92ea5..6fddced 100644 --- a/tests/test_client_asyncio.py +++ b/tests/test_client_asyncio.py @@ -8,17 +8,15 @@ from pytest_httpx import HTTPXMock from pytest_mock import MockerFixture +from .constants import CLIENT_ID, ENV + if TYPE_CHECKING: from apitally.client.asyncio import ApitallyClient -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" - - @pytest.fixture(scope="module") -async def client(module_mocker: MockerFixture) -> ApitallyClient: +async def client() -> ApitallyClient: from apitally.client.asyncio import ApitallyClient from apitally.client.base import ApitallyKeyCacheBase diff --git a/tests/test_client_base.py b/tests/test_client_base.py index 1eba32f..361236c 100644 --- a/tests/test_client_base.py +++ b/tests/test_client_base.py @@ -1,8 +1,6 @@ import pytest - -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" +from .constants import CLIENT_ID, ENV def test_request_logger(): diff --git a/tests/test_client_threading.py b/tests/test_client_threading.py index 21dfab3..c490dd3 100644 --- a/tests/test_client_threading.py +++ b/tests/test_client_threading.py @@ -9,15 +9,13 @@ from pytest_mock import MockerFixture from requests_mock import Mocker +from .constants import CLIENT_ID, ENV + if TYPE_CHECKING: from apitally.client.threading import ApitallyClient -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" - - @pytest.fixture(scope="module") def client() -> ApitallyClient: from apitally.client.base import ApitallyKeyCacheBase diff --git a/tests/test_django_ninja.py b/tests/test_django_ninja.py index f776a8d..1322661 100644 --- a/tests/test_django_ninja.py +++ b/tests/test_django_ninja.py @@ -49,7 +49,7 @@ def setup(module_mocker: MockerFixture) -> None: ], APITALLY_MIDDLEWARE={ "client_id": "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9", - "env": "default", + "env": "dev", "sync_api_keys": True, "identify_consumer_callback": "tests.test_django_ninja.identify_consumer", }, diff --git a/tests/test_django_rest_framework.py b/tests/test_django_rest_framework.py index 3833dfa..4fe5b3b 100644 --- a/tests/test_django_rest_framework.py +++ b/tests/test_django_rest_framework.py @@ -47,7 +47,7 @@ def setup(module_mocker: MockerFixture) -> None: ], APITALLY_MIDDLEWARE={ "client_id": "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9", - "env": "default", + "env": "dev", }, ) django.setup() diff --git a/tests/test_fastapi.py b/tests/test_fastapi.py index 0d65b5b..6fd614c 100644 --- a/tests/test_fastapi.py +++ b/tests/test_fastapi.py @@ -6,6 +6,8 @@ import pytest from pytest_mock import MockerFixture +from .constants import CLIENT_ID, ENV + if find_spec("fastapi") is None: pytest.skip("fastapi is not available", allow_module_level=True) @@ -24,10 +26,6 @@ pass -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" - - @pytest.fixture(scope="module") def app(module_mocker: MockerFixture) -> FastAPI: from fastapi import Depends, FastAPI, Security diff --git a/tests/test_flask.py b/tests/test_flask.py index 95b4b9e..cb96b3c 100644 --- a/tests/test_flask.py +++ b/tests/test_flask.py @@ -6,6 +6,8 @@ import pytest from pytest_mock import MockerFixture +from .constants import CLIENT_ID, ENV + if find_spec("flask") is None: pytest.skip("flask is not available", allow_module_level=True) @@ -16,10 +18,6 @@ from apitally.client.base import KeyRegistry -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" - - @pytest.fixture(scope="module") def app(module_mocker: MockerFixture) -> Flask: from flask import Flask diff --git a/tests/test_starlette.py b/tests/test_starlette.py index a9999cf..54d48c8 100644 --- a/tests/test_starlette.py +++ b/tests/test_starlette.py @@ -7,6 +7,8 @@ from pytest import FixtureRequest from pytest_mock import MockerFixture +from .constants import CLIENT_ID, ENV + if find_spec("starlette") is None: pytest.skip("starlette is not available", allow_module_level=True) @@ -17,10 +19,6 @@ from apitally.client.base import KeyRegistry -CLIENT_ID = "76b5cb91-a0a4-4ea0-a894-57d2b9fcb2c9" -ENV = "default" - - @pytest.fixture( scope="module", params=["starlette", "fastapi"] if find_spec("fastapi") is not None else ["starlette"],