diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml index c93d33a74d3e7656a52edbf77d32f5714028630b..639a7eecb9ad9630f9196c43a6e785a72c2efe70 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml @@ -6,6 +6,7 @@ services: context: . dockerfile: ./deploy/Dockerfile image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}} + restart: always env_file: - .env {%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or @@ -51,8 +52,9 @@ services: - "POSTGRES_DB={{cookiecutter.project_name}}" volumes: - {{cookiecutter.project_name}}-db-data:/var/lib/postgresql/data + restart: always healthcheck: - test: ["CMD-SHELL", "pg_isready"] + test: pg_isready -U {{cookiecutter.project_name}} interval: 2s timeout: 3s retries: 40 @@ -62,6 +64,7 @@ services: db: image: {{cookiecutter.db_info.image}} hostname: {{cookiecutter.project_name}}-db + restart: always environment: - "ALLOW_EMPTY_PASSWORD=yes" - "MYSQL_ROOT_PASSWORD={{cookiecutter.project_name}}" @@ -115,10 +118,11 @@ services: redis: image: bitnami/redis:6.2.5 hostname: {{cookiecutter.project_name}}-redis + restart: always environment: - "ALLOW_EMPTY_PASSWORD=yes" healthcheck: - test: ["CMD", "redis-cli", "ping"] + test: redis-cli ping interval: 1s timeout: 3s retries: 30 diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py index 8ab5548c6b685250b9afc5297cb40ecd6adbba6f..245d40828b41043542ae320aa7839e07304b5686 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py @@ -22,8 +22,7 @@ from sqlalchemy.orm import sessionmaker from {{cookiecutter.project_name}}.db.dependencies import get_db_session from {{cookiecutter.project_name}}.db.utils import create_database, drop_database {%- elif cookiecutter.orm == "tortoise" %} -from tortoise.contrib.test import finalizer, initializer, _restore_default # noqa: WPS450 -from tortoise import Tortoise +from tortoise.contrib.test import finalizer, initializer from {{cookiecutter.project_name}}.db.config import MODELS_MODULES {%- endif %} {%- endif %} @@ -124,7 +123,7 @@ async def transaction(_engine: AsyncEngine) -> AsyncGenerator[AsyncConnection, N await conn.rollback() {%- elif cookiecutter.orm == "tortoise" %} -@pytest.fixture(scope="session", autouse=True) +@pytest.fixture(autouse=True) def initialize_db(event_loop: AbstractEventLoop) -> Generator[None, None, None]: """ Initialize models and database. @@ -143,25 +142,6 @@ def initialize_db(event_loop: AbstractEventLoop) -> Generator[None, None, None]: finalizer() -@pytest.fixture(autouse=True) -@pytest.mark.asyncio -async def clean_db() -> AsyncGenerator[None, None]: - """ - Removes all data from database after test. - - :yields: Nothing. - """ - yield - - _restore_default() - for app in Tortoise.apps.values(): - for model in app.values(): - meta = model._meta # noqa: WPS437 - quote_char = meta.db.query_class._builder().QUOTE_CHAR # noqa: WPS437 - await meta.db.execute_script( - f"DELETE FROM {quote_char}{meta.db_table}{quote_char}" # noqa: S608 - ) - {%- endif %} {%- endif %} diff --git a/pyproject.toml b/pyproject.toml index 3658f442354dcb64e1d28153b45791c17737f10d..39133bec5673f526ab88111f8c9bdfdb5ca19c2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi_template" -version = "3.1.2" +version = "3.1.3" description = "Feature-rich robust FastAPI template" authors = ["Pavel Kirilin <win10@list.ru>"] packages = [{ include = "fastapi_template" }]