init: added template

This commit is contained in:
ITQ
2026-02-12 11:36:43 +03:00
parent 030e49edb9
commit 514393e3f8
96 changed files with 14594 additions and 183 deletions
+3
View File
@@ -0,0 +1,3 @@
# Below all environment variables and default values
BACKEND_BASE_URL=http://127.0.0.1:13240
+170
View File
@@ -0,0 +1,170 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
# PyPI configuration file
.pypirc
# Ruff files
.ruff_cache
+44
View File
@@ -0,0 +1,44 @@
# E2E tests for Lotty
## Prerequisites
Ensure you have the following installed on your system:
- [Python](https://www.python.org/) (>=3.10,<3.14)
- [uv](https://docs.astral.sh/uv/) (latest version recommended)
- [Docker](https://www.docker.com/) (latest version recommended)
- [Docker compose](https://docs.docker.com/compose/) (latest version recommended)
## Warning
Please note that containers will use ports from 13240 to 13248, so there is must be no listeners on this ports range.
## Setup
### Clone the project
### Go to the project directory
### Install dependencies
```bash
uv sync --no-dev
```
### Customize environment (optional)
```bash
cp .env.template .env
```
And setup env vars according to your needs.
### Run tests
```bash
uv run pytest .
```
### Results
You will see something like `n passed in Ns`
+81
View File
@@ -0,0 +1,81 @@
import os
import subprocess
import time
from collections.abc import Generator
import httpx
import pytest
from dotenv import load_dotenv
load_dotenv()
BACKEND_BASE_URL = os.getenv("BACKEND_BASE_URL", "http://127.0.0.1:13240")
@pytest.fixture(scope="session", autouse=True)
def docker_compose() -> Generator[None]:
# btw, this is just in case you've forgotten to shut down compose :)
subprocess.run(
executable="docker",
args=[
"docker",
"compose",
"--profile",
"loadtest",
"--profile",
"minio",
"--profile",
"observability",
"--profile",
"proxy",
"--profile",
"telegram_bot",
"down",
],
check=True,
)
subprocess.run(
executable="docker",
args=[
"docker",
"compose",
"--project-name",
"template-testing",
"--profile",
"minio",
"up",
"-d",
"--build",
"--force-recreate",
"--remove-orphans",
],
check=True,
)
time.sleep(5)
yield
subprocess.run(
executable="docker",
args=[
"docker",
"compose",
"--project-name",
"template-testing",
"--profile",
"minio",
"down",
"-v",
],
check=True,
)
@pytest.fixture(scope="session")
def client() -> Generator[httpx.Client]:
with httpx.Client(base_url=BACKEND_BASE_URL, timeout=10.0) as client:
yield client
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
items.sort(key=lambda item: "test_health" not in item.nodeid)
+94
View File
@@ -0,0 +1,94 @@
[project]
dependencies = ["httpx>=0.28.1", "pytest>=8.3.4", "python-dotenv>=1.0.1"]
name = "lotty-tests-e2e"
readme = "README.md"
requires-python = ">=3.10,<3.14"
version = "0.1.0"
[dependency-groups]
dev = ["ruff"]
[tool.ruff]
builtins = []
cache-dir = ".ruff_cache"
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"dist",
"migrations",
"node_modules",
"venv",
]
extend-exclude = []
extend-include = []
fix = false
fix-only = false
force-exclude = true
include = ["**/pyproject.toml", "*.ipynb", "*.py", "*.pyi"]
indent-width = 4
line-length = 79
namespace-packages = []
output-format = "full"
preview = false
required-version = ">=0.8.4"
respect-gitignore = true
show-fixes = true
src = [".", "src"]
target-version = "py310"
unsafe-fixes = false
[tool.ruff.analyze]
detect-string-imports = true
direction = "Dependencies"
exclude = []
include-dependencies = {}
preview = false
[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = 79
exclude = []
indent-style = "space"
line-ending = "lf"
preview = false
quote-style = "double"
skip-magic-trailing-comma = false
[tool.ruff.lint]
allowed-confusables = [""]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
exclude = ["tests.py"]
explicit-preview-rules = false
extend-fixable = []
extend-per-file-ignores = {}
extend-safe-fixes = []
extend-select = []
extend-unsafe-fixes = []
external = []
fixable = ["ALL"]
ignore = ["ANN401", "ARG", "COM812", "D", "FBT001", "FBT002", "N813", "S101"]
logger-objects = []
per-file-ignores = {}
preview = false
select = ["ALL"]
task-tags = ["FIXME", "HACK", "TODO", "WORKOUT"]
typing-modules = []
unfixable = []
[tool.ruff.lint.pylint]
max-args = 6
+3
View File
@@ -0,0 +1,3 @@
[pytest]
log_cli = true
log_level = INFO
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
GREEN='\033[1;32m'
NC='\033[0m'
uvx ruff format .
uvx ruff check . --fix
printf "${GREEN}Linters/formatters runned${NC}\n"
View File
@@ -0,0 +1,52 @@
import logging
import time
from http import HTTPStatus as status
from httpx import Client
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_generate_ad_text(client: Client) -> None:
"""
Tests integration between:
- backend
- redis
- yandexgpt
- celery
"""
payload = {
"advertiser_name": "Центральный Университет",
"ad_title": "Всероссийский кейс-чемпионат DEADLINE",
}
response = client.post("/generate/ad_text", json=payload)
assert response.status_code == status.OK
response_data = response.json()
assert "task_id" in response_data, "Missing task_id in response"
task_id = response_data["task_id"]
start_time = time.time()
while True:
result_response = client.get(f"/generate/ad_text/{task_id}/result")
assert result_response.status_code in (status.OK, status.NOT_FOUND)
result_data = result_response.json()
if (
result_data.get("status") == "SUCCESS"
and result_response.status_code == status.OK
):
assert isinstance(result_data.get("result"), str), (
"Result must be a string"
)
elapsed_time = time.time() - start_time
logger.info(
"Task %s completed in %.2f seconds", task_id, elapsed_time
)
logger.info("Generated Ad Text: %s", result_data["result"])
break
time.sleep(1)
+38
View File
@@ -0,0 +1,38 @@
import logging
from http import HTTPStatus as status
from httpx import Client
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_healthcheck(client: Client) -> None:
"""
Tests integration between:
- redis
- celery
- postgres
- minio
- yandexgpt
"""
response = client.get("/health?format=json")
assert response.status_code == status.OK
response_data = response.json()
unhealthy_services = [
service
for service, status in response_data.items()
if status != "working"
]
for service in unhealthy_services:
logger.error(
"Service %s unhealthy: %s", service, response_data[service]
)
assert not unhealthy_services, (
f"Some services are unhealthy: {', '.join(unhealthy_services)}"
)